From bd2dac1b30d72d74be46b65ed4d0b5eb87324ef1 Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Wed, 21 Dec 2022 22:30:54 +0100 Subject: [PATCH 1/5] Fix #493 import-module loses previously stored configuration --- Source/VSTeam.psm1 | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/VSTeam.psm1 b/Source/VSTeam.psm1 index 28f753ec..c8233f1e 100644 --- a/Source/VSTeam.psm1 +++ b/Source/VSTeam.psm1 @@ -31,18 +31,32 @@ if ($null -ne $env:TEAM_PROJECT) { # if not account and pat is set, then do not try to set the default project - if ($null -eq $env:TEAM_PAT -and $null -eq $env:TEAM_ACCT) { - Write-Warning "No PAT or Account set. You must set the environment variables TEAM_PAT or TEAM_ACCT before loading the module to use the default project." + if (($null -eq $env:TEAM_PAT -and $null -eq $env:TEAM_TOKEN) -and $null -eq $env:TEAM_ACCT) { + Write-Warning "No PAT or Account set. You must set the environment variables (TEAM_PAT or TEAM_TOKEN) and TEAM_ACCT before loading the module to use the default project." } else { # set vsteam account to initialize given variables properly - Set-VSTeamAccount -Account $env:TEAM_ACCT -PersonalAccessToken $env:TEAM_PAT + $commonArgs = @{ + Account = $env:TEAM_ACCT + Version = $env:TEAM_VERSION + } + + if (_useBearerToken) { + $commonArgs.Add("UseBearerToken", $true) + $commonArgs.Add("PersonalAccessToken", $env:TEAM_TOKEN) + } else { + $pat = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:TEAM_PAT)) #decode base64 stored pat + $pat = $pat.Substring(1) #remove the leading : + $commonArgs.Add("PersonalAccessToken", $pat) + } + $defaultProject = $env:TEAM_PROJECT #save temporary defalt project because it's removed during Set-VSTeamAccount call + Set-VSTeamAccount @commonArgs # Make sure the value in the environment variable still exisits. - if (Get-VSTeamProject | Where-Object ProjectName -eq $env:TEAM_PROJECT) { - Set-VSTeamDefaultProject -Project $env:TEAM_PROJECT + if (Get-VSTeamProject | Where-Object ProjectName -eq $defaultProject) { + Set-VSTeamDefaultProject -Project $defaultProject } else { - Write-Warning "The default project '$env:TEAM_PROJECT' stored in the environment variable TEAM_PROJECT does not exist." + Write-Warning "The default project '$defaultProject' stored in the environment variable TEAM_PROJECT does not exist." } } From 556f0e97715ee54d09baba8573276c1add6ab1ce Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Sat, 31 Dec 2022 18:07:04 +0100 Subject: [PATCH 2/5] Fix Versions test on local If the user calls Set-VSTeamAccount with -Local parameter, the TEAM_VERSION environment variable is preserved. The Versions.SetApiVersion did not manage the APIs.Version value and the test failed. This behavior does not occur in during the github build because the TEAM_VERSION variable is not set --- Source/Classes/Versions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Classes/Versions.cs b/Source/Classes/Versions.cs index e5566dcb..e094ff41 100644 --- a/Source/Classes/Versions.cs +++ b/Source/Classes/Versions.cs @@ -79,6 +79,9 @@ public static void SetApiVersion(APIs service, string version) case APIs.WorkItemTracking: WorkItemTracking = version; break; + case APIs.Version: + Version = version; + break; } } From ac9cbb582df0d78a78347791dcc5a9d8d5fd4287 Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Sat, 31 Dec 2022 18:22:05 +0100 Subject: [PATCH 3/5] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de6f9b58..80c1a175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/502) fr - Updated test c# project to .NET 6.0 - Fixed test fail on ubuntu-latest +Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/508) from [Miguel Nieto](https://github.com/mnieto) the following: +- Fix import-module vsteam loses previously stored configuration: [issue #493](https://github.com/MethodsAndPractices/vsteam/issues/493) +- Fixed test Versions fail on local machine + ## 7.9.0 Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/481) from [Sebastian Schütze](https://github.com/SebastianSchuetze) the following: From 0de8b4e706f0bec19954106a1478d613b6a24fe3 Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Sat, 13 May 2023 20:49:55 +0200 Subject: [PATCH 4/5] update changelog and apply suggested changes --- CHANGELOG.md | 3 +++ Source/VSTeam.psm1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 481f299f..859deac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 7.12.0 +Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/508) from [Miguel Nieto](https://github.com/mnieto) the following: +- Fix import-module loses previously stored configuration [493](https://github.com/MethodsAndPractices/vsteam/issues/493) + Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/506) from [Miguel Nieto](https://github.com/mnieto) the following: - fix tests that involve dates fail when OS culture has 24 hours format diff --git a/Source/VSTeam.psm1 b/Source/VSTeam.psm1 index c8233f1e..4d6eb933 100644 --- a/Source/VSTeam.psm1 +++ b/Source/VSTeam.psm1 @@ -31,7 +31,7 @@ if ($null -ne $env:TEAM_PROJECT) { # if not account and pat is set, then do not try to set the default project - if (($null -eq $env:TEAM_PAT -and $null -eq $env:TEAM_TOKEN) -and $null -eq $env:TEAM_ACCT) { + if (($null -eq $env:TEAM_PAT -or $null -eq $env:TEAM_TOKEN) -and $null -eq $env:TEAM_ACCT) { Write-Warning "No PAT or Account set. You must set the environment variables (TEAM_PAT or TEAM_TOKEN) and TEAM_ACCT before loading the module to use the default project." } else { From 6448ff6f8b844ae8fcbbe1a6902aa1a8f44f846e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20S=20Sch=C3=BCtze?= Date: Sat, 20 May 2023 15:22:21 +0200 Subject: [PATCH 5/5] docs: updated changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7d18a2b..067b839c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,14 +3,14 @@ ## 7.13.0 Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/515) from [mrwalters1988](https://github.com/mrwalters1988) the following: - - feat: added parameter for Add-VSTeamAccessControlEntry to choose whether to merge the Bits or to Overwrite the bits. -## 7.12.0 - Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/508) from [Miguel Nieto](https://github.com/mnieto) the following: - Fix import-module loses previously stored configuration [493](https://github.com/MethodsAndPractices/vsteam/issues/493) +## 7.12.0 + + Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/506) from [Miguel Nieto](https://github.com/mnieto) the following: - fix tests that involve dates fail when OS culture has 24 hours format