Skip to content

Commit

Permalink
fix: import-module loses previously stored configuration
Browse files Browse the repository at this point in the history
This pull request resolves two main issues. First, it fixes bug #493 where the `import-module vsteam` command was causing loss of previously stored configurations. Second, it corrects the 'Versions' test failure on local setups when `Set-VSTeamAccount` is used with the `-Local` parameter. This issue didn't surface during GitHub builds due to the `TEAM_VERSION` variable not being set. In addition to these fixes, the pull request includes updates to the change log and documentation.

---------

Co-authored-by: Sebastian S Schütze <[email protected]>
  • Loading branch information
mnieto and SebastianSchuetze authored May 20, 2023
1 parent a465383 commit ec50dc9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +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.

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

Expand All @@ -32,6 +35,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:
Expand Down
3 changes: 3 additions & 0 deletions Source/Classes/Versions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static void SetApiVersion(APIs service, string version)
case APIs.WorkItemTracking:
WorkItemTracking = version;
break;
case APIs.Version:
Version = version;
break;
}
}

Expand Down
26 changes: 20 additions & 6 deletions Source/VSTeam.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 -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 {
# 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."
}
}

Expand Down

0 comments on commit ec50dc9

Please sign in to comment.