From 9793dc67fb087de4cbad69a766b213d8f79ff141 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 11 Nov 2024 11:56:55 +0100 Subject: [PATCH 001/134] notes --- tools/dev/UserJourney.ps1 | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/dev/UserJourney.ps1 b/tools/dev/UserJourney.ps1 index 8b327f98a..fa05f7685 100644 --- a/tools/dev/UserJourney.ps1 +++ b/tools/dev/UserJourney.ps1 @@ -3,10 +3,12 @@ ### # Connect to GitHub interactively using GitHub App and Device Flow (User Access Token, UAT) -Connect-GitHub (-Host github.com) (-ClientID '') +Connect-GitHub (-Host github.com) (-ClientID '') # First should set default context # Log on to a specific instance of GitHub (enterprise) -Connect-GitHub -Host 'msx.ghe.com' +Connect-GitHub -Host 'msx.ghe.com' # Adds context, but is not default +Connect-GitHub -Host 'msx.ghe.com' -Default # Can be added as default by setting the default flag +Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' # Contexts should be selectable/overrideable on any call # Connect to GitHub interactively using OAuth App and Device Flow (should not use this, should we even support it?) Connect-GitHub -Mode 'OAuthApp' -Scope 'gist read:org repo workflow' @@ -31,6 +33,29 @@ Connect-GitHub -Token *********** # When you connect, a context is saved. # Variables, stored under "Contexts" on the existing config.json. # Secrets, names are stored in the variables. +# Context = [ +# { +# name: "github.com/MariusStorhaug" +# id: 1 +# host: "github.com" -> Public +# default: true +# type: UAT +# }, +# { +# name: "github.com/qweqweqwe" +# id: 1 +# host: "github.com" +# default: false +# type: UAT +# }, +# { +# name: "dnb.ghe.com/Marius-Storhaug" +# id: 2 +# host: "dnb.ghe.com" +# default: false +# type: UAT +# } +# ] <# $Config = @{ ConfigFilePath = 'C:\Repos\GitHub\PSModule\src\functions\private\Config\config.json' @@ -64,4 +89,14 @@ Disconnect-GitHub -Context 'name' # Removes the context variables and secrets # Calling specific functions with context or an ad-hoc token? +Get-GitHubRepository Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' + + + +Connect-GitHub -ClientID '' -PrivateKey '' +Get-GitHubOrganization +foreach (org) { + Connect-GitHub -Token *********** + Get-GitHubRepository +} From b787a0edeb103d226ae9d389472742dd0ff58494 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 12 Nov 2024 02:07:41 +0100 Subject: [PATCH 002/134] tmp --- .../public/Auth/Connect-GitHubAccount.ps1 | 30 +------ .../public/Config/Get-GitHubContext.ps1 | 6 +- .../public/Config/Set-GitHubContext.ps1 | 80 ++++++++++++++++++- 3 files changed, 85 insertions(+), 31 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 7694381d5..80b528f81 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -294,36 +294,10 @@ } } } - Set-GitHubContext @context # Needed so we can use the next authenticated functions (API calls). - try { - switch -Regex ($context['AuthType']) { - 'PAT|UAT|IAT' { - $viewer = Get-GitHubViewer - $context['Name'] = $viewer.login - $context['NodeID'] = $viewer.id - $context['DatabaseID'] = $viewer.databaseId - } - 'App' { - $app = Get-GitHubApp - $context['Name'] = $app.slug - $context['NodeID'] = $app.node_id - $context['DatabaseID'] = $app.id - } - default { - $context['Name'] = 'unknown' - $context['ID'] = 'unknown' - } - } - Set-GitHubContext @context - } catch { - Write-Verbose ($_ | Out-String) - Write-Verbose 'Failed to set the user name' - } - - Write-Verbose ($context | Format-Table | Out-String) + $context = Set-GitHubContext @context if (-not $Silent) { - $name = $(Get-GitHubConfig -Name Name) + $name = $context.Name Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged in as $name!" } diff --git a/src/functions/public/Config/Get-GitHubContext.ps1 b/src/functions/public/Config/Get-GitHubContext.ps1 index d6ff6ce82..b067383b6 100644 --- a/src/functions/public/Config/Get-GitHubContext.ps1 +++ b/src/functions/public/Config/Get-GitHubContext.ps1 @@ -15,7 +15,11 @@ function Get-GitHubContext { #> [OutputType([object])] [CmdletBinding()] - param () + param ( + # The name of the context. + [Parameter(Mandatory)] + [string] $Name + ) Get-Store -Name $script:Config.Name } diff --git a/src/functions/public/Config/Set-GitHubContext.ps1 b/src/functions/public/Config/Set-GitHubContext.ps1 index af28273f7..20eb46eed 100644 --- a/src/functions/public/Config/Set-GitHubContext.ps1 +++ b/src/functions/public/Config/Set-GitHubContext.ps1 @@ -89,8 +89,84 @@ function Set-GitHubContext { [string] $Scope ) - $storeName = $Script:Config.Name - # $storeName = $Script:Config.Name, $HostName, $Name -join '/' + # Set a temporary context. + $variables = @{ + ApiBaseUri = $ApiBaseUri # https://api.github.com + ApiVersion = $ApiVersion # 2022-11-28 + AuthClientID = $AuthClientID # Client ID for UAT + AuthType = $AuthType # UAT / PAT / App / IAT + ClientID = $ClientID # Client ID for GitHub Apps + DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp + HostName = $HostName # github.com / msx.ghe.com / github.local + NodeID = $NodeID # User ID / app ID (GraphQL Node ID) + DatabaseID = $DatabaseID # Database ID + Name = $Name # Username / app slug + Owner = $Owner # Owner name + Repo = $Repo # Repo name + Scope = $Scope # 'gist read:org repo workflow' + SecretExpirationDate = $SecretExpirationDate # 2024-01-01-00:00:00 + SecretType = $SecretType # ghu / gho / ghp / github_pat / PEM / ghs / + } + + $variables | Remove-HashtableEntry -NullOrEmptyValues + + Set-Store -Name "$($Script:Config.Name)/tempContext" -Secret $Secret -Variables $variables + + # Run functions to get info on the temporary context. + try { + switch -Regex ($variables['AuthType']) { + 'PAT|UAT|IAT' { + $viewer = Get-GitHubViewer -Context 'tempContext' + $variables['Name'] = $viewer.login + $variables['NodeID'] = $viewer.id + $variables['DatabaseID'] = $viewer.databaseId + } + 'App' { + $app = Get-GitHubApp -Context 'tempContext' + $variables['Name'] = $app.slug + $variables['NodeID'] = $app.node_id + $variables['DatabaseID'] = $app.id + } + default { + $variables['Name'] = 'unknown' + $variables['ID'] = 'unknown' + } + } + } catch { + Write-Error 'Failed to get info on the context.' + throw ($_ | Out-String) + } + + # Set the context to named context. + Set-Store -Name "$($Script:Config.Name)/$HostName/$Name" -Secret $Secret -Variables $variables + + + # Remove the temporary context. + Remove-Store -Name "$($Script:Config.Name)/tempContext" + + # IF FIRST, set the context to the default context. + # IF DEFAULT is defined, set the context to the default context. + + + + + + + + + + Write-Verbose ($context | Format-Table | Out-String) + + + + + + + + + + + $storeName = "$($Script:Config.Name)/$NodeID" if ($PSCmdlet.ShouldProcess('Context', 'Set')) { From 29da8085f63073d2d2610afdb8026648a59ab1d8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 00:30:51 +0100 Subject: [PATCH 003/134] Wreck it with all the context changes :) --- .../Test-GitHubAccessTokenRefreshRequired.ps1 | 4 +- src/functions/public/API/Invoke-GitHubAPI.ps1 | 29 ++- .../public/Auth/Connect-GitHubAccount.ps1 | 52 ++--- .../public/Auth/Context/Get-GitHubContext.ps1 | 44 ++++ .../public/Auth/Context/Set-GitHubContext.ps1 | 153 ++++++++++++++ .../Get-GitHubContextSetting.ps1 | 31 +++ .../Set-GitHubContextSetting.ps1 | 126 +++++++++++ .../public/Auth/Disconnect-GitHubAccount.ps1 | 6 +- .../public/Config/Get-GitHubConfig.ps1 | 20 +- .../public/Config/Get-GitHubContext.ps1 | 25 --- .../public/Config/Set-GitHubConfig.ps1 | 124 +---------- .../public/Config/Set-GitHubContext.ps1 | 200 ------------------ src/loader.ps1 | 15 +- tools/dev/contexts.ps1 | 12 +- tools/dev/store.ps1 | 10 +- 15 files changed, 447 insertions(+), 404 deletions(-) create mode 100644 src/functions/public/Auth/Context/Get-GitHubContext.ps1 create mode 100644 src/functions/public/Auth/Context/Set-GitHubContext.ps1 create mode 100644 src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 create mode 100644 src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 delete mode 100644 src/functions/public/Config/Get-GitHubContext.ps1 delete mode 100644 src/functions/public/Config/Set-GitHubContext.ps1 diff --git a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 index 850bacdd1..744be9183 100644 --- a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 @@ -15,13 +15,13 @@ [CmdletBinding()] param() - $tokenType = Get-GitHubConfig -Name 'SecretType' -ErrorAction SilentlyContinue + $tokenType = Get-GitHubConfig -Name 'TokenType' -ErrorAction SilentlyContinue if ($tokenType -ne 'ghu_*') { Write-Verbose 'The access token is not a user token. No need to refresh.' return $false } - $tokenExpirationDate = Get-GitHubConfig -Name 'SecretExpirationDate' -ErrorAction SilentlyContinue + $tokenExpirationDate = Get-GitHubConfig -Name 'TokenExpirationDate' -ErrorAction SilentlyContinue $currentDateTime = Get-Date $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index fe7801ac4..23365bcc1 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -32,7 +32,7 @@ [Parameter( ParameterSetName = 'ApiEndpoint' )] - [string] $ApiBaseUri = (Get-GitHubConfig -Name ApiBaseUri), + [string] $ApiBaseUri, # The specific endpoint for the API call, e.g., '/repos/user/repo/pulls'. [Parameter( @@ -74,7 +74,7 @@ # The secure token used for authentication in the GitHub API. It should be stored as a SecureString to ensure it's kept safe in memory. [Parameter()] - [SecureString] $Token = (Get-GitHubConfig -Name Secret), + [SecureString] $Token, # The 'Content-Type' header for the API request. The default is 'application/vnd.github+json'. [Parameter()] @@ -82,18 +82,31 @@ # The GitHub API version to be used. By default, it pulls from a configuration script variable. [Parameter()] - [string] $Version = (Get-GitHubConfig -Name ApiVersion) + [string] $Version, + + # The context to use for the API call. This is used to retrieve the necessary configuration settings. + [Parameter()] + [string] $Context = 'DefaultContext' ) - $secretType = (Get-GitHubConfig -Name SecretType) - switch ($secretType) { + + + $ContextName = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText + $contextObject = Get-GitHubContext -Name $ContextName + + $ApiBaseUri = (Get-GitHubConfig -Name 'ApiBaseUri' -Context $Context) + $Token = (Get-GitHubConfig -Name 'Token' -Context $Context) + $Version = (Get-GitHubConfig -Name 'ApiVersion' -Context $Context) + + $TokenType = (Get-GitHubConfig -Name 'TokenType' -Context $Context) + switch ($tokenType) { 'ghu' { if (Test-GitHubAccessTokenRefreshRequired) { Connect-GitHubAccount -Silent - $Token = (Get-GitHubConfig -Name Secret) + $Token = (Get-GitHubConfig -Name 'Token' -Context $Context) } } 'PEM' { - $ClientID = Get-GithubConfig -Name ClientID + $ClientID = Get-GithubConfig -Name 'ClientID' -Context $Context $JWT = Get-GitHubAppJSONWebToken -ClientId $ClientID -PrivateKey $Token $Token = $JWT.Token } @@ -146,7 +159,7 @@ } try { - Write-Verbose "Calling GitHub API with the following parameters:" + Write-Verbose 'Calling GitHub API with the following parameters:' Write-Verbose ($APICall | ConvertFrom-HashTable | Format-List | Out-String) Invoke-RestMethod @APICall | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 80b528f81..1c90166e9 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -32,7 +32,7 @@ Connect-GitHubAccount -UseAccessToken ! Enter your personal access token: ************* - User gets prompted for the access token and stores it in the secret store. + User gets prompted for the access token and stores it in the context. The token is used when connecting to GitHub. .EXAMPLE @@ -183,7 +183,7 @@ Write-Verbose "Using $Mode authentication..." $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -Scope $Scope -HostName $HostName } else { - $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'SecretExpirationDate') - (Get-Date) + $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'TokenExpirationDate') - (Get-Date) $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 $hours = $accessTokenValidity.Hours.ToString().PadLeft(2, '0') $minutes = $accessTokenValidity.Minutes.ToString().PadLeft(2, '0') @@ -221,9 +221,9 @@ switch ($Mode) { 'GitHubApp' { $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - SecretExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) - SecretType = $tokenResponse.access_token -replace $tokenPrefixPattern + Token = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + TokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + TokenType = $tokenResponse.access_token -replace $tokenPrefixPattern AuthClientID = $authClientID DeviceFlowType = $Mode RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token @@ -233,8 +233,8 @@ } 'OAuthApp' { $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - SecretType = $tokenResponse.access_token -replace $tokenPrefixPattern + Token = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + TokenType = $tokenResponse.access_token -replace $tokenPrefixPattern AuthClientID = $authClientID DeviceFlowType = $Mode Scope = $tokenResponse.scope @@ -250,9 +250,9 @@ 'App' { Write-Verbose 'Logging in as a GitHub App...' $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $PrivateKey - SecretType = 'PEM' - ClientID = $ClientID + Token = ConvertTo-SecureString -AsPlainText $PrivateKey + TokenType = 'PEM' + ClientID = $ClientID } } 'PAT' { @@ -262,47 +262,49 @@ Start-Process "https://$HostName/settings/tokens" $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString $Token = ConvertFrom-SecureString $accessTokenValue -AsPlainText - $secretType = $Token -replace $tokenPrefixPattern + $tokenType = $Token -replace $tokenPrefixPattern $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $Token - SecretType = $secretType + Token = ConvertTo-SecureString -AsPlainText $Token + TokenType = $tokenType } } 'Token' { - $secretType = $Token -replace $tokenPrefixPattern - switch -Regex ($secretType) { + $tokenType = $Token -replace $tokenPrefixPattern + switch -Regex ($tokenType) { 'ghp|github_pat' { $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $Token - SecretType = $secretType + Token = ConvertTo-SecureString -AsPlainText $Token + TokenType = $tokenType } $context['AuthType'] = 'PAT' } 'ghs' { Write-Verbose 'Logging in using an installation access token...' $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $Token - SecretType = $secretType + Token = ConvertTo-SecureString -AsPlainText $Token + TokenType = $tokenType } $context['AuthType'] = 'IAT' } default { Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host "Unexpected token type: $secretType" - throw "Unexpected token type: $secretType" + Write-Host "Unexpected token type: $tokenType" + throw "Unexpected token type: $tokenType" } } } } - $context = Set-GitHubContext @context - + $context = Set-GitHubContext $context + Set-ContextSetting -Name 'DefaultContext' -Value $context['Name'] -Context $script:Config.Name + Get-GitHubConfig if (-not $Silent) { - $name = $context.Name + $name = $context.Username Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged in as $name!" } } catch { - throw $_ + Write-Error $_ + throw 'Failed to connect to GitHub.' } finally { Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue Remove-Variable -Name context -ErrorAction SilentlyContinue diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 new file mode 100644 index 000000000..dc2de7e75 --- /dev/null +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -0,0 +1,44 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } + +function Get-GitHubContext { + <# + .SYNOPSIS + Get the current GitHub context. + + .DESCRIPTION + Get the current GitHub context. + + .EXAMPLE + Get-GitHubContext + + Gets the current GitHub context. + #> + [OutputType([object])] + [CmdletBinding()] + param ( + # The name of the context. + [Parameter( + Mandatory, + ParameterSetName = 'Name' + )] + [string] $Name, + + # List all available contexts. + [Parameter( + Mandatory, + ParameterSetName = 'ListAvailable' + )] + [switch] $ListAvailable + ) + + if ($ListAvailable) { + return Get-Context -Name "$($script:Config.Name)/*" -AsPlainText + } + + if (-not $Name) { + $defaultContext = Get-ContextSetting -Name 'DefaultContext' - + return Get-Context -Name $script:Config.Name + } + + Get-Context -Name $script:Config.Name +} diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 new file mode 100644 index 000000000..84fa8a556 --- /dev/null +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -0,0 +1,153 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } + +function Set-GitHubContext { + <# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .EXAMPLE + An example + + .NOTES + General notes + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # The Node ID of the context. + [Parameter()] + [string] $NodeID, + + # The Database ID of the context. + [Parameter()] + [string] $DatabaseID, + + # Set the access token type. + [Parameter(Mandatory)] + [string] $TokenType, + + # Set the client ID. + [Parameter()] + [string] $ClientID, + + # Set the access token. + [Parameter(Mandatory)] + [securestring] $Token, + + # Set the expiration date of the contexts token. + [Parameter()] + [datetime] $TokenExpirationDate, + + # Set the API Base URI. + [Parameter(Mandatory)] + [string] $ApiBaseUri, + + # Set the GitHub API Version. + [Parameter(Mandatory)] + [string] $ApiVersion, + + # Set the authentication client ID. + [Parameter()] + [string] $AuthClientID, + + # Set the authentication type. + [Parameter(Mandatory)] + [string] $AuthType, + + # Set the device flow type. + [Parameter()] + [string] $DeviceFlowType, + + # Set the API hostname. + [Parameter(Mandatory)] + [string] $HostName, + + # Set the default for the Owner parameter. + [Parameter()] + [string] $Owner, + + # Set the refresh token. + [Parameter()] + [securestring] $RefreshToken, + + # Set the refresh token expiration date. + [Parameter()] + [datetime] $RefreshTokenExpirationDate, + + # Set the default for the Repo parameter. + [Parameter()] + [string] $Repo, + + # Set the scope. + [Parameter()] + [string] $Scope + ) + + $tempContextName = 'tempContext' + $Name = "$($script:Config.Name)/$tempContextName" + + # Set a temporary context. + $context = @{ + ApiBaseUri = $ApiBaseUri # https://api.github.com + ApiVersion = $ApiVersion # 2022-11-28 + AuthClientID = $AuthClientID # Client ID for UAT + AuthType = $AuthType # UAT / PAT / App / IAT + ClientID = $ClientID # Client ID for GitHub Apps + DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp + HostName = $HostName # github.com / msx.ghe.com / github.local + NodeID = $NodeID # User ID / app ID (GraphQL Node ID) + DatabaseID = $DatabaseID # Database ID + Name = $Name # HostName/Username or HostName/AppSlug + UserName = $UserName # User name + Owner = $Owner # Owner name + Repo = $Repo # Repo name + Scope = $Scope # 'gist read:org repo workflow' + #----------------------------------------------------------------------------------------- + TokenType = $TokenType # ghu / gho / ghp / github_pat / PEM / ghs / + Token = $Token # Access token + TokenExpirationDate = $TokenExpirationDate # 2024-01-01-00:00:00 + RefreshToken = $RefreshToken # Refresh token + RefreshTokenExpirationDate = $RefreshTokenExpirationDate # 2024-01-01-00:00:00 + } + + $context | Remove-HashtableEntry -NullOrEmptyValues + + Set-Context $context + + # Run functions to get info on the temporary context. + try { + switch -Regex ($context['AuthType']) { + 'PAT|UAT|IAT' { + $viewer = Get-GitHubViewer -Context $tempContextName + $context['Name'] = "$($Script:Config.Name)/$HostName/$($viewer.login)" + $context['Username'] = $viewer.login + $context['NodeID'] = $viewer.id + $context['DatabaseID'] = $viewer.databaseId + } + 'App' { + $app = Get-GitHubApp -Context $tempContextName + $context['Name'] = "$($Script:Config.Name)/$HostName/$($app.slug)" + $context['Username'] = $app.slug + $context['NodeID'] = $app.node_id + $context['DatabaseID'] = $app.id + } + default { + throw 'Failed to get info on the context. Unknown logon type.' + } + } + } catch { + Write-Error $_ + throw 'Failed to get info on the context.' + } + + if ($PSCmdlet.ShouldProcess('Context', 'Set')) { + # Set the context to named context. + Set-Context $context + + # Remove the temporary context. + Remove-Context -Name $tempContextName + } + Get-Context -Name $context['Name'] -AsPlainText +} diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 new file mode 100644 index 000000000..c600f8a02 --- /dev/null +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -0,0 +1,31 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } + +function Get-GitHubConfig { + <# + .SYNOPSIS + Get a module configuration value. + + .DESCRIPTION + Get a named configuration value from the GitHub config. + + .EXAMPLE + Get-GitHubConfig -Name DefaultUser + + Get the current GitHub configuration for the DefaultUser. + #> + [Alias('Get-GHConfig')] + [Alias('GGHC')] + [OutputType([object])] + [CmdletBinding()] + param ( + # Choose a configuration name to get. + [Parameter()] + [string] $Name + ) + + if (-not $Name) { + Get-Context -Name $script:Config.Name -AsPlainText + } + + Get-ContextSetting -Name $Name -Context $script:Config.Name -AsPlainText +} diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 new file mode 100644 index 000000000..36f9f10a7 --- /dev/null +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -0,0 +1,126 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } + +function Set-GitHubContextSetting { + <# + .SYNOPSIS + Set the GitHub configuration. + + .DESCRIPTION + Set the GitHub configuration. Specific scopes can be set by using the parameters. + + .EXAMPLE + Set-GitHubConfig -APIBaseURI 'https://api.github.com" -APIVersion '2022-11-28' + + Sets the App.API scope of the GitHub configuration. + + .EXAMPLE + Set-GitHubConfig -Name "MyFavouriteRepo" -Value 'https://github.com/PSModule/GitHub' + + Sets a item called 'MyFavouriteRepo' in the GitHub configuration. + #> + [Alias('Set-GHConfig')] + [CmdletBinding(SupportsShouldProcess)] + param ( + # Set the access token type. + [Parameter()] + [string] $TokenType, + + # The Node ID of the context. + [Parameter()] + [string] $NodeID, + + # The Database ID of the context. + [Parameter()] + [string] $DatabaseID, + + # Set the access token. + [Parameter()] + [securestring] $Token, + + # Set the access token expiration date. + [Parameter()] + [datetime] $TokenExpirationDate, + + # Set the API Base URI. + [Parameter()] + [string] $ApiBaseUri, + + # Set the GitHub API Version. + [Parameter()] + [string] $ApiVersion, + + # Set the authentication client ID. + [Parameter()] + [string] $AuthClientID, + + # Set the authentication type. + [Parameter()] + [string] $AuthType, + + # Set the client ID. + [Parameter()] + [string] $ClientID, + + # Set the device flow type. + [Parameter()] + [string] $DeviceFlowType, + + # Set the default for the Owner parameter. + [Parameter()] + [string] $Owner, + + # Set the refresh token. + [Parameter()] + [securestring] $RefreshToken, + + # Set the refresh token expiration date. + [Parameter()] + [datetime] $RefreshTokenExpirationDate, + + # Set the default for the Repo parameter. + [Parameter()] + [string] $Repo, + + # Set the scope. + [Parameter()] + [string] $Scope + ) + + $storeName = $Script:Config.Name + + if ($PSCmdlet.ShouldProcess('Config', 'Set')) { + + if ($RefreshToken) { + Set-Context -Name "$storeName/RefreshToken" -Token $RefreshToken -Variables @{ + RefreshTokenExpirationDate = $RefreshTokenExpirationDate + } + } + + $variables = @{ + ApiBaseUri = $ApiBaseUri + ApiVersion = $ApiVersion + AuthClientID = $AuthClientID + AuthType = $AuthType + ClientID = $ClientID + DeviceFlowType = $DeviceFlowType + HostName = $HostName + NodeID = $NodeID + DatabaseID = $DatabaseID + Owner = $Owner + Repo = $Repo + Scope = $Scope + Token = $Token + TokenExpirationDate = $TokenExpirationDate + TokenType = $TokenType + } + + $variables | Remove-HashtableEntry -NullOrEmptyValues + + foreach ($key in $variables.Keys) { + if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$($variables[$key])]")) { + Write-Verbose "Setting [$key] to [$($variables[$key])]" + Set-ContextSetting -Name $key -Value $variables[$key] -Context $script:Config.Name + } + } + } +} diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 27a599f00..8fc3fc749 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -27,8 +27,10 @@ [CmdletBinding()] param () - Remove-Store -Name $script:Config.Name + $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name + Remove-Context -Name "$($script:Config.Name)/$defaultContext" + Set-ContextSetting -Name 'DefaultContext' -Value '' -Context $script:Config.Name Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host 'Logged out of GitHub!' + Write-Host "Logged out of GitHub! [$defaultContext]" } diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index ca595aeb0..d521eeaec 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,31 +1,29 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } function Get-GitHubConfig { <# .SYNOPSIS - Get configuration value. + Get a GitHub module configuration. .DESCRIPTION - Get a named configuration value from the GitHub configuration file. + Get a GitHub module configuration. .EXAMPLE - Get-GitHubConfig -Name ApiBaseUri + Get-GitHubConfig -Name DefaultUser - Get the current GitHub configuration for the ApiBaseUri. + Get the current GitHub configuration for the DefaultUser. #> - [Alias('Get-GHConfig')] - [Alias('GGHC')] - [OutputType([object])] + [OutputType([void])] [CmdletBinding()] param ( - # Choose a configuration name to get. + # The name of the configuration to get. [Parameter()] [string] $Name ) if (-not $Name) { - return Get-GitHubContext + Get-Context -Name $script:Config.Name -AsPlainText } - Get-StoreConfig -Name $Name -Store $script:Config.Name + Get-ContextSetting -Name $Name -Context $script:Config.Name -AsPlainText } diff --git a/src/functions/public/Config/Get-GitHubContext.ps1 b/src/functions/public/Config/Get-GitHubContext.ps1 deleted file mode 100644 index 1b658303c..000000000 --- a/src/functions/public/Config/Get-GitHubContext.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } - -function Get-GitHubContext { - <# - .SYNOPSIS - Get the current GitHub context. - - .DESCRIPTION - Get the current GitHub context. - - .EXAMPLE - Get-GitHubContext - - Gets the current GitHub context. - #> - [OutputType([object])] - [CmdletBinding()] - param ( - # The name of the context. - [Parameter(Mandatory)] - [string] $Name - ) - - Get-Store -Name $script:Config.Name -} diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 0d3486b00..3ed8226b2 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,135 +1,31 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } function Set-GitHubConfig { <# .SYNOPSIS - Set the GitHub configuration. + Set a GitHub module configuration. .DESCRIPTION - Set the GitHub configuration. Specific scopes can be set by using the parameters. + Set a GitHub module configuration. .EXAMPLE - Set-GitHubConfig -APIBaseURI 'https://api.github.com" -APIVersion '2022-11-28' + Set-GitHubConfig -Name DefaultUser -Value 'Octocat' - Sets the App.API scope of the GitHub configuration. - - .EXAMPLE - Set-GitHubConfig -Name "MyFavouriteRepo" -Value 'https://github.com/PSModule/GitHub' - - Sets a item called 'MyFavouriteRepo' in the GitHub configuration. + Sets the DefaultUser item in the GitHub configuration to 'Octocat'. #> [Alias('Set-GHConfig')] [CmdletBinding(SupportsShouldProcess)] param ( # Set the access token type. [Parameter()] - [string] $SecretType, - - # The Node ID of the context. - [Parameter()] - [string] $NodeID, - - # The Database ID of the context. - [Parameter()] - [string] $DatabaseID, - - # Set the access token. - [Parameter()] - [securestring] $Secret, - - # Set the access token expiration date. - [Parameter()] - [datetime] $SecretExpirationDate, - - # Set the API Base URI. - [Parameter()] - [string] $ApiBaseUri, - - # Set the GitHub API Version. - [Parameter()] - [string] $ApiVersion, - - # Set the authentication client ID. - [Parameter()] - [string] $AuthClientID, - - # Set the authentication type. - [Parameter()] - [string] $AuthType, - - # Set the client ID. - [Parameter()] - [string] $ClientID, + [string] $Name, - # Set the device flow type. - [Parameter()] - [string] $DeviceFlowType, - - # Set the API hostname. - [Parameter()] - [string] $HostName, - - # Set the default for the Owner parameter. - [Parameter()] - [string] $Owner, - - # Set the refresh token. - [Parameter()] - [securestring] $RefreshToken, - - # Set the refresh token expiration date. - [Parameter()] - [datetime] $RefreshTokenExpirationDate, - - # Set the default for the Repo parameter. - [Parameter()] - [string] $Repo, - - # Set the scope. - [Parameter()] - [string] $Scope, - - # Set the GitHub username. + # Set the access token type. [Parameter()] - [string] $Name + [string] $Value ) - $storeName = $Script:Config.Name - - if ($PSCmdlet.ShouldProcess('Config', 'Set')) { - - if ($RefreshToken) { - Set-Store -Name "$storeName/RefreshToken" -Secret $RefreshToken -Variables @{ - RefreshTokenExpirationDate = $RefreshTokenExpirationDate - } - } - - $variables = @{ - ApiBaseUri = $ApiBaseUri - ApiVersion = $ApiVersion - AuthClientID = $AuthClientID - AuthType = $AuthType - ClientID = $ClientID - DeviceFlowType = $DeviceFlowType - HostName = $HostName - NodeID = $NodeID - DatabaseID = $DatabaseID - Name = $Name - Owner = $Owner - Repo = $Repo - Scope = $Scope - Secret = $Secret - SecretExpirationDate = $SecretExpirationDate - SecretType = $SecretType - } - - $variables | Remove-HashtableEntry -NullOrEmptyValues - - foreach ($key in $variables.Keys) { - if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$($variables[$key])]")) { - Write-Verbose "Setting [$key] to [$($variables[$key])]" - Set-StoreConfig -Name $key -Value $variables[$key] -Store $script:Config.Name - } - } + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Set')) { + Set-ContextSetting -Name $Name -Value $Value -Context $script:Config.Name } } diff --git a/src/functions/public/Config/Set-GitHubContext.ps1 b/src/functions/public/Config/Set-GitHubContext.ps1 deleted file mode 100644 index 99041d892..000000000 --- a/src/functions/public/Config/Set-GitHubContext.ps1 +++ /dev/null @@ -1,200 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } - -function Set-GitHubContext { - <# - .SYNOPSIS - Short description - - .DESCRIPTION - Long description - - .EXAMPLE - An example - - .NOTES - General notes - #> - [CmdletBinding(SupportsShouldProcess)] - param ( - # The name of the context. - [Parameter(Mandatory)] - [string] $Name, - - # The Node ID of the context. - [Parameter()] - [string] $NodeID, - - # The Database ID of the context. - [Parameter()] - [string] $DatabaseID, - - # Set the access token type. - [Parameter(Mandatory)] - [string] $SecretType, - - # Set the client ID. - [Parameter()] - [string] $ClientID, - - # Set the access token. - [Parameter(Mandatory)] - [securestring] $Secret, - - # Set the expiration date of the contexts secret. - [Parameter()] - [datetime] $SecretExpirationDate, - - # Set the API Base URI. - [Parameter(Mandatory)] - [string] $ApiBaseUri, - - # Set the GitHub API Version. - [Parameter(Mandatory)] - [string] $ApiVersion, - - # Set the authentication client ID. - [Parameter()] - [string] $AuthClientID, - - # Set the authentication type. - [Parameter(Mandatory)] - [string] $AuthType, - - # Set the device flow type. - [Parameter()] - [string] $DeviceFlowType, - - # Set the API hostname. - [Parameter(Mandatory)] - [string] $HostName, - - # Set the default for the Owner parameter. - [Parameter()] - [string] $Owner, - - # Set the refresh token. - [Parameter()] - [securestring] $RefreshToken, - - # Set the refresh token expiration date. - [Parameter()] - [datetime] $RefreshTokenExpirationDate, - - # Set the default for the Repo parameter. - [Parameter()] - [string] $Repo, - - # Set the scope. - [Parameter()] - [string] $Scope - ) - - # Set a temporary context. - $variables = @{ - ApiBaseUri = $ApiBaseUri # https://api.github.com - ApiVersion = $ApiVersion # 2022-11-28 - AuthClientID = $AuthClientID # Client ID for UAT - AuthType = $AuthType # UAT / PAT / App / IAT - ClientID = $ClientID # Client ID for GitHub Apps - DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp - HostName = $HostName # github.com / msx.ghe.com / github.local - NodeID = $NodeID # User ID / app ID (GraphQL Node ID) - DatabaseID = $DatabaseID # Database ID - Name = $Name # Username / app slug - Owner = $Owner # Owner name - Repo = $Repo # Repo name - Scope = $Scope # 'gist read:org repo workflow' - SecretExpirationDate = $SecretExpirationDate # 2024-01-01-00:00:00 - SecretType = $SecretType # ghu / gho / ghp / github_pat / PEM / ghs / - } - - $variables | Remove-HashtableEntry -NullOrEmptyValues - - Set-Store -Name "$($Script:Config.Name)/tempContext" -Secret $Secret -Variables $variables - - # Run functions to get info on the temporary context. - try { - switch -Regex ($variables['AuthType']) { - 'PAT|UAT|IAT' { - $viewer = Get-GitHubViewer -Context 'tempContext' - $variables['Name'] = $viewer.login - $variables['NodeID'] = $viewer.id - $variables['DatabaseID'] = $viewer.databaseId - } - 'App' { - $app = Get-GitHubApp -Context 'tempContext' - $variables['Name'] = $app.slug - $variables['NodeID'] = $app.node_id - $variables['DatabaseID'] = $app.id - } - default { - $variables['Name'] = 'unknown' - $variables['ID'] = 'unknown' - } - } - } catch { - Write-Error 'Failed to get info on the context.' - throw ($_ | Out-String) - } - - # Set the context to named context. - Set-Store -Name "$($Script:Config.Name)/$HostName/$Name" -Secret $Secret -Variables $variables - - - # Remove the temporary context. - Remove-Store -Name "$($Script:Config.Name)/tempContext" - - # IF FIRST, set the context to the default context. - # IF DEFAULT is defined, set the context to the default context. - - - - - - - - - - Write-Verbose ($context | Format-Table | Out-String) - - - - - - - - - - - $storeName = "$($Script:Config.Name)/$NodeID" - - if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - - if ($RefreshToken) { - Set-Store -Name "$storeName/RefreshToken" -Secret $RefreshToken -Variables @{ - RefreshTokenExpirationDate = $RefreshTokenExpirationDate - } - } - $variables = @{ - ApiBaseUri = $ApiBaseUri # https://api.github.com - ApiVersion = $ApiVersion # 2022-11-28 - AuthClientID = $AuthClientID # Client ID for UAT - AuthType = $AuthType # UAT / PAT / App / IAT - ClientID = $ClientID # Client ID for GitHub Apps - DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp - HostName = $HostName # github.com / msx.ghe.com / github.local - NodeID = $NodeID # User ID / app ID (GraphQL Node ID) - DatabaseID = $DatabaseID # Database ID - Name = $Name # Username / app slug - Owner = $Owner # Owner name - Repo = $Repo # Repo name - Scope = $Scope # 'gist read:org repo workflow' - SecretExpirationDate = $SecretExpirationDate # 2024-01-01-00:00:00 - SecretType = $SecretType # ghu / gho / ghp / github_pat / PEM / ghs / - } - - $variables | Remove-HashtableEntry -NullOrEmptyValues - - Set-Store -Name $storeName -Secret $Secret -Variables $variables - } -} diff --git a/src/loader.ps1 b/src/loader.ps1 index afedb29d5..34a925e67 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -1,6 +1,9 @@ -$scriptFilePath = $MyInvocation.MyCommand.Path +$moduleInfo = $MyInvocation.MyCommand +$scriptFilePath = $MyInvocation.MyCommand.Path + Write-Verbose "[$scriptFilePath] - Initializing GitHub PowerShell module..." +Write-Verbose ($moduleInfo.Module | Out-String) if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' @@ -8,9 +11,9 @@ if ($env:GITHUB_ACTIONS -eq 'true') { Set-GitHubEnv -Name 'GITHUB_REPOSITORY_NAME' -Value $env:GITHUB_REPOSITORY_NAME } -### This is the store config for this module -$storeParams = @{ - Name = $script:Config.Name - Variables = @{} +### This is the context for this module +$contextParams = @{ + Name = $script:Config.Name + DefaultContext = 'null' } -Set-Store @storeParams +Set-Context @contextParams diff --git a/tools/dev/contexts.ps1 b/tools/dev/contexts.ps1 index bc4c8f14b..8e6220dca 100644 --- a/tools/dev/contexts.ps1 +++ b/tools/dev/contexts.ps1 @@ -4,8 +4,8 @@ ApiVersion = $ApiVersion HostName = $HostName AuthType = $authType # 'UAT', 'PAT', 'IAT', 'APP' - Secret = $tokenResponse.access_token - SecretType = $AccessTokenType # 'UAT', 'PAT classic' 'PAT modern', 'PEM', 'IAT' + Token = $tokenResponse.access_token + TokenType = $AccessTokenType # 'UAT', 'PAT classic' 'PAT modern', 'PEM', 'IAT' id = 'MariusStorhaug' # username/slug, clientid } UAT = @{ @@ -13,7 +13,7 @@ DeviceFlowType = $Mode UATGHA = @{ - SecretExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + TokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) RefreshToken = $tokenResponse.refresh_token RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) } @@ -23,14 +23,14 @@ } } PAT = @{ - Secret = $accessTokenValue + Token = $accessTokenValue AccessTokenType = $accessTokenType } APP = @{ - Secret = $PEM + Token = $PEM } # => Generates JWT when used towards an org/user IAT = @{ - Secret = $AccessToken + Token = $AccessToken AccessTokenType = $accessTokenType } } diff --git a/tools/dev/store.ps1 b/tools/dev/store.ps1 index 4542c05d0..7112807e2 100644 --- a/tools/dev/store.ps1 +++ b/tools/dev/store.ps1 @@ -1,19 +1,19 @@ -Set-Store -Name 'PSModule.Store' -Secret 'qwe' -Metadata @{ +Set-Context -Name 'PSModule.Store' -Secret 'qwe' -Metadata @{ SecretVaultName = 'SecretStore' SecretVaultType = 'Microsoft.PowerShell.SecretStore' } -Set-StoreConfig -Name SecretVaultName -Value $null -Store 'PSModule.Store' +Set-ContextSetting -Name SecretVaultName -Value $null -Context 'PSModule.Store' -Get-StoreConfig -Name SecretVaultName -Store 'PSModule.Store' +Get-ContextSetting -Name SecretVaultName -Context 'PSModule.Store' -Get-Store -Name 'PSModule.Store' +Get-Context -Name 'PSModule.Store' Set-Secret -Name 'PSModule.GitHub' -Secret 'qwe' -Metadata @{ defaultContext = 'github.com/MariusStorhaug' } -Get-Store -Name 'PSModule.GitHub' -AsPlainText +Get-Context -Name 'PSModule.GitHub' -AsPlainText Set-Secret -Name 'GitHubPowerShell/github.com/MariusStorhaug' -Secret 'qwe' -Metadata @{ Username = 'MariusStorhaug' From eb6af12a54eadfde4d361aa9984852a96f09c545 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 00:34:11 +0100 Subject: [PATCH 004/134] Fix loader --- src/loader.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index 34a925e67..a07f20cdf 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -12,8 +12,7 @@ if ($env:GITHUB_ACTIONS -eq 'true') { } ### This is the context for this module -$contextParams = @{ +Set-Context @{ Name = $script:Config.Name DefaultContext = 'null' } -Set-Context @contextParams From 798d1d12beee7d1ded0fc181d30d46fa103635d4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 00:41:32 +0100 Subject: [PATCH 005/134] Fix get-ghconfig --- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 6 ++---- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 4 ++-- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index c600f8a02..f71c6d9aa 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,6 +1,6 @@ #Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } -function Get-GitHubConfig { +function Get-GitHubContextSetting { <# .SYNOPSIS Get a module configuration value. @@ -9,12 +9,10 @@ function Get-GitHubConfig { Get a named configuration value from the GitHub config. .EXAMPLE - Get-GitHubConfig -Name DefaultUser + Get-GitHubContextSetting -Name DefaultUser Get the current GitHub configuration for the DefaultUser. #> - [Alias('Get-GHConfig')] - [Alias('GGHC')] [OutputType([object])] [CmdletBinding()] param ( diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 36f9f10a7..ad7a4a40b 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -9,12 +9,12 @@ function Set-GitHubContextSetting { Set the GitHub configuration. Specific scopes can be set by using the parameters. .EXAMPLE - Set-GitHubConfig -APIBaseURI 'https://api.github.com" -APIVersion '2022-11-28' + Set-GitHubContextSetting -APIBaseURI 'https://api.github.com" -APIVersion '2022-11-28' Sets the App.API scope of the GitHub configuration. .EXAMPLE - Set-GitHubConfig -Name "MyFavouriteRepo" -Value 'https://github.com/PSModule/GitHub' + Set-GitHubContextSetting -Name "MyFavouriteRepo" -Value 'https://github.com/PSModule/GitHub' Sets a item called 'MyFavouriteRepo' in the GitHub configuration. #> diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index d521eeaec..f47d2c843 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -22,7 +22,7 @@ function Get-GitHubConfig { ) if (-not $Name) { - Get-Context -Name $script:Config.Name -AsPlainText + return Get-Context -Name $script:Config.Name -AsPlainText } Get-ContextSetting -Name $Name -Context $script:Config.Name -AsPlainText From 597e8ecac5399140ac7c7db81fb354cf2256472d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 00:48:54 +0100 Subject: [PATCH 006/134] Add remove + cleanup odcs --- .../public/Config/Get-GitHubConfig.ps1 | 2 +- .../public/Config/Remove-GitHubConfig.ps1 | 26 +++++++++++++++++++ .../public/Config/Set-GitHubConfig.ps1 | 3 +-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/functions/public/Config/Remove-GitHubConfig.ps1 diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index f47d2c843..b17f54305 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -11,7 +11,7 @@ function Get-GitHubConfig { .EXAMPLE Get-GitHubConfig -Name DefaultUser - Get the current GitHub configuration for the DefaultUser. + Get the DefaultUser value from the GitHub module configuration. #> [OutputType([void])] [CmdletBinding()] diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 new file mode 100644 index 000000000..d113e2c23 --- /dev/null +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -0,0 +1,26 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } + +function Remove-GitHubConfig { + <# + .SYNOPSIS + Remove a GitHub module configuration. + + .DESCRIPTION + Remove a GitHub module configuration. + + .EXAMPLE + Remove-GitHubConfig -Name DefaultUser + + Removes the 'DefaultUser' item in the GitHub module configuration. + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # Set the access token type. + [Parameter()] + [string] $Name + ) + + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) { + Set-ContextSetting -Name $Name -Value $null -Context $script:Config.Name + } +} diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 3ed8226b2..30f65ad24 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -11,9 +11,8 @@ function Set-GitHubConfig { .EXAMPLE Set-GitHubConfig -Name DefaultUser -Value 'Octocat' - Sets the DefaultUser item in the GitHub configuration to 'Octocat'. + Sets the value of DefaultUser to 'Octocat' in the GitHub module configuration. #> - [Alias('Set-GHConfig')] [CmdletBinding(SupportsShouldProcess)] param ( # Set the access token type. From 814fbccf6643b4abe70f8fbbcdfedfa569009873 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 01:30:55 +0100 Subject: [PATCH 007/134] Update to Context 2.0.1 --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index dc2de7e75..4947177bf 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 84fa8a556..300a8ee8c 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index f71c6d9aa..ade45e57a 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index ad7a4a40b..333274e8f 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index b17f54305..bdc062398 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index d113e2c23..377a0c226 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 30f65ad24..4fa37e8a1 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } function Set-GitHubConfig { <# From fbeacafb134f8f5795eaa2915b8c7b9fe24148a1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 12:15:45 +0100 Subject: [PATCH 008/134] Refactor GitHub context handling to use splatting for improved clarity --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 1c90166e9..af52548d9 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -294,7 +294,7 @@ } } } - $context = Set-GitHubContext $context + $context = Set-GitHubContext @context Set-ContextSetting -Name 'DefaultContext' -Value $context['Name'] -Context $script:Config.Name Get-GitHubConfig if (-not $Silent) { diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 300a8ee8c..d66d530d7 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -114,7 +114,7 @@ function Set-GitHubContext { $context | Remove-HashtableEntry -NullOrEmptyValues - Set-Context $context + Set-Context $context # Not splatting, but actually passing the hashtable. # Run functions to get info on the temporary context. try { @@ -143,10 +143,7 @@ function Set-GitHubContext { } if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - # Set the context to named context. Set-Context $context - - # Remove the temporary context. Remove-Context -Name $tempContextName } Get-Context -Name $context['Name'] -AsPlainText From 6dbd20803a36d49728d63ee8b3f25291e5cd5d24 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 12:45:39 +0100 Subject: [PATCH 009/134] Enhance loader script to re-load preexisting settings from module context --- src/loader.ps1 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index a07f20cdf..52656065a 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -3,7 +3,10 @@ $scriptFilePath = $MyInvocation.MyCommand.Path Write-Verbose "[$scriptFilePath] - Initializing GitHub PowerShell module..." -Write-Verbose ($moduleInfo.Module | Out-String) +Write-Verbose ($moduleInfo.Version | Out-String) +Write-Verbose ($moduleInfo.CommandType | Out-String) +Write-Verbose ($moduleInfo.ModuleName | Out-String) +Write-Verbose ($moduleInfo.Name | Out-String) if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' @@ -12,7 +15,11 @@ if ($env:GITHUB_ACTIONS -eq 'true') { } ### This is the context for this module -Set-Context @{ - Name = $script:Config.Name - DefaultContext = 'null' -} +# Get current module context +$context = Get-Context -Name $script:Config.Name -AsPlainText + +# Add values from the variables, if the values are not present in the context +$context['Name'] = $context['Name'] ?? $script:Config.Name + +# Set the context using the values from the variables +Set-Context @context From 8b7927a8a44441fb4c5da0f4175279b98bbcd27e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 12:46:19 +0100 Subject: [PATCH 010/134] Refactor Get-GitHubContext function to improve context retrieval logic and set DefaultContext in configuration --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 8 ++++---- src/variables/private/Config.ps1 | 3 ++- tools/dev/UserJourney.ps1 | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 4947177bf..f68b38fa2 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -35,10 +35,10 @@ function Get-GitHubContext { return Get-Context -Name "$($script:Config.Name)/*" -AsPlainText } - if (-not $Name) { - $defaultContext = Get-ContextSetting -Name 'DefaultContext' - - return Get-Context -Name $script:Config.Name + if ($Name) { + return Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText } - Get-Context -Name $script:Config.Name + $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText + Get-Context -Name "$($script:Config.Name)/$defaultContext" } diff --git a/src/variables/private/Config.ps1 b/src/variables/private/Config.ps1 index 8d3d0de05..8daa18311 100644 --- a/src/variables/private/Config.ps1 +++ b/src/variables/private/Config.ps1 @@ -1,3 +1,4 @@ $script:Config = @{ - Name = 'PSModule.GitHub' # $script:Config.Name + Name = 'PSModule.GitHub' # $script:Config.Name + DefaultContext = 'null' } diff --git a/tools/dev/UserJourney.ps1 b/tools/dev/UserJourney.ps1 index fa05f7685..400191fbb 100644 --- a/tools/dev/UserJourney.ps1 +++ b/tools/dev/UserJourney.ps1 @@ -96,7 +96,7 @@ Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' Connect-GitHub -ClientID '' -PrivateKey '' Get-GitHubOrganization -foreach (org) { - Connect-GitHub -Token *********** - Get-GitHubRepository -} +# foreach (org) { +# Connect-GitHub -Token *********** +# Get-GitHubRepository +# } From 4f8248eb3ca1ed08cc93793189fbed3d8fd1ffd0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 12:55:44 +0100 Subject: [PATCH 011/134] Fix loading --- src/loader.ps1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index 52656065a..cccf911b1 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -3,10 +3,6 @@ $scriptFilePath = $MyInvocation.MyCommand.Path Write-Verbose "[$scriptFilePath] - Initializing GitHub PowerShell module..." -Write-Verbose ($moduleInfo.Version | Out-String) -Write-Verbose ($moduleInfo.CommandType | Out-String) -Write-Verbose ($moduleInfo.ModuleName | Out-String) -Write-Verbose ($moduleInfo.Name | Out-String) if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' @@ -19,7 +15,7 @@ if ($env:GITHUB_ACTIONS -eq 'true') { $context = Get-Context -Name $script:Config.Name -AsPlainText # Add values from the variables, if the values are not present in the context -$context['Name'] = $context['Name'] ?? $script:Config.Name +$context['Name'] = $context.Name ?? $script:Config.Name # Set the context using the values from the variables Set-Context @context From 2c2e9dd023c556d36c3c9eee7307ec7147505690 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 13:11:34 +0100 Subject: [PATCH 012/134] Improve context initialization by creating a new context if none exists --- src/loader.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index cccf911b1..000a8bfb1 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -12,10 +12,10 @@ if ($env:GITHUB_ACTIONS -eq 'true') { ### This is the context for this module # Get current module context -$context = Get-Context -Name $script:Config.Name -AsPlainText - -# Add values from the variables, if the values are not present in the context -$context['Name'] = $context.Name ?? $script:Config.Name - -# Set the context using the values from the variables -Set-Context @context +$context = (Get-Context -Name $script:Config.Name -AsPlainText) +if (-not $context) { + Write-Verbose 'No context found, creating a new context...' + Set-Context @{ + Name = $script:Config.Name + } +} From f92e355a628597affc227716d998e1b5463f0742 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 13:11:45 +0100 Subject: [PATCH 013/134] FIx --- src/loader.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index 000a8bfb1..4c61622bb 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -1,5 +1,4 @@ -$moduleInfo = $MyInvocation.MyCommand -$scriptFilePath = $MyInvocation.MyCommand.Path +$scriptFilePath = $MyInvocation.MyCommand.Path Write-Verbose "[$scriptFilePath] - Initializing GitHub PowerShell module..." From e23e708b59d8c6f7d62bcab5e217dde9cb5e4187 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 13:27:45 +0100 Subject: [PATCH 014/134] Fix Set-GHContext in connect --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index af52548d9..1c90166e9 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -294,7 +294,7 @@ } } } - $context = Set-GitHubContext @context + $context = Set-GitHubContext $context Set-ContextSetting -Name 'DefaultContext' -Value $context['Name'] -Context $script:Config.Name Get-GitHubConfig if (-not $Silent) { From a84a6c5d6381b9b8c8d344103ab59aeecd2f35bb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 13:37:11 +0100 Subject: [PATCH 015/134] Fix --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 1c90166e9..344ea1ce9 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -156,7 +156,6 @@ } $context = @{ - Name = 'tmp' ApiBaseUri = $ApiBaseUri ApiVersion = $ApiVersion HostName = $HostName @@ -294,7 +293,7 @@ } } } - $context = Set-GitHubContext $context + $context = Set-GitHubContext @context Set-ContextSetting -Name 'DefaultContext' -Value $context['Name'] -Context $script:Config.Name Get-GitHubConfig if (-not $Silent) { From a3a2a0d4fb92dc1546d5e35a0d46fba808a1ecb3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 13:51:50 +0100 Subject: [PATCH 016/134] Fix context setting in Connect-GitHubAccount and update context removal in Set-GitHubContext --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 344ea1ce9..4d43c3e1c 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -294,7 +294,7 @@ } } $context = Set-GitHubContext @context - Set-ContextSetting -Name 'DefaultContext' -Value $context['Name'] -Context $script:Config.Name + Set-GitHubConfig -Name 'DefaultContext' -Value $context['Name'] Get-GitHubConfig if (-not $Silent) { $name = $context.Username diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index d66d530d7..2a6424820 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -144,7 +144,7 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context - Remove-Context -Name $tempContextName + Remove-Context -Name "$($script:Config.Name)/$tempContextName" } Get-Context -Name $context['Name'] -AsPlainText } From 4d3e7e326fd0715db25d6b8b7320a10b237da268 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 14:25:40 +0100 Subject: [PATCH 017/134] Enhance GitHub API commands to utilize context settings for improved configuration management --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 21 ++++++++++--------- .../public/Auth/Get-GitHubViewer.ps1 | 8 +++++-- .../GraphQL/Invoke-GitHubGraphQLQuery.ps1 | 6 +++++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 23365bcc1..e37993611 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -86,27 +86,28 @@ # The context to use for the API call. This is used to retrieve the necessary configuration settings. [Parameter()] - [string] $Context = 'DefaultContext' + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) + $context = Get-GitHubContext -Name $Context + if (-not $context) { + throw 'Log in using Connect-GitHub before running this command.' + } - $ContextName = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText - $contextObject = Get-GitHubContext -Name $ContextName - - $ApiBaseUri = (Get-GitHubConfig -Name 'ApiBaseUri' -Context $Context) - $Token = (Get-GitHubConfig -Name 'Token' -Context $Context) - $Version = (Get-GitHubConfig -Name 'ApiVersion' -Context $Context) - + $ApiBaseUri = $ApiBaseUri ?? ($context['ApiBaseUri'] | ConvertFrom-SecureString -AsPlainText) + $Version = $Version ?? ($context['ApiVersion'] | ConvertFrom-SecureString -AsPlainText) $TokenType = (Get-GitHubConfig -Name 'TokenType' -Context $Context) + $Token = $Token ?? $context['Token'] + switch ($tokenType) { 'ghu' { if (Test-GitHubAccessTokenRefreshRequired) { Connect-GitHubAccount -Silent - $Token = (Get-GitHubConfig -Name 'Token' -Context $Context) + $Token = (Get-GitHubContextSetting -Name 'Token' -Context $Context) } } 'PEM' { - $ClientID = Get-GithubConfig -Name 'ClientID' -Context $Context + $ClientID = (Get-GitHubContextSetting -Name 'ClientID' -Context $Context) $JWT = Get-GitHubAppJSONWebToken -ClientId $ClientID -PrivateKey $Token $Token = $JWT.Token } diff --git a/src/functions/public/Auth/Get-GitHubViewer.ps1 b/src/functions/public/Auth/Get-GitHubViewer.ps1 index d29d8a863..b748c7fd2 100644 --- a/src/functions/public/Auth/Get-GitHubViewer.ps1 +++ b/src/functions/public/Auth/Get-GitHubViewer.ps1 @@ -16,7 +16,11 @@ #> [CmdletBinding()] param( - [string[]] $Fields = @('login', 'id', 'databaseId') + # The fields to return. + [string[]] $Fields = @('login', 'id', 'databaseId'), + + # Context to run the command in. + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) $query = @" @@ -26,6 +30,6 @@ query { } } "@ - $results = Invoke-GitHubGraphQLQuery -Query $query + $results = Invoke-GitHubGraphQLQuery -Query $query -Context $Context return $results.data.viewer } diff --git a/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 b/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 index 686711d87..081c7aacf 100644 --- a/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 +++ b/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 @@ -17,10 +17,14 @@ [string] $Query, # The variables to pass to the query. - [hashtable] $Variables + [hashtable] $Variables, + + # The context to run the command in. + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) $inputObject = @{ + Context = $Context APIEndpoint = '/graphql' Method = 'Post' Body = @{ From 87000e1dc4a42a41010e5f01bebf9db3d5bb18b4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 14:41:30 +0100 Subject: [PATCH 018/134] Set context on get app --- src/functions/public/Apps/Get-GitHubApp.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Apps/Get-GitHubApp.ps1 b/src/functions/public/Apps/Get-GitHubApp.ps1 index 24d97b633..ae61fe13c 100644 --- a/src/functions/public/Apps/Get-GitHubApp.ps1 +++ b/src/functions/public/Apps/Get-GitHubApp.ps1 @@ -22,9 +22,13 @@ #> [OutputType([pscustomobject])] [CmdletBinding()] - param() + param( + # The context to run the command in. + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) $inputObject = @{ + Context = $Context APIEndpoint = '/app' Method = 'GET' } From f8f0b84736370e5408ce0da4a77da75617b3e028 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 14:59:39 +0100 Subject: [PATCH 019/134] Fix --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 2a6424820..83f1aa8cb 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -118,6 +118,7 @@ function Set-GitHubContext { # Run functions to get info on the temporary context. try { + Write-Verbose "Getting info on the context." switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName @@ -137,6 +138,7 @@ function Set-GitHubContext { throw 'Failed to get info on the context. Unknown logon type.' } } + Write-Verbose $($context['Username']) } catch { Write-Error $_ throw 'Failed to get info on the context.' From 0d548cdc46bc73c6f1f7c2c36f77ba380cdb4c46 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 15:09:54 +0100 Subject: [PATCH 020/134] Fix --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index e37993611..7f48eeaee 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -96,7 +96,7 @@ $ApiBaseUri = $ApiBaseUri ?? ($context['ApiBaseUri'] | ConvertFrom-SecureString -AsPlainText) $Version = $Version ?? ($context['ApiVersion'] | ConvertFrom-SecureString -AsPlainText) - $TokenType = (Get-GitHubConfig -Name 'TokenType' -Context $Context) + $TokenType = $context['TokenType'] | ConvertFrom-SecureString -AsPlainText $Token = $Token ?? $context['Token'] switch ($tokenType) { From 2c6f7d90b94eb4b8b6b23eb9ad5add4c6fcbfadf Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 15:22:04 +0100 Subject: [PATCH 021/134] test --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 7f48eeaee..86498fe54 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -89,6 +89,11 @@ [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) + Write-Verbose 'Invoking GitHub API...' + $PSBoundParameters.GetEnumerator() | ForEach-Object { + Write-Verbose " - $($_.Key): $($_.Value)" + } + $context = Get-GitHubContext -Name $Context if (-not $context) { throw 'Log in using Connect-GitHub before running this command.' From b6a6ffb9be239f5a1059c46ebdf82fa3370e1353 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 15:32:11 +0100 Subject: [PATCH 022/134] test --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 86498fe54..ff3ed956b 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -100,8 +100,11 @@ } $ApiBaseUri = $ApiBaseUri ?? ($context['ApiBaseUri'] | ConvertFrom-SecureString -AsPlainText) + Write-Verbose "ApiBaseUri: $ApiBaseUri" $Version = $Version ?? ($context['ApiVersion'] | ConvertFrom-SecureString -AsPlainText) + Write-Verbose "Version: $Version" $TokenType = $context['TokenType'] | ConvertFrom-SecureString -AsPlainText + Write-Verbose "TokenType: $TokenType" $Token = $Token ?? $context['Token'] switch ($tokenType) { From a7e340b621fcdc03b770147d8eac387b4cc4c952 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 15:43:46 +0100 Subject: [PATCH 023/134] Fix --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index ff3ed956b..a5a5901cb 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -94,18 +94,38 @@ Write-Verbose " - $($_.Key): $($_.Value)" } - $context = Get-GitHubContext -Name $Context - if (-not $context) { + $contextObj = Get-GitHubContext -Name $Context + if (-not $contextObj) { throw 'Log in using Connect-GitHub before running this command.' } - $ApiBaseUri = $ApiBaseUri ?? ($context['ApiBaseUri'] | ConvertFrom-SecureString -AsPlainText) + $ApiBaseUri = if ([string]::IsNullOrEmpty($ApiBaseUri)) { + $contextObj['ApiBaseUri'] | ConvertFrom-SecureString -AsPlainText + } else { + $ApiBaseUri + } Write-Verbose "ApiBaseUri: $ApiBaseUri" - $Version = $Version ?? ($context['ApiVersion'] | ConvertFrom-SecureString -AsPlainText) + + $Version = if ([string]::IsNullOrEmpty($Version)) { + $contextObj['Version'] | ConvertFrom-SecureString -AsPlainText + } else { + $Version + } Write-Verbose "Version: $Version" - $TokenType = $context['TokenType'] | ConvertFrom-SecureString -AsPlainText + + $TokenType = if ([string]::IsNullOrEmpty($TokenType)) { + $contextObj['TokenType'] | ConvertFrom-SecureString -AsPlainText + } else { + $TokenType + } Write-Verbose "TokenType: $TokenType" - $Token = $Token ?? $context['Token'] + + $Token = if ([string]::IsNullOrEmpty($Token)) { + $contextObj['Token'] + } else { + $Token + } + Write-Verbose "Token: $Token" switch ($tokenType) { 'ghu' { From fdd6f6aa69de33545c32871467b9f74f92ea1003 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 15:57:33 +0100 Subject: [PATCH 024/134] test --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index a5a5901cb..74162b9e8 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -99,31 +99,31 @@ throw 'Log in using Connect-GitHub before running this command.' } - $ApiBaseUri = if ([string]::IsNullOrEmpty($ApiBaseUri)) { - $contextObj['ApiBaseUri'] | ConvertFrom-SecureString -AsPlainText - } else { - $ApiBaseUri + if ([string]::IsNullOrEmpty($ApiBaseUri)) { + Write-Verbose 'Using default API base URI from context.' + Write-Verbose $($contextObj['ApiBaseUri']) + $ApiBaseUri = ConvertFrom-SecureString -SecureString $contextObj['ApiBaseUri'] -AsPlainText } Write-Verbose "ApiBaseUri: $ApiBaseUri" - $Version = if ([string]::IsNullOrEmpty($Version)) { - $contextObj['Version'] | ConvertFrom-SecureString -AsPlainText - } else { - $Version + if ([string]::IsNullOrEmpty($Version)) { + Write-Verbose 'Using default API version from context.' + Write-Verbose $($contextObj['Version']) + $Version = ConvertFrom-SecureString -SecureString $contextObj['Version'] -AsPlainText } Write-Verbose "Version: $Version" - $TokenType = if ([string]::IsNullOrEmpty($TokenType)) { - $contextObj['TokenType'] | ConvertFrom-SecureString -AsPlainText - } else { - $TokenType + if ([string]::IsNullOrEmpty($TokenType)) { + Write-Verbose 'Using default token type from context.' + Write-Verbose $($contextObj['TokenType']) + $TokenType = ConvertFrom-SecureString -SecureString $contextObj['TokenType'] -AsPlainText } Write-Verbose "TokenType: $TokenType" - $Token = if ([string]::IsNullOrEmpty($Token)) { - $contextObj['Token'] - } else { - $Token + if ([string]::IsNullOrEmpty($Token)) { + Write-Verbose 'Using default token from context.' + Write-Verbose $($contextObj['Token']) + $Token = $contextObj['Token'] } Write-Verbose "Token: $Token" From 6c5a5e7cd88d2b96c88c97ada70d542ed469b834 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 16:02:27 +0100 Subject: [PATCH 025/134] test --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 74162b9e8..6dbf3b129 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -95,6 +95,7 @@ } $contextObj = Get-GitHubContext -Name $Context + Write-Verbose ($contextObj | Out-String) if (-not $contextObj) { throw 'Log in using Connect-GitHub before running this command.' } From 254a6c2572a0a1b31570bf36b130d42df7b0e126 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 16:13:10 +0100 Subject: [PATCH 026/134] fix context --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index f68b38fa2..8b80cbd47 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -32,11 +32,11 @@ function Get-GitHubContext { ) if ($ListAvailable) { - return Get-Context -Name "$($script:Config.Name)/*" -AsPlainText + return Get-Context -Name "$($script:Config.Name)/*" } if ($Name) { - return Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText + return Get-Context -Name "$($script:Config.Name)/$Name" } $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText From 29bc8701ed05117c6d055c1d0fd53b8807edce0f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 16:25:13 +0100 Subject: [PATCH 027/134] UseAPIVersjon --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 6dbf3b129..d84676332 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -82,7 +82,7 @@ # The GitHub API version to be used. By default, it pulls from a configuration script variable. [Parameter()] - [string] $Version, + [string] $ApiVersion, # The context to use for the API call. This is used to retrieve the necessary configuration settings. [Parameter()] @@ -107,12 +107,12 @@ } Write-Verbose "ApiBaseUri: $ApiBaseUri" - if ([string]::IsNullOrEmpty($Version)) { + if ([string]::IsNullOrEmpty($ApiVersion)) { Write-Verbose 'Using default API version from context.' - Write-Verbose $($contextObj['Version']) - $Version = ConvertFrom-SecureString -SecureString $contextObj['Version'] -AsPlainText + Write-Verbose $($contextObj['ApiVersion']) + $ApiVersion = ConvertFrom-SecureString -SecureString $contextObj['ApiVersion'] -AsPlainText } - Write-Verbose "Version: $Version" + Write-Verbose "ApiVersion: $ApiVersion" if ([string]::IsNullOrEmpty($TokenType)) { Write-Verbose 'Using default token type from context.' @@ -145,7 +145,7 @@ $headers = @{ Accept = $Accept - 'X-GitHub-Api-Version' = $Version + 'X-GitHub-Api-Version' = $ApiVersion } Remove-HashtableEntry -Hashtable $headers -NullOrEmptyValues From 8bd07bc556641b786dc3c1c3d1f71175479c70e8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 16:35:28 +0100 Subject: [PATCH 028/134] Fix Database --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 83f1aa8cb..a9dde1946 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -125,7 +125,7 @@ function Set-GitHubContext { $context['Name'] = "$($Script:Config.Name)/$HostName/$($viewer.login)" $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id - $context['DatabaseID'] = $viewer.databaseId + $context['DatabaseID'] = ($viewer.databaseId).ToString() } 'App' { $app = Get-GitHubApp -Context $tempContextName From 1fd1af6035f62845806e8616c233c255958e9578 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 18:57:22 +0100 Subject: [PATCH 029/134] Check what contexts we have... --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index a9dde1946..4bb090f88 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -146,6 +146,7 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context + Write-Verbose (Get-Context | Out-String) Remove-Context -Name "$($script:Config.Name)/$tempContextName" } Get-Context -Name $context['Name'] -AsPlainText From b2bee58b320cee6b84af97f6afd2449c18790db0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 19:30:20 +0100 Subject: [PATCH 030/134] Use Context 2.0.3 for fixing lists of contexts --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 4 ++-- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 8b80cbd47..f323c1934 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 4bb090f88..79371aa9b 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Set-GitHubContext { <# @@ -118,7 +118,7 @@ function Set-GitHubContext { # Run functions to get info on the temporary context. try { - Write-Verbose "Getting info on the context." + Write-Verbose 'Getting info on the context.' switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index ade45e57a..f7be47506 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 333274e8f..d536072d3 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index bdc062398..2a73dda6e 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 377a0c226..dc05fb70d 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 4fa37e8a1..3944e5824 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } function Set-GitHubConfig { <# From a9d48fa4ba45f68b36b3c88a51e5e9a10cfb789e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 19:47:26 +0100 Subject: [PATCH 031/134] Improve verbosity output in Set-GitHubContext by using Get-Context with -AsPlainText --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 79371aa9b..1f90a7690 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -146,7 +146,7 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context - Write-Verbose (Get-Context | Out-String) + Write-Verbose (Get-Context -AsPlainText | Out-String) Remove-Context -Name "$($script:Config.Name)/$tempContextName" } Get-Context -Name $context['Name'] -AsPlainText From 8022f4a2c543628f94988005de537ae45d4b634d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 23:23:53 +0100 Subject: [PATCH 032/134] Update Context module requirement to version 2.0.4 in multiple scripts --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index f323c1934..abf702d4a 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 1f90a7690..12e161881 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index f7be47506..dbe8bdb55 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index d536072d3..035553e9d 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 2a73dda6e..d7af625dc 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index dc05fb70d..2e7e45990 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 3944e5824..710bbf109 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } function Set-GitHubConfig { <# From d914b00d327cd41b6a3dd4bc4c95af3fdbdd4ee2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 23:47:32 +0100 Subject: [PATCH 033/134] test what remove does --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 12e161881..89468808a 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -148,6 +148,7 @@ function Set-GitHubContext { Set-Context $context Write-Verbose (Get-Context -AsPlainText | Out-String) Remove-Context -Name "$($script:Config.Name)/$tempContextName" + Write-Verbose (Get-Context -AsPlainText | Out-String) } Get-Context -Name $context['Name'] -AsPlainText } From 88ffa918dc95bef0e58656872ac21c44074e0c61 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 16 Nov 2024 23:48:53 +0100 Subject: [PATCH 034/134] Refactor Set-GitHubContext to use variable for context name in Remove-Context --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 89468808a..f32245495 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -147,7 +147,7 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context Write-Verbose (Get-Context -AsPlainText | Out-String) - Remove-Context -Name "$($script:Config.Name)/$tempContextName" + Remove-Context -Name $Name Write-Verbose (Get-Context -AsPlainText | Out-String) } Get-Context -Name $context['Name'] -AsPlainText From 920ac6541843cbb3d66686e7ee9b005222f375d1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 00:15:18 +0100 Subject: [PATCH 035/134] test --- .../public/Auth/Context/Set-GitHubContext.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index f32245495..2b3331949 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -122,14 +122,16 @@ function Set-GitHubContext { switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName - $context['Name'] = "$($Script:Config.Name)/$HostName/$($viewer.login)" + $newName = "$($Script:Config.Name)/$HostName/$($viewer.login)" + $context['Name'] = $newName $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id $context['DatabaseID'] = ($viewer.databaseId).ToString() } 'App' { $app = Get-GitHubApp -Context $tempContextName - $context['Name'] = "$($Script:Config.Name)/$HostName/$($app.slug)" + $newName = "$($Script:Config.Name)/$HostName/$($app.slug)" + $context['Name'] = $newName $context['Username'] = $app.slug $context['NodeID'] = $app.node_id $context['DatabaseID'] = $app.id @@ -146,9 +148,7 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context - Write-Verbose (Get-Context -AsPlainText | Out-String) Remove-Context -Name $Name - Write-Verbose (Get-Context -AsPlainText | Out-String) } - Get-Context -Name $context['Name'] -AsPlainText + Get-Context -Name $newName -AsPlainText } From f1c0cac68530492dd6c06d80cf0bbba6fa753bad Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 00:42:01 +0100 Subject: [PATCH 036/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 2b3331949..f42be53f5 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -150,5 +150,6 @@ function Set-GitHubContext { Set-Context $context Remove-Context -Name $Name } + Write-Verbose (Get-SecretInfo | Out-String) Get-Context -Name $newName -AsPlainText } From f5c8b28b01c95dd7f36d74ff4f01750fd8ded739 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 00:50:17 +0100 Subject: [PATCH 037/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index f42be53f5..628d2ad05 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -150,6 +150,6 @@ function Set-GitHubContext { Set-Context $context Remove-Context -Name $Name } - Write-Verbose (Get-SecretInfo | Out-String) + Write-Verbose ($(Get-Context -AsPlainText).Name) Get-Context -Name $newName -AsPlainText } From 696c9676869f8c4cd5c450bf624fd6d9125a8fbd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 00:58:37 +0100 Subject: [PATCH 038/134] Fix --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 628d2ad05..2a455cba6 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -150,6 +150,8 @@ function Set-GitHubContext { Set-Context $context Remove-Context -Name $Name } - Write-Verbose ($(Get-Context -AsPlainText).Name) + Get-Context -AsPlainText | ForEach-Object { + Write-Verbose $_.Name + } Get-Context -Name $newName -AsPlainText } From faa876b73a6d481d360dee7cd38963e5b980d8b5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 01:47:40 +0100 Subject: [PATCH 039/134] test --- .../public/Auth/Context/Get-GitHubContext.ps1 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index abf702d4a..cd4b2fd39 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -31,14 +31,17 @@ function Get-GitHubContext { [switch] $ListAvailable ) - if ($ListAvailable) { - return Get-Context -Name "$($script:Config.Name)/*" + $contexts = if ($ListAvailable) { + Get-Context -Name "$($script:Config.Name)/*" + } elseif ($Name) { + Get-Context -Name "$($script:Config.Name)/$Name" + } else { + $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText + Get-Context -Name "$($script:Config.Name)/$defaultContext" } - if ($Name) { - return Get-Context -Name "$($script:Config.Name)/$Name" + $contexts | ForEach-Object { + $_['Name'] = $_['Name'] -replace "$($script:Config.Name)/" + $_ } - - $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText - Get-Context -Name "$($script:Config.Name)/$defaultContext" } From 8751bb7f6e88be57e14b231ff0f7fd3b4d8caaca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 11:35:51 +0100 Subject: [PATCH 040/134] Fix? --- .../public/Auth/Context/Set-GitHubContext.ps1 | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 2a455cba6..43a414fd7 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -86,7 +86,7 @@ function Set-GitHubContext { ) $tempContextName = 'tempContext' - $Name = "$($script:Config.Name)/$tempContextName" + $tempContextFullName = "$($script:Config.Name)/$tempContextName" # Set a temporary context. $context = @{ @@ -99,7 +99,7 @@ function Set-GitHubContext { HostName = $HostName # github.com / msx.ghe.com / github.local NodeID = $NodeID # User ID / app ID (GraphQL Node ID) DatabaseID = $DatabaseID # Database ID - Name = $Name # HostName/Username or HostName/AppSlug + Name = $tempContextFullName # HostName/Username or HostName/AppSlug UserName = $UserName # User name Owner = $Owner # Owner name Repo = $Repo # Repo name @@ -122,16 +122,18 @@ function Set-GitHubContext { switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName - $newName = "$($Script:Config.Name)/$HostName/$($viewer.login)" - $context['Name'] = $newName + $newName = "$HostName/$($viewer.login)" + $newFullName = "$($Script:Config.Name)/$newName" + $context['Name'] = $newFullName $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id $context['DatabaseID'] = ($viewer.databaseId).ToString() } 'App' { $app = Get-GitHubApp -Context $tempContextName - $newName = "$($Script:Config.Name)/$HostName/$($app.slug)" - $context['Name'] = $newName + $newName = "$HostName/$($app.slug)" + $newFullName = "$($Script:Config.Name)/$newName" + $context['Name'] = $newFullName $context['Username'] = $app.slug $context['NodeID'] = $app.node_id $context['DatabaseID'] = $app.id @@ -140,7 +142,7 @@ function Set-GitHubContext { throw 'Failed to get info on the context. Unknown logon type.' } } - Write-Verbose $($context['Username']) + Write-Verbose "Found user with username: [$($context['Username'])]" } catch { Write-Error $_ throw 'Failed to get info on the context.' @@ -148,10 +150,8 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context - Remove-Context -Name $Name + Remove-Context -Name $tempContextFullName } - Get-Context -AsPlainText | ForEach-Object { - Write-Verbose $_.Name - } - Get-Context -Name $newName -AsPlainText + + Get-GithubContext -Name $newName -AsPlainText } From ee22ded9de7d5a4c5f94b17ce6e7ffc80e8f03d7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 11:44:43 +0100 Subject: [PATCH 041/134] fix output --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 6 +++--- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index cd4b2fd39..afde6516e 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -32,12 +32,12 @@ function Get-GitHubContext { ) $contexts = if ($ListAvailable) { - Get-Context -Name "$($script:Config.Name)/*" + Get-Context -Name "$($script:Config.Name)/*" -AsPlainText } elseif ($Name) { - Get-Context -Name "$($script:Config.Name)/$Name" + Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText } else { $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText - Get-Context -Name "$($script:Config.Name)/$defaultContext" + Get-Context -Name "$($script:Config.Name)/$defaultContext" -AsPlainText } $contexts | ForEach-Object { diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 43a414fd7..3e680f400 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -153,5 +153,5 @@ function Set-GitHubContext { Remove-Context -Name $tempContextFullName } - Get-GithubContext -Name $newName -AsPlainText + Get-GithubContext -Name $newName } From c06c66f5c3040976c5a3805d524e59a989189743 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 12:10:14 +0100 Subject: [PATCH 042/134] Test with only tokens as secstring --- src/classes/public/GitHubContext.ps1 | 18 ++++++++++++++++++ src/functions/public/API/Invoke-GitHubAPI.ps1 | 6 +++--- .../public/Auth/Context/Get-GitHubContext.ps1 | 11 ++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/classes/public/GitHubContext.ps1 diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 new file mode 100644 index 000000000..c5bbcfcf4 --- /dev/null +++ b/src/classes/public/GitHubContext.ps1 @@ -0,0 +1,18 @@ +class GitHubContext { + [string]$Name + [string]$AuthType + [string]$SecretType + [string]$ApiBaseUri = 'https://api.github.com' + [string]$ApiVersion = '2022-11-28' + [string]$HostName = 'github.com' + [int]$ID + + GitHubContext([string]$name, [string]$authType, [string]$secretType, [System.Security.SecureString]$secret, [string]$hostName, [int]$id) { + $this.Name = $name + $this.AuthType = $authType + $this.SecretType = $secretType + $this.Secret = $secret + $this.HostName = $hostName + $this.ID = $id + } +} diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index d84676332..9e81da705 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -103,21 +103,21 @@ if ([string]::IsNullOrEmpty($ApiBaseUri)) { Write-Verbose 'Using default API base URI from context.' Write-Verbose $($contextObj['ApiBaseUri']) - $ApiBaseUri = ConvertFrom-SecureString -SecureString $contextObj['ApiBaseUri'] -AsPlainText + $ApiBaseUri = $contextObj['ApiBaseUri'] } Write-Verbose "ApiBaseUri: $ApiBaseUri" if ([string]::IsNullOrEmpty($ApiVersion)) { Write-Verbose 'Using default API version from context.' Write-Verbose $($contextObj['ApiVersion']) - $ApiVersion = ConvertFrom-SecureString -SecureString $contextObj['ApiVersion'] -AsPlainText + $ApiVersion = $contextObj['ApiVersion'] } Write-Verbose "ApiVersion: $ApiVersion" if ([string]::IsNullOrEmpty($TokenType)) { Write-Verbose 'Using default token type from context.' Write-Verbose $($contextObj['TokenType']) - $TokenType = ConvertFrom-SecureString -SecureString $contextObj['TokenType'] -AsPlainText + $TokenType = $contextObj['TokenType'] } Write-Verbose "TokenType: $TokenType" diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index afde6516e..d907081f0 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -13,6 +13,10 @@ function Get-GitHubContext { Gets the current GitHub context. #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Encapsulated in a function. Never leaves as a plain text.' + )] [OutputType([object])] [CmdletBinding()] param ( @@ -42,6 +46,11 @@ function Get-GitHubContext { $contexts | ForEach-Object { $_['Name'] = $_['Name'] -replace "$($script:Config.Name)/" - $_ + $_.Token = ConvertTo-SecureString -String $_.Token -AsPlainText + $_.RefreshToken = ConvertTo-SecureString -String $_.Token -AsPlainText + Write-Output $_ } + + Remove-Variable contexts -ErrorAction SilentlyContinue + [System.GC]::Collect() } From 9a44bb022fe7554a038fe4bf30f873aed9d5e59e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 12:25:11 +0100 Subject: [PATCH 043/134] Test --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 3 +-- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 4d43c3e1c..519622a6e 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -293,8 +293,7 @@ } } } - $context = Set-GitHubContext @context - Set-GitHubConfig -Name 'DefaultContext' -Value $context['Name'] + $context = Set-GitHubContext @context -Default Get-GitHubConfig if (-not $Silent) { $name = $context.Username diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 3e680f400..5f32afa4d 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -82,7 +82,11 @@ function Set-GitHubContext { # Set the scope. [Parameter()] - [string] $Scope + [string] $Scope, + + # Set as the default context. + [Parameter()] + [switch] $Default ) $tempContextName = 'tempContext' @@ -150,8 +154,7 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context + Set-GitHubConfig -Name 'DefaultContext' -Value $context['Name'] Remove-Context -Name $tempContextFullName } - - Get-GithubContext -Name $newName } From 0845d316814159036eeaf50e7c74cd415cf8384d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 12:43:57 +0100 Subject: [PATCH 044/134] testing use of default context --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 2 +- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 4 ++-- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 1 + src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 9e81da705..238643fb5 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -95,7 +95,7 @@ } $contextObj = Get-GitHubContext -Name $Context - Write-Verbose ($contextObj | Out-String) + Write-Verbose "Using GitHub context: $Context" if (-not $contextObj) { throw 'Log in using Connect-GitHub before running this command.' } diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 519622a6e..9ea988bf2 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -293,8 +293,8 @@ } } } - $context = Set-GitHubContext @context -Default - Get-GitHubConfig + Set-GitHubContext @context -Default + $context = Get-GitHubContext if (-not $Silent) { $name = $context.Username Write-Host '✓ ' -ForegroundColor Green -NoNewline diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index d907081f0..209afb049 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -41,6 +41,7 @@ function Get-GitHubContext { Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText } else { $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText + Write-Verbose "Using the default context: $defaultContext" Get-Context -Name "$($script:Config.Name)/$defaultContext" -AsPlainText } diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 5f32afa4d..58cf193a2 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -154,7 +154,9 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Set-Context $context - Set-GitHubConfig -Name 'DefaultContext' -Value $context['Name'] Remove-Context -Name $tempContextFullName + if ($Default) { + Set-GitHubConfig -Name 'DefaultContext' -Value $context['Name'] + } } } From 56651b7705c82a966fcfb443cf3fd240c780b863 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 12:56:47 +0100 Subject: [PATCH 045/134] Test with defining another parameter set --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 209afb049..3ae9bf08b 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -18,7 +18,7 @@ function Get-GitHubContext { Justification = 'Encapsulated in a function. Never leaves as a plain text.' )] [OutputType([object])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param ( # The name of the context. [Parameter( From 6db46740029a2d593fb7b03ab30112d7405bccdf Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 12:57:33 +0100 Subject: [PATCH 046/134] named paramsets --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 3ae9bf08b..7fd68b948 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -18,19 +18,19 @@ function Get-GitHubContext { Justification = 'Encapsulated in a function. Never leaves as a plain text.' )] [OutputType([object])] - [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] + [CmdletBinding(DefaultParameterSetName = 'CurrentContext')] param ( # The name of the context. [Parameter( Mandatory, - ParameterSetName = 'Name' + ParameterSetName = 'NamedContext' )] [string] $Name, # List all available contexts. [Parameter( Mandatory, - ParameterSetName = 'ListAvailable' + ParameterSetName = 'ListAvailableContexts' )] [switch] $ListAvailable ) From e283b08ab8b790072edc9ce721d233b3a9590c47 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 13:06:08 +0100 Subject: [PATCH 047/134] test --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 7fd68b948..b16e14d4f 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -42,7 +42,7 @@ function Get-GitHubContext { } else { $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText Write-Verbose "Using the default context: $defaultContext" - Get-Context -Name "$($script:Config.Name)/$defaultContext" -AsPlainText + Get-Context -Name $defaultContext -AsPlainText } $contexts | ForEach-Object { From fbc8e8cf8274976b899e39eadf77879981c74d7b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 13:16:27 +0100 Subject: [PATCH 048/134] debug --- src/classes/public/GitHubContext.ps1 | 18 ------------------ .../public/Auth/Context/Get-GitHubContext.ps1 | 3 +++ 2 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 src/classes/public/GitHubContext.ps1 diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 deleted file mode 100644 index c5bbcfcf4..000000000 --- a/src/classes/public/GitHubContext.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -class GitHubContext { - [string]$Name - [string]$AuthType - [string]$SecretType - [string]$ApiBaseUri = 'https://api.github.com' - [string]$ApiVersion = '2022-11-28' - [string]$HostName = 'github.com' - [int]$ID - - GitHubContext([string]$name, [string]$authType, [string]$secretType, [System.Security.SecureString]$secret, [string]$hostName, [int]$id) { - $this.Name = $name - $this.AuthType = $authType - $this.SecretType = $secretType - $this.Secret = $secret - $this.HostName = $hostName - $this.ID = $id - } -} diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index b16e14d4f..6fd6ddb59 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -42,6 +42,9 @@ function Get-GitHubContext { } else { $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText Write-Verbose "Using the default context: $defaultContext" + Get-Context | ForEach-Object { + Write-Verbose ($_['Name']) + } Get-Context -Name $defaultContext -AsPlainText } From 2765cff91fbb58bb388ee579873b7bec289ec38d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 13:44:03 +0100 Subject: [PATCH 049/134] refactor: update default context retrieval to use GitHub configuration functions --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 4 ++-- src/functions/public/Auth/Disconnect-GitHubAccount.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 6fd6ddb59..c32136c16 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -40,9 +40,9 @@ function Get-GitHubContext { } elseif ($Name) { Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText } else { - $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText + $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" - Get-Context | ForEach-Object { + Get-Context -AsPlainText | ForEach-Object { Write-Verbose ($_['Name']) } Get-Context -Name $defaultContext -AsPlainText diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 8fc3fc749..546033bdf 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -27,9 +27,9 @@ [CmdletBinding()] param () - $defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name + $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Remove-Context -Name "$($script:Config.Name)/$defaultContext" - Set-ContextSetting -Name 'DefaultContext' -Value '' -Context $script:Config.Name + Remove-GitHubConfig -Name 'DefaultContext' Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged out of GitHub! [$defaultContext]" From 6304609882e3c7d294865feb7f79194beb0b17ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 15:44:21 +0100 Subject: [PATCH 050/134] chore: update required module version to 2.0.5 across GitHub context functions --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index c32136c16..98ae91167 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 58cf193a2..e1fedca3c 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index dbe8bdb55..8d1d2b8a0 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 035553e9d..6195e75fe 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index d7af625dc..6e73bbea5 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 2e7e45990..1662ea18c 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 710bbf109..2b845e230 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } function Set-GitHubConfig { <# From 1f4be3f0413ff5df1791ac090aa3b43704499d3e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 19:30:40 +0100 Subject: [PATCH 051/134] chore: update required module version to 2.0.6 across GitHub context functions --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 98ae91167..26f9c6fa2 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index e1fedca3c..37075cb66 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 8d1d2b8a0..f8920e689 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 6195e75fe..37840b292 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 6e73bbea5..6e6d9bea0 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 1662ea18c..9051e8e0b 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 2b845e230..9877bcb86 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.5' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } function Set-GitHubConfig { <# From 55f68418b6ea21777eb52b711503d0006de3ce2f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 19:56:08 +0100 Subject: [PATCH 052/134] Fix --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 26f9c6fa2..8ab00cb59 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -48,7 +48,9 @@ function Get-GitHubContext { Get-Context -Name $defaultContext -AsPlainText } + Write-Verbose "Found $($contexts.Count) contexts." $contexts | ForEach-Object { + Write-Verbose "Processing context: $($_['Name'])" $_['Name'] = $_['Name'] -replace "$($script:Config.Name)/" $_.Token = ConvertTo-SecureString -String $_.Token -AsPlainText $_.RefreshToken = ConvertTo-SecureString -String $_.Token -AsPlainText From ecd4fa905968ccf0cf13a525282ff396c0da9128 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 20:13:24 +0100 Subject: [PATCH 053/134] Fix default context --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 8ab00cb59..0d0ffe7dd 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -36,16 +36,19 @@ function Get-GitHubContext { ) $contexts = if ($ListAvailable) { + Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" Get-Context -Name "$($script:Config.Name)/*" -AsPlainText } elseif ($Name) { + Write-Verbose "Listing available contexts. [$($script:Config.Name)/$Name]" Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - Write-Verbose "Using the default context: $defaultContext" + $defaultContextFullName = "$($script:Config.Name)/$defaultContext" + Write-Verbose "Using the default context: [$defaultContextFullName]" Get-Context -AsPlainText | ForEach-Object { Write-Verbose ($_['Name']) } - Get-Context -Name $defaultContext -AsPlainText + Get-Context -Name $defaultContextFullName -AsPlainText } Write-Verbose "Found $($contexts.Count) contexts." From d2fade8312af4313fc25f568f1819a983f0c2b60 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 20:22:50 +0100 Subject: [PATCH 054/134] refactor: simplify default context retrieval in Get-GitHubContext function --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 0d0ffe7dd..d9eeff514 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -39,16 +39,15 @@ function Get-GitHubContext { Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" Get-Context -Name "$($script:Config.Name)/*" -AsPlainText } elseif ($Name) { - Write-Verbose "Listing available contexts. [$($script:Config.Name)/$Name]" + Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - $defaultContextFullName = "$($script:Config.Name)/$defaultContext" - Write-Verbose "Using the default context: [$defaultContextFullName]" + Write-Verbose "Using the default context: $defaultContext" Get-Context -AsPlainText | ForEach-Object { Write-Verbose ($_['Name']) } - Get-Context -Name $defaultContextFullName -AsPlainText + Get-Context -Name $defaultContext -AsPlainText } Write-Verbose "Found $($contexts.Count) contexts." From 27c2587e68457bc74597cf81483643ed5c9b3a50 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 21:36:50 +0100 Subject: [PATCH 055/134] test --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index d9eeff514..ac691b2ba 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -47,7 +47,7 @@ function Get-GitHubContext { Get-Context -AsPlainText | ForEach-Object { Write-Verbose ($_['Name']) } - Get-Context -Name $defaultContext -AsPlainText + Get-Context -Name "*$defaultContext*" -AsPlainText } Write-Verbose "Found $($contexts.Count) contexts." From 6d350dae3306dd87ba3fec3c250e46f6fd2ec0c7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 21:54:05 +0100 Subject: [PATCH 056/134] test --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index ac691b2ba..72404a4f7 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -47,7 +47,7 @@ function Get-GitHubContext { Get-Context -AsPlainText | ForEach-Object { Write-Verbose ($_['Name']) } - Get-Context -Name "*$defaultContext*" -AsPlainText + Get-Context -AsPlainText | Where-Object { $_['Name'] -eq "$($script:Config.Name)/$defaultContext" } } Write-Verbose "Found $($contexts.Count) contexts." From df41906cc58f81c94084b404c1c68d54fb4d0011 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 22:03:30 +0100 Subject: [PATCH 057/134] fix --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 72404a4f7..0d68595a6 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -46,8 +46,10 @@ function Get-GitHubContext { Write-Verbose "Using the default context: $defaultContext" Get-Context -AsPlainText | ForEach-Object { Write-Verbose ($_['Name']) + if ($_['Name'] -eq "$($script:Config.Name)/$defaultContext") { + $_ + } } - Get-Context -AsPlainText | Where-Object { $_['Name'] -eq "$($script:Config.Name)/$defaultContext" } } Write-Verbose "Found $($contexts.Count) contexts." From 69bb7b41b36aca3fb726484a728d92a83caba7d2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 22:38:46 +0100 Subject: [PATCH 058/134] test --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 0d68595a6..c8cbb0107 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -44,12 +44,7 @@ function Get-GitHubContext { } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" - Get-Context -AsPlainText | ForEach-Object { - Write-Verbose ($_['Name']) - if ($_['Name'] -eq "$($script:Config.Name)/$defaultContext") { - $_ - } - } + Get-Context -AsPlainText -Name ("$($script:Config.Name)/$defaultContext" -replace '([\\\*\?\[\]])', '`$1' ) } Write-Verbose "Found $($contexts.Count) contexts." From 9502195e32127b7442ada7283df5d502b814cab1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 22:52:14 +0100 Subject: [PATCH 059/134] Test --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index c8cbb0107..2f88ff92a 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -44,7 +44,7 @@ function Get-GitHubContext { } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" - Get-Context -AsPlainText -Name ("$($script:Config.Name)/$defaultContext" -replace '([\\\*\?\[\]])', '`$1' ) + Get-Context -AsPlainText -Name ("$($script:Config.Name)/$defaultContext" -replace '([\\\*\?\[\]\.])', '`$1' ) } Write-Verbose "Found $($contexts.Count) contexts." From 3c204bba2f0ac4a21b0ea983b2e766bb7c0deeb0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 17 Nov 2024 23:02:56 +0100 Subject: [PATCH 060/134] refactor: update Get-GitHubContext to filter contexts by name --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 2f88ff92a..f654a924c 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -44,7 +44,7 @@ function Get-GitHubContext { } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" - Get-Context -AsPlainText -Name ("$($script:Config.Name)/$defaultContext" -replace '([\\\*\?\[\]\.])', '`$1' ) + Get-Context -AsPlainText | Where-Object { $_['Name'] -eq "$($script:Config.Name)/$defaultContext" } } Write-Verbose "Found $($contexts.Count) contexts." From d95402d5962731f189e11efd7e10de4a58e2389e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 21 Nov 2024 16:08:36 +0100 Subject: [PATCH 061/134] Fix documentation --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 37075cb66..cc634d0b7 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -126,8 +126,7 @@ function Set-GitHubContext { switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName - $newName = "$HostName/$($viewer.login)" - $newFullName = "$($Script:Config.Name)/$newName" + $newFullName = $viewer.id $context['Name'] = $newFullName $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id @@ -136,7 +135,7 @@ function Set-GitHubContext { 'App' { $app = Get-GitHubApp -Context $tempContextName $newName = "$HostName/$($app.slug)" - $newFullName = "$($Script:Config.Name)/$newName" + $newFullName = $app.node_id $context['Name'] = $newFullName $context['Username'] = $app.slug $context['NodeID'] = $app.node_id From f51f546b7a4b3fbd66d0c4505364e667a931ce9c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 21 Nov 2024 23:57:26 +0100 Subject: [PATCH 062/134] Bump Context to 3.0.1 --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 16 +++---- .../public/Auth/Context/Get-GitHubContext.ps1 | 13 ++---- .../public/Auth/Context/Set-GitHubContext.ps1 | 23 +++++----- .../Get-GitHubContextSetting.ps1 | 16 +++++-- .../Set-GitHubContextSetting.ps1 | 46 ++++++------------- .../public/Config/Get-GitHubConfig.ps1 | 6 +-- .../public/Config/Remove-GitHubConfig.ps1 | 4 +- .../public/Config/Set-GitHubConfig.ps1 | 4 +- src/loader.ps1 | 6 +-- src/variables/private/Config.ps1 | 3 +- 10 files changed, 58 insertions(+), 79 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 238643fb5..7597193f5 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -102,29 +102,29 @@ if ([string]::IsNullOrEmpty($ApiBaseUri)) { Write-Verbose 'Using default API base URI from context.' - Write-Verbose $($contextObj['ApiBaseUri']) - $ApiBaseUri = $contextObj['ApiBaseUri'] + Write-Verbose $($contextObj.ApiBaseUri) + $ApiBaseUri = $contextObj.ApiBaseUri } Write-Verbose "ApiBaseUri: $ApiBaseUri" if ([string]::IsNullOrEmpty($ApiVersion)) { Write-Verbose 'Using default API version from context.' - Write-Verbose $($contextObj['ApiVersion']) - $ApiVersion = $contextObj['ApiVersion'] + Write-Verbose $($contextObj.ApiVersion) + $ApiVersion = $contextObj.ApiVersion } Write-Verbose "ApiVersion: $ApiVersion" if ([string]::IsNullOrEmpty($TokenType)) { Write-Verbose 'Using default token type from context.' - Write-Verbose $($contextObj['TokenType']) - $TokenType = $contextObj['TokenType'] + Write-Verbose $($contextObj.TokenType) + $TokenType = $contextObj.TokenType } Write-Verbose "TokenType: $TokenType" if ([string]::IsNullOrEmpty($Token)) { Write-Verbose 'Using default token from context.' - Write-Verbose $($contextObj['Token']) - $Token = $contextObj['Token'] + Write-Verbose $($contextObj.Token) + $Token = $contextObj.Token } Write-Verbose "Token: $Token" diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index f654a924c..246ecfcf8 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Get-GitHubContext { <# @@ -37,22 +37,19 @@ function Get-GitHubContext { $contexts = if ($ListAvailable) { Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" - Get-Context -Name "$($script:Config.Name)/*" -AsPlainText + Get-Context -ID "$($script:Config.Name)/*" } elseif ($Name) { Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" - Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText + Get-Context -ID "$($script:Config.Name)/$Name" } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" - Get-Context -AsPlainText | Where-Object { $_['Name'] -eq "$($script:Config.Name)/$defaultContext" } + Get-Context | Where-Object { $_.Name -eq "$defaultContext" } } Write-Verbose "Found $($contexts.Count) contexts." $contexts | ForEach-Object { - Write-Verbose "Processing context: $($_['Name'])" - $_['Name'] = $_['Name'] -replace "$($script:Config.Name)/" - $_.Token = ConvertTo-SecureString -String $_.Token -AsPlainText - $_.RefreshToken = ConvertTo-SecureString -String $_.Token -AsPlainText + Write-Verbose "Processing context: $($_.Name)" Write-Output $_ } diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index cc634d0b7..bef472b28 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Set-GitHubContext { <# @@ -90,7 +90,7 @@ function Set-GitHubContext { ) $tempContextName = 'tempContext' - $tempContextFullName = "$($script:Config.Name)/$tempContextName" + $tempContextID = "$($script:Config.Name)/$tempContextName" # Set a temporary context. $context = @{ @@ -103,7 +103,7 @@ function Set-GitHubContext { HostName = $HostName # github.com / msx.ghe.com / github.local NodeID = $NodeID # User ID / app ID (GraphQL Node ID) DatabaseID = $DatabaseID # Database ID - Name = $tempContextFullName # HostName/Username or HostName/AppSlug + ContextID = $tempContextName # HostName/Username or HostName/AppSlug UserName = $UserName # User name Owner = $Owner # Owner name Repo = $Repo # Repo name @@ -118,7 +118,7 @@ function Set-GitHubContext { $context | Remove-HashtableEntry -NullOrEmptyValues - Set-Context $context # Not splatting, but actually passing the hashtable. + Set-Context -ID $tempContextID -Context $context # Run functions to get info on the temporary context. try { @@ -126,17 +126,16 @@ function Set-GitHubContext { switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName - $newFullName = $viewer.id - $context['Name'] = $newFullName + $newContextID = "$HostName/$($viewer.login)" + $context['ContextID'] = $newContextID $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id $context['DatabaseID'] = ($viewer.databaseId).ToString() } 'App' { $app = Get-GitHubApp -Context $tempContextName - $newName = "$HostName/$($app.slug)" - $newFullName = $app.node_id - $context['Name'] = $newFullName + $newContextID = "$HostName/$($app.slug)" + $context['ContextID'] = $newContextID $context['Username'] = $app.slug $context['NodeID'] = $app.node_id $context['DatabaseID'] = $app.id @@ -152,10 +151,10 @@ function Set-GitHubContext { } if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Set-Context $context - Remove-Context -Name $tempContextFullName + Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context + Remove-Context -ID $tempContextID if ($Default) { - Set-GitHubConfig -Name 'DefaultContext' -Value $context['Name'] + Set-GitHubConfig -Name 'DefaultContext' -Value $newContextID } } } diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index f8920e689..891dfbcfc 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Get-GitHubContextSetting { <# @@ -15,15 +15,21 @@ function Get-GitHubContextSetting { #> [OutputType([object])] [CmdletBinding()] - param ( + param( # Choose a configuration name to get. [Parameter()] - [string] $Name + [string] $Name, + + # The name of the context. + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) + $contextID = "$($script:Config.Name)/$Context" + if (-not $Name) { - Get-Context -Name $script:Config.Name -AsPlainText + Get-Context -ID $contextID } - Get-ContextSetting -Name $Name -Context $script:Config.Name -AsPlainText + Get-ContextSetting -Name $Name -ID $contextID } diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 37840b292..90ce91783 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Set-GitHubContextSetting { <# @@ -83,43 +83,23 @@ function Set-GitHubContextSetting { # Set the scope. [Parameter()] - [string] $Scope + [string] $Scope, + + # The context name to set the configuration for. + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) - $storeName = $Script:Config.Name + $contextID = "$($Script:Config.Name)/$Context" if ($PSCmdlet.ShouldProcess('Config', 'Set')) { - if ($RefreshToken) { - Set-Context -Name "$storeName/RefreshToken" -Token $RefreshToken -Variables @{ - RefreshTokenExpirationDate = $RefreshTokenExpirationDate - } - } - - $variables = @{ - ApiBaseUri = $ApiBaseUri - ApiVersion = $ApiVersion - AuthClientID = $AuthClientID - AuthType = $AuthType - ClientID = $ClientID - DeviceFlowType = $DeviceFlowType - HostName = $HostName - NodeID = $NodeID - DatabaseID = $DatabaseID - Owner = $Owner - Repo = $Repo - Scope = $Scope - Token = $Token - TokenExpirationDate = $TokenExpirationDate - TokenType = $TokenType - } - - $variables | Remove-HashtableEntry -NullOrEmptyValues - - foreach ($key in $variables.Keys) { - if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$($variables[$key])]")) { - Write-Verbose "Setting [$key] to [$($variables[$key])]" - Set-ContextSetting -Name $key -Value $variables[$key] -Context $script:Config.Name + $PSBoundParameters.GetEnumerator() | ForEach-Object { + $key = $_.Key + $value = $_.Value + if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$value]")) { + Write-Verbose "Setting [$key] to [$value]" + Set-ContextSetting -Name $key -Value $value -Context $contextID } } } diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 6e6d9bea0..d56edbbf6 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Get-GitHubConfig { <# @@ -22,8 +22,8 @@ function Get-GitHubConfig { ) if (-not $Name) { - return Get-Context -Name $script:Config.Name -AsPlainText + return Get-Context -Name $script:Config.Name } - Get-ContextSetting -Name $Name -Context $script:Config.Name -AsPlainText + Get-ContextSetting -Name $Name -ID $script:Config.Name } diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 9051e8e0b..69c29d3a0 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Remove-GitHubConfig { <# @@ -21,6 +21,6 @@ function Remove-GitHubConfig { ) if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) { - Set-ContextSetting -Name $Name -Value $null -Context $script:Config.Name + Set-ContextSetting -Name $Name -Value $null -ID $script:Config.Name } } diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 9877bcb86..c08da38e2 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '2.0.6' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } function Set-GitHubConfig { <# @@ -25,6 +25,6 @@ function Set-GitHubConfig { ) if ($PSCmdlet.ShouldProcess('ContextSetting', 'Set')) { - Set-ContextSetting -Name $Name -Value $Value -Context $script:Config.Name + Set-ContextSetting -Name $Name -Value $Value -ID $script:Config.Name } } diff --git a/src/loader.ps1 b/src/loader.ps1 index 4c61622bb..bfd06ad6f 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -11,10 +11,8 @@ if ($env:GITHUB_ACTIONS -eq 'true') { ### This is the context for this module # Get current module context -$context = (Get-Context -Name $script:Config.Name -AsPlainText) +$context = (Get-Context -ID $script:Config.Name) if (-not $context) { Write-Verbose 'No context found, creating a new context...' - Set-Context @{ - Name = $script:Config.Name - } + Set-Context -ID $script:Config.Name -Context @{ ContextID = 'GitHub' } } diff --git a/src/variables/private/Config.ps1 b/src/variables/private/Config.ps1 index 8daa18311..8d3d0de05 100644 --- a/src/variables/private/Config.ps1 +++ b/src/variables/private/Config.ps1 @@ -1,4 +1,3 @@ $script:Config = @{ - Name = 'PSModule.GitHub' # $script:Config.Name - DefaultContext = 'null' + Name = 'PSModule.GitHub' # $script:Config.Name } From d909644cde747543f4ae603e9b47aecf7149687c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 00:14:31 +0100 Subject: [PATCH 063/134] test --- .github/workflows/Nightly-Run.yml | 6 ++++ .github/workflows/Process-PSModule.yml | 6 ++++ .../public/Auth/Context/Get-GitHubContext.ps1 | 2 +- tests/GitHub.Tests.ps1 | 32 ++++++++++++++++--- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Nightly-Run.yml b/.github/workflows/Nightly-Run.yml index c25d80630..4469a9064 100644 --- a/.github/workflows/Nightly-Run.yml +++ b/.github/workflows/Nightly-Run.yml @@ -10,6 +10,12 @@ permissions: pull-requests: write statuses: write +env: + TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }} + TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }} + TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }} + TEST_PAT: ${{ secrets.TEST_PAT }} + jobs: Process-PSModule: uses: PSModule/Process-PSModule/.github/workflows/CI.yml@v3 diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index f6ed58e7d..9110efba6 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -24,6 +24,12 @@ permissions: pages: write id-token: write +env: + TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }} + TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }} + TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }} + TEST_PAT: ${{ secrets.TEST_PAT }} + jobs: Process-PSModule: uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v3 diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 246ecfcf8..d093bf1c5 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -44,7 +44,7 @@ function Get-GitHubContext { } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" - Get-Context | Where-Object { $_.Name -eq "$defaultContext" } + Get-Context -ID "$($script:Config.Name)/$defaultContext" } Write-Verbose "Found $($contexts.Count) contexts." diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 21dcfbd94..413981bf5 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -1,8 +1,32 @@ -BeforeAll { - Connect-GitHub -} +Describe 'GitHub' { + Context 'Connect-GitHubAccount' { + It 'Connect-GitHubAccount function exists' { + Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty + } + + It 'Can be called without parameters on GitHub Actions' { + { Connect-GitHubAccount } | Should -Not -Throw + } + + It 'Can be called with a classic PAT token' { + { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw + } + + It 'Can be called with a fine-grained PAT token' { + { Connect-GitHubAccount -Token $env:TEST_FG_PAT } | Should -Not -Throw + } + + It 'Can be called with a GitHub App' { + { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw + } + + # It 'Can be called with a GitHub App Installation Access Token' { + # { Connect-GitHubAccount -Token $env:TEST_APP_INSTALLATION_ACCESS_TOKEN } | Should -Not -Throw + # } + } + + -Describe 'GitHub' { Context 'Invoke-GitHubAPI' { It 'Invoke-GitHubAPI function exists' { Get-Command Invoke-GitHubAPI | Should -Not -BeNullOrEmpty From 520f9d0944567a39cc29e16c3ce000994919590f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 00:23:06 +0100 Subject: [PATCH 064/134] vbump Context to 3.0.2 --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index d093bf1c5..e1fa6a02f 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index bef472b28..14588339f 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 891dfbcfc..6ada93120 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 90ce91783..8369fdb14 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index d56edbbf6..387777389 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 69c29d3a0..b9cd67f9b 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index c08da38e2..9c47cc615 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } function Set-GitHubConfig { <# From a6b5b582861f34b33a0c9ec4309554f26ba9ac7d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 00:26:01 +0100 Subject: [PATCH 065/134] feat: add Get-SecretInfo call to Get-GitHubContext function --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index e1fa6a02f..24ee1f5cb 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -45,6 +45,7 @@ function Get-GitHubContext { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" Get-Context -ID "$($script:Config.Name)/$defaultContext" + Get-SecretInfo } Write-Verbose "Found $($contexts.Count) contexts." From 01147287e06d65ac24d296d6a40b9d16628bbdfa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 00:34:36 +0100 Subject: [PATCH 066/134] test --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 24ee1f5cb..c2698dc3e 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -19,7 +19,7 @@ function Get-GitHubContext { )] [OutputType([object])] [CmdletBinding(DefaultParameterSetName = 'CurrentContext')] - param ( + param( # The name of the context. [Parameter( Mandatory, @@ -45,7 +45,7 @@ function Get-GitHubContext { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" Get-Context -ID "$($script:Config.Name)/$defaultContext" - Get-SecretInfo + Get-SecretInfo | Get-Secret -AsPlainText } Write-Verbose "Found $($contexts.Count) contexts." From a7cf3804f8fb93c7fe683fc3315fd5f7b517ba5e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 01:30:19 +0100 Subject: [PATCH 067/134] chore: update Context module requirement to version 3.0.3 across multiple scripts --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 5 +---- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 7 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index c2698dc3e..ab7881e7f 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Get-GitHubContext { <# @@ -53,7 +53,4 @@ function Get-GitHubContext { Write-Verbose "Processing context: $($_.Name)" Write-Output $_ } - - Remove-Variable contexts -ErrorAction SilentlyContinue - [System.GC]::Collect() } diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 14588339f..caf1011a8 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 6ada93120..54997569c 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 8369fdb14..48c7506f7 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 387777389..0335a114c 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index b9cd67f9b..3d2e041a0 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 9c47cc615..68d37359a 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.2' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } function Set-GitHubConfig { <# From 4fd9b18dbefc907fc016d80d4e5e7e5566e949ab Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 14:09:43 +0100 Subject: [PATCH 068/134] Test again --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 9ea988bf2..261c4ef0c 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -143,7 +143,7 @@ $tokenPrefixPattern = '(?<=^(ghu|gho|ghs|github_pat|ghp)).*' # If running on GitHub Actions and no access token is provided, use the GitHub token. - if ($env:GITHUB_ACTIONS -eq 'true') { + if (($env:GITHUB_ACTIONS -eq 'true') -and $PSCmdlet.ParameterSetName -ne 'App') { $tokenNotProvided = [string]::IsNullOrEmpty($Token) $gitHubToken = $env:GH_TOKEN ?? $env:GITHUB_TOKEN $gitHubTokenPresent = -not [string]::IsNullOrEmpty($gitHubToken) From 0af0c5282a8dd36ad2a2a2adb1d14f12cdf7d387 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 14:30:55 +0100 Subject: [PATCH 069/134] Check contexts --- tests/GitHub.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 413981bf5..7357e0849 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -6,18 +6,22 @@ It 'Can be called without parameters on GitHub Actions' { { Connect-GitHubAccount } | Should -Not -Throw + Get-GitHubContext } It 'Can be called with a classic PAT token' { { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw + Get-GitHubContext } It 'Can be called with a fine-grained PAT token' { { Connect-GitHubAccount -Token $env:TEST_FG_PAT } | Should -Not -Throw + Get-GitHubContext } It 'Can be called with a GitHub App' { { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw + Get-GitHubContext } # It 'Can be called with a GitHub App Installation Access Token' { From 60b48401a00e0c7a187a9dad21f723b702657423 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 14:42:58 +0100 Subject: [PATCH 070/134] test: enhance GitHub context tests with verbose output --- tests/GitHub.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 7357e0849..87eae5ea9 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -6,22 +6,22 @@ It 'Can be called without parameters on GitHub Actions' { { Connect-GitHubAccount } | Should -Not -Throw - Get-GitHubContext + Write-Verbose (Get-GitHubContext | Out-String) -Verbose } It 'Can be called with a classic PAT token' { { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw - Get-GitHubContext + Write-Verbose (Get-GitHubContext | Out-String) -Verbose } It 'Can be called with a fine-grained PAT token' { { Connect-GitHubAccount -Token $env:TEST_FG_PAT } | Should -Not -Throw - Get-GitHubContext + Write-Verbose (Get-GitHubContext | Out-String) -Verbose } It 'Can be called with a GitHub App' { { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw - Get-GitHubContext + Write-Verbose (Get-GitHubContext | Out-String) -Verbose } # It 'Can be called with a GitHub App Installation Access Token' { From 59775db9a6625ce509f1b0510b5faf0ba7720e1c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 15:04:48 +0100 Subject: [PATCH 071/134] Get-GitHubContext now only returns the context with correct ID. --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index ab7881e7f..24341cf06 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -45,7 +45,6 @@ function Get-GitHubContext { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' Write-Verbose "Using the default context: $defaultContext" Get-Context -ID "$($script:Config.Name)/$defaultContext" - Get-SecretInfo | Get-Secret -AsPlainText } Write-Verbose "Found $($contexts.Count) contexts." From cf7d305753d5c5861849e3db2aaa7cf4f538e7d3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 15:10:37 +0100 Subject: [PATCH 072/134] test --- .../public/Auth/Context/Get-GitHubContext.ps1 | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 24341cf06..b56681c0d 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -35,21 +35,17 @@ function Get-GitHubContext { [switch] $ListAvailable ) - $contexts = if ($ListAvailable) { - Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" - Get-Context -ID "$($script:Config.Name)/*" + if ($ListAvailable) { + $ID = "$($script:Config.Name)/*" + Write-Verbose "Getting available contexts for [$ID]" } elseif ($Name) { - Write-Verbose "Listing available contexts. [$($script:Config.Name)/*]" - Get-Context -ID "$($script:Config.Name)/$Name" + $ID = "$($script:Config.Name)/$Name" + Write-Verbose "Getting available contexts for [$ID]" } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - Write-Verbose "Using the default context: $defaultContext" - Get-Context -ID "$($script:Config.Name)/$defaultContext" + $ID = "$($script:Config.Name)/$defaultContext" + Write-Verbose "Getting the default context: [$ID]" } - Write-Verbose "Found $($contexts.Count) contexts." - $contexts | ForEach-Object { - Write-Verbose "Processing context: $($_.Name)" - Write-Output $_ - } + Get-Context -ID $ID } From 1a5cddeff7ca2ea01514b78853d99a28a43a7a36 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 15:21:27 +0100 Subject: [PATCH 073/134] test --- tests/GitHub.Tests.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 87eae5ea9..9bd7f24a6 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -24,6 +24,11 @@ Write-Verbose (Get-GitHubContext | Out-String) -Verbose } + It 'Can list all contexts' { + Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose + (Get-GitHubContext -ListAvailable).Count | Should -Be 4 + } + # It 'Can be called with a GitHub App Installation Access Token' { # { Connect-GitHubAccount -Token $env:TEST_APP_INSTALLATION_ACCESS_TOKEN } | Should -Not -Throw # } From b11eb58c4c77c00b34a35fe6bf1596b5ab23d8e7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 16:01:48 +0100 Subject: [PATCH 074/134] Add GitHubContext class to manage GitHub API authentication details --- src/classes/public/GitHubContext.ps1 | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/classes/public/GitHubContext.ps1 diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 new file mode 100644 index 000000000..47aa597ab --- /dev/null +++ b/src/classes/public/GitHubContext.ps1 @@ -0,0 +1,83 @@ +class GitHubContext { + # The API base URI. + # https://api.github.com + [string] $ApiBaseUri + + # The GitHub API version. + # 2022-11-28 + [string] $ApiVersion + + # The authentication client ID. + # Client ID for UAT + [string] $AuthClientID + + # The authentication type. + # UAT / PAT / App / IAT + [string] $AuthType + + # Client ID for GitHub Apps + [string] $ClientID + + # The device flow type. + # GitHubApp / OAuthApp + [string] $DeviceFlowType + + # The API hostname. + # github.com / msx.ghe.com / github.local + [string] $HostName + + # User ID / App ID as GraphQL Node ID + [string] $NodeID + + # The Database ID of the context. + [string] $DatabaseID + + # The context ID. + # HostName/Username or HostName/AppSlug + [string] $ContextID + + # The user name. + [string] $UserName + + # The default value for the Owner parameter. + [string] $Owner + + # The default value for the Repo parameter. + [string] $Repo + + # The scope when authenticating with OAuth. + # 'gist read:org repo workflow' + [string] $Scope + + # The token type. + # ghu / gho / ghp / github_pat / PEM / ghs / + [string] $TokenType + + # The access token. + [securestring] $Token + + # The token expiration date. + # 2024-01-01-00:00:00 + [datetime] $TokenExpirationDate + + # The refresh token. + [securestring] $RefreshToken + + # The refresh token expiration date. + # 2024-01-01-00:00:00 + [datetime] $RefreshTokenExpirationDate + + GitHubContext([string]$ContextID) { + $this.ContextID = $ContextID + } + + GitHubContext([hashtable]$Properties) { + $this.Init($Properties) + } + + [void] Init([hashtable]$Properties) { + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } +} From e78dd98af4998b3781ef76e70fc3fd5ddfcc5fdb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 16:26:26 +0100 Subject: [PATCH 075/134] Add XML format definitions for GitHubContext display in table and list views --- src/formats/GitHubContext.Format.ps1xml | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/formats/GitHubContext.Format.ps1xml diff --git a/src/formats/GitHubContext.Format.ps1xml b/src/formats/GitHubContext.Format.ps1xml new file mode 100644 index 000000000..fae31a1c3 --- /dev/null +++ b/src/formats/GitHubContext.Format.ps1xml @@ -0,0 +1,131 @@ + + + + + + GitHubContextTableView + + GitHubContext + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UserName + + + HostName + + + AuthType + + + TokenType + + + TokenExpirationDate + + + Owner + + + Repo + + + + + + + + + + GitHubContextListView + + GitHubContext + + + + + + + HostName + + + UserName + + + AuthType + + + TokenType + + + TokenExpirationDate + + + Repo + + + Scope + + + ApiBaseUri + + + ApiVersion + + + AuthClientID + + + ClientID + + + DeviceFlowType + + + NodeID + + + DatabaseID + + + ContextID + + + Owner + + + RefreshTokenExpirationDate + + + + + + + + From 38bf10455bdb01cd9acc5fa47f962460063bf083 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 16:39:54 +0100 Subject: [PATCH 076/134] Refactor GitHubContext constructor to accept PSCustomObject and update Get-GitHubContext output type to GitHubContext --- src/classes/public/GitHubContext.ps1 | 10 ++++++---- .../public/Auth/Context/Get-GitHubContext.ps1 | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 index 47aa597ab..2a1339e9a 100644 --- a/src/classes/public/GitHubContext.ps1 +++ b/src/classes/public/GitHubContext.ps1 @@ -72,12 +72,14 @@ } GitHubContext([hashtable]$Properties) { - $this.Init($Properties) - } - - [void] Init([hashtable]$Properties) { foreach ($Property in $Properties.Keys) { $this.$Property = $Properties.$Property } } + + GitHubContext([PSCustomObject]$Object) { + foreach ($Property in $Object.PSObject.Properties) { + $this.$Property.Name = $Property.Value + } + } } diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index b56681c0d..e21944ee8 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -17,7 +17,7 @@ function Get-GitHubContext { 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Encapsulated in a function. Never leaves as a plain text.' )] - [OutputType([object])] + [OutputType([GitHubContext])] [CmdletBinding(DefaultParameterSetName = 'CurrentContext')] param( # The name of the context. @@ -47,5 +47,5 @@ function Get-GitHubContext { Write-Verbose "Getting the default context: [$ID]" } - Get-Context -ID $ID + [GitHubContext](Get-Context -ID $ID) } From c950fdd52145492ecb6f9757049e266cc53e1b7c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 17:06:05 +0100 Subject: [PATCH 077/134] Fix convertion from PSCustomObject to GitHubContext --- src/classes/public/GitHubContext.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 index 2a1339e9a..1a2b50c32 100644 --- a/src/classes/public/GitHubContext.ps1 +++ b/src/classes/public/GitHubContext.ps1 @@ -78,8 +78,8 @@ } GitHubContext([PSCustomObject]$Object) { - foreach ($Property in $Object.PSObject.Properties) { - $this.$Property.Name = $Property.Value + $Object.PSObject.Properties | ForEach-Object { + $this.($_.Name) = $_.Value } } } From dd597d43777e204b82c7e6a3053245f1cf5b777b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 17:17:03 +0100 Subject: [PATCH 078/134] Fix Get-GitHubConfig --- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 0335a114c..062f83244 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -22,7 +22,7 @@ function Get-GitHubConfig { ) if (-not $Name) { - return Get-Context -Name $script:Config.Name + return Get-Context -ID $script:Config.Name } Get-ContextSetting -Name $Name -ID $script:Config.Name From 09b649457672ec9a2dbced03689d53757060c3fe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 17:35:00 +0100 Subject: [PATCH 079/134] Fixes -ListAvailable for Get-GitHubContext --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index e21944ee8..95e20cf66 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -47,5 +47,7 @@ function Get-GitHubContext { Write-Verbose "Getting the default context: [$ID]" } - [GitHubContext](Get-Context -ID $ID) + Get-Context -ID $ID | ForEach-Object { + [GitHubContext]$_ + } } From 4848248959ba6f21ce2c739e7c486b1a250cea36 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 18:56:22 +0100 Subject: [PATCH 080/134] Enhance GitHub context management by renaming parameters, adding argument completers, and introducing Set-GitHubDefaultContext function --- .../public/Auth/Context/Get-GitHubContext.ps1 | 18 ++++++++-- .../public/Auth/Context/Set-GitHubContext.ps1 | 1 + .../Auth/Context/Set-GitHubDefaultContext.ps1 | 33 +++++++++++++++++++ .../public/Auth/Disconnect-GitHubAccount.ps1 | 15 +++++++-- 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 95e20cf66..c738868ae 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -25,7 +25,8 @@ function Get-GitHubContext { Mandatory, ParameterSetName = 'NamedContext' )] - [string] $Name, + [Alias('Name')] + [string] $Context, # List all available contexts. [Parameter( @@ -38,8 +39,8 @@ function Get-GitHubContext { if ($ListAvailable) { $ID = "$($script:Config.Name)/*" Write-Verbose "Getting available contexts for [$ID]" - } elseif ($Name) { - $ID = "$($script:Config.Name)/$Name" + } elseif ($Context) { + $ID = "$($script:Config.Name)/$Context" Write-Verbose "Getting available contexts for [$ID]" } else { $defaultContext = Get-GitHubConfig -Name 'DefaultContext' @@ -51,3 +52,14 @@ function Get-GitHubContext { [GitHubContext]$_ } } + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + $defaultContext = Get-GitHubConfig -Name 'DefaultContext' + + Get-Context -ID "$wordToComplete*" -Verbose:$false | Where-Object { $_.ContextID -ne $defaultContext } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } +} diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index caf1011a8..28182c56f 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -146,6 +146,7 @@ function Set-GitHubContext { } Write-Verbose "Found user with username: [$($context['Username'])]" } catch { + Remove-Context -ID $tempContextID Write-Error $_ throw 'Failed to get info on the context.' } diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 new file mode 100644 index 000000000..b4ecc1f31 --- /dev/null +++ b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 @@ -0,0 +1,33 @@ +function Set-GitHubDefaultContext { + <# + .SYNOPSIS + Set the default context. + + .DESCRIPTION + Set the default context for the GitHub module. + + .EXAMPLE + Set-GitHubDefaultContext -Context 'github.com/Octocat' + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # The context to set as the default. + [Parameter(Mandatory)] + [string] $Context + ) + + if ($PSCmdlet.ShouldProcess("$Context", 'Set default context')) { + Set-GitHubConfig -Name 'DefaultContext' -Value $Context + } +} + +Register-ArgumentCompleter -CommandName Set-GitHubDefaultContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + $defaultContext = Get-GitHubConfig -Name 'DefaultContext' + + Get-Context -ID "$wordToComplete*" -Verbose:$false | Where-Object { $_.ContextID -ne $defaultContext } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } +} diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 546033bdf..dca129fab 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -25,12 +25,23 @@ [OutputType([void])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] - param () + param( + $Context + ) $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - Remove-Context -Name "$($script:Config.Name)/$defaultContext" + Remove-Context -ID "$($script:Config.Name)/$defaultContext" Remove-GitHubConfig -Name 'DefaultContext' Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged out of GitHub! [$defaultContext]" } + +Register-ArgumentCompleter -CommandName Disconnect-GitHubAccount -ParameterName ID -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-Context -ID "$wordToComplete*" -Verbose:$false | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } +} From 21bc568d51c817ceacab0c896ff8b08f7572b422 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 19:10:26 +0100 Subject: [PATCH 081/134] Fix default context --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index c738868ae..298bbdf66 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -43,7 +43,10 @@ function Get-GitHubContext { $ID = "$($script:Config.Name)/$Context" Write-Verbose "Getting available contexts for [$ID]" } else { - $defaultContext = Get-GitHubConfig -Name 'DefaultContext' + $config = Get-GitHubConfig + if ([string]::IsNullOrEmpty($config.DefaultContext)) { + throw "No default GitHub context found. Please run 'Set-GitHubDefaultContext' or 'Connect-GitHub' to configure a GitHub context." + } $ID = "$($script:Config.Name)/$defaultContext" Write-Verbose "Getting the default context: [$ID]" } From ffe0bb4cd4070ef05c16049988253ddee86bbe94 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 19:24:40 +0100 Subject: [PATCH 082/134] Fix --- .../public/Auth/Disconnect-GitHubAccount.ps1 | 50 +++++++++++-------- tests/GitHub.Tests.ps1 | 2 +- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index dca129fab..22cc51bbc 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -1,43 +1,53 @@ function Disconnect-GitHubAccount { <# .SYNOPSIS - Disconnects from GitHub and removes the current GitHub configuration. + Disconnects from GitHub and removes the GitHub context. .DESCRIPTION - Disconnects from GitHub and removes the current GitHub configuration. + Disconnects from GitHub and removes the GitHub context. .EXAMPLE Disconnect-GitHubAccount - Disconnects from GitHub and removes the current GitHub configuration. + Disconnects from GitHub and removes the default GitHub context. + + .EXAMPLE + Disconnect-GithubAccount -Context 'github.com/Octocat' + + Disconnects from GitHub and removes the context 'github.com/Octocat'. #> - [Alias('Disconnect-GHAccount')] - [Alias('Disconnect-GitHub')] - [Alias('Disconnect-GH')] - [Alias('Logout-GitHubAccount')] - [Alias('Logout-GHAccount')] - [Alias('Logout-GitHub')] - [Alias('Logout-GH')] - [Alias('Logoff-GitHubAccount')] - [Alias('Logoff-GHAccount')] - [Alias('Logoff-GitHub')] - [Alias('Logoff-GH')] + [Alias( + 'Disconnect-GHAccount', + 'Disconnect-GitHub', + 'Disconnect-GH', + 'Logout-GitHubAccount', + 'Logout-GHAccount', + 'Logout-GitHub', + 'Logout-GH', + 'Logoff-GitHubAccount', + 'Logoff-GHAccount', + 'Logoff-GitHub', + 'Logoff-GH' + )] [OutputType([void])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] param( - $Context + # The context to log out of. + [Parameter()] + [Alias('Name')] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) - $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - Remove-Context -ID "$($script:Config.Name)/$defaultContext" - Remove-GitHubConfig -Name 'DefaultContext' + $Context = Get-GitHubConfig -Name 'DefaultContext' + Remove-Context -ID "$($script:Config.Name)/$Context" + Remove-GitHubConfig -Name $Context Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Logged out of GitHub! [$defaultContext]" + Write-Host "Logged out of GitHub! [$Context]" } -Register-ArgumentCompleter -CommandName Disconnect-GitHubAccount -ParameterName ID -ScriptBlock { +Register-ArgumentCompleter -CommandName Disconnect-GitHubAccount -ParameterName Context -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 9bd7f24a6..72f406025 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -26,7 +26,7 @@ It 'Can list all contexts' { Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose - (Get-GitHubContext -ListAvailable).Count | Should -Be 4 + (Get-GitHubContext -ListAvailable).Count | Should -Be 3 } # It 'Can be called with a GitHub App Installation Access Token' { From 8143bf363e0f9e8b9bd2dda1832e3e7fe77835c9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 19:41:17 +0100 Subject: [PATCH 083/134] Fix Get-GitHubContext --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 298bbdf66..99329120d 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -44,10 +44,11 @@ function Get-GitHubContext { Write-Verbose "Getting available contexts for [$ID]" } else { $config = Get-GitHubConfig - if ([string]::IsNullOrEmpty($config.DefaultContext)) { + $Context = $config.DefaultContext + if ([string]::IsNullOrEmpty($Context)) { throw "No default GitHub context found. Please run 'Set-GitHubDefaultContext' or 'Connect-GitHub' to configure a GitHub context." } - $ID = "$($script:Config.Name)/$defaultContext" + $ID = "$($script:Config.Name)/$Context" Write-Verbose "Getting the default context: [$ID]" } From 9a60b8c011c0c6b031cf7b4970261f66532e8180 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 20:31:29 +0100 Subject: [PATCH 084/134] Fix --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 28182c56f..891346878 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -155,7 +155,7 @@ function Set-GitHubContext { Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context Remove-Context -ID $tempContextID if ($Default) { - Set-GitHubConfig -Name 'DefaultContext' -Value $newContextID + Set-GitHubDefaultContext -Context $newContextID } } } From ee9f4e40f4c9351759e525a9034dcd26ce6bf003 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 20:35:44 +0100 Subject: [PATCH 085/134] Fix SetGitHubcontext --- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 48c7506f7..6b6155efb 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -99,7 +99,7 @@ function Set-GitHubContextSetting { $value = $_.Value if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$value]")) { Write-Verbose "Setting [$key] to [$value]" - Set-ContextSetting -Name $key -Value $value -Context $contextID + Set-ContextSetting -Name $key -Value $value -ID $contextID } } } From d4ba085a0ecc56b6032df74c631542ad6ef21e1a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 20:55:29 +0100 Subject: [PATCH 086/134] Check if we can swap context --- .../public/Auth/Context/Set-GitHubDefaultContext.ps1 | 1 + tests/GitHub.Tests.ps1 | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 index b4ecc1f31..db6012fa7 100644 --- a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 @@ -13,6 +13,7 @@ param ( # The context to set as the default. [Parameter(Mandatory)] + [Alias('Name')] [string] $Context ) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 72f406025..7a2881f8c 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -1,5 +1,5 @@ Describe 'GitHub' { - Context 'Connect-GitHubAccount' { + Context 'Auth' { It 'Connect-GitHubAccount function exists' { Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty } @@ -29,6 +29,11 @@ (Get-GitHubContext -ListAvailable).Count | Should -Be 3 } + It 'Can swap context to another' { + { Set-GitHubDefaultContext -Context 'github.com/github-actions[bot]' } | Should -Not -Throw + Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions[bot]' + } + # It 'Can be called with a GitHub App Installation Access Token' { # { Connect-GitHubAccount -Token $env:TEST_APP_INSTALLATION_ACCESS_TOKEN } | Should -Not -Throw # } From e95823eb56c905b09d30380fb7002733f036ae05 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 21:39:06 +0100 Subject: [PATCH 087/134] Many fixes :) --- .../Test-GitHubAccessTokenRefreshRequired.ps1 | 14 ++++---- .../License/Get-GitHubRepositoryLicense.ps1 | 28 ++++++++-------- .../Assets/Get-GitHubReleaseAssetByID.ps1 | 4 +-- .../Get-GitHubReleaseAssetByReleaseID.ps1 | 4 +-- .../Releases/Get-GitHubReleaseAll.ps1 | 4 +-- .../Releases/Get-GitHubReleaseByID.ps1 | 4 +-- .../Releases/Get-GitHubReleaseByTagName.ps1 | 4 +-- .../Releases/Get-GitHubReleaseLatest.ps1 | 4 +-- .../Get-GitHubRepositoryAutolinkById.ps1 | 4 +-- .../Get-GitHubRepositoryAutolinkList.ps1 | 4 +-- .../Get-GitHubRepositoryByName.ps1 | 4 +-- .../Get-GitHubRepositoryListByOrg.ps1 | 2 +- .../New-GitHubRepositoryFromTemplate.ps1 | 2 +- .../Repositories/New-GitHubRepositoryOrg.ps1 | 2 +- .../public/Actions/Disable-GitHubWorkflow.ps1 | 4 +-- .../public/Actions/Enable-GitHubWorkflow.ps1 | 4 +-- .../public/Actions/Get-GitHubWorkflow.ps1 | 4 +-- .../public/Actions/Get-GitHubWorkflowRun.ps1 | 4 +-- .../Actions/Get-GitHubWorkflowUsage.ps1 | 4 +-- .../Actions/Remove-GitHubWorkflowRun.ps1 | 4 +-- .../public/Actions/Start-GitHubWorkflow.ps1 | 4 +-- .../Actions/Start-GitHubWorkflowReRun.ps1 | 4 +-- .../public/Actions/Stop-GitHubWorkflowRun.ps1 | 4 +-- .../public/Branches/Get-GitHubRepoBranch.ps1 | 4 +-- .../public/License/Get-GitHubLicense.ps1 | 4 +-- .../Assets/Add-GitHubReleaseAsset.ps1 | 4 +-- .../Assets/Get-GitHubReleaseAsset.ps1 | 4 +-- .../Assets/Remove-GitHubReleaseAsset.ps1 | 4 +-- .../Assets/Set-GitHubReleaseAsset.ps1 | 4 +-- .../Releases/Releases/Get-GitHubRelease.ps1 | 4 +-- .../Releases/Releases/New-GitHubRelease.ps1 | 4 +-- .../Releases/New-GitHubReleaseNote.ps1 | 4 +-- .../Releases/Remove-GitHubRelease.ps1 | 4 +-- .../Releases/Releases/Set-GitHubRelease.ps1 | 4 +-- .../Get-GitHubRepositoryAutolink.ps1 | 4 +-- .../Get-GitHubRepositoryCustomProperty.ps1 | 4 +-- ...epositoryPrivateVulnerabilityReporting.ps1 | 4 +-- .../Disable-GitHubRepositorySecurityFix.ps1 | 4 +-- ...ble-GitHubRepositoryVulnerabilityAlert.ps1 | 4 +-- ...epositoryPrivateVulnerabilityReporting.ps1 | 4 +-- .../Enable-GitHubRepositorySecurityFix.ps1 | 4 +-- ...ble-GitHubRepositoryVulnerabilityAlert.ps1 | 4 +-- .../Repositories/Get-GitHubRepository.ps1 | 4 +-- .../Get-GitHubRepositoryActivity.ps1 | 4 +-- .../Get-GitHubRepositoryCodeownersError.ps1 | 4 +-- .../Get-GitHubRepositoryContributor.ps1 | 4 +-- .../Repositories/Get-GitHubRepositoryFork.ps1 | 4 +-- .../Get-GitHubRepositoryLanguage.ps1 | 4 +-- .../Get-GitHubRepositorySecurityFix.ps1 | 4 +-- .../Repositories/Get-GitHubRepositoryTag.ps1 | 4 +-- .../Repositories/Get-GitHubRepositoryTeam.ps1 | 4 +-- .../Get-GitHubRepositoryTopic.ps1 | 4 +-- .../Repositories/Move-GitHubRepository.ps1 | 4 +-- .../Repositories/New-GitHubRepository.ps1 | 2 +- .../Set-GitHubRepositoryTopic.ps1 | 4 +-- .../Start-GitHubRepositoryEvent.ps1 | 4 +-- ...est-GitHubRepositoryVulnerabilityAlert.ps1 | 4 +-- .../Repositories/Update-GitHubRepository.ps1 | 4 +-- .../Get-GitHubRepositoryRuleSuite.ps1 | 4 +-- .../Get-GitHubRepositoryRuleSuiteById.ps1 | 4 +-- .../Get-GitHubRepositoryRuleSuiteList.ps1 | 4 +-- .../Get-GitHubRepositoryTagProtection.ps1 | 4 +-- .../New-GitHubRepositoryTagProtection.ps1 | 4 +-- .../Remove-GitHubRepositoryTagProtection.ps1 | 4 +-- .../public/Teams/Get-GitHubRepoTeam.ps1 | 4 +-- tests/GitHub.Tests.ps1 | 32 +++++++++---------- 66 files changed, 157 insertions(+), 161 deletions(-) diff --git a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 index 744be9183..671a1a8ff 100644 --- a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 @@ -13,15 +13,13 @@ #> [OutputType([bool])] [CmdletBinding()] - param() + param( + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) - $tokenType = Get-GitHubConfig -Name 'TokenType' -ErrorAction SilentlyContinue - if ($tokenType -ne 'ghu_*') { - Write-Verbose 'The access token is not a user token. No need to refresh.' - return $false - } - - $tokenExpirationDate = Get-GitHubConfig -Name 'TokenExpirationDate' -ErrorAction SilentlyContinue + $contextObj = Get-GitHubContext -Context $Context + $tokenExpirationDate = $contextObj.TokenExpirationDate $currentDateTime = Get-Date $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime diff --git a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 index b3db1c4c2..73a2912ed 100644 --- a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 +++ b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 @@ -22,25 +22,23 @@ filter Get-GitHubRepositoryLicense { param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) - process { - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/license" - Accept = 'application/vnd.github+json' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $Response = $_.Response - $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) - $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force - $Response - } + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/license" + Accept = 'application/vnd.github+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $Response = $_.Response + $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) + $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force + $Response } } diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 index 1ec06269f..e7387d5f8 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 @@ -22,11 +22,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter(Mandatory)] diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index cb3ac0b0d..ea8dd0bdf 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter( diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index 7ebd6982c..2ed5b0145 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -21,11 +21,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter(ParameterSetName = 'AllUsers')] diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 index 34cf612a4..ae2cab2e6 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter( diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 index 4ed7ccf35..db6b659f0 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the tag to get a release from. [Parameter( diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 index 8cc417614..013a812ca 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 @@ -21,11 +21,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 index b77396a33..cdff8e230 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the autolink. [Parameter(Mandatory)] diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 index c3a49359e..3edebc52c 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 index a37e81f12..b7f6c6422 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 @@ -24,11 +24,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index d6666f478..9e2f108a2 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -33,7 +33,7 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # Specifies the types of repositories you want returned. [Parameter()] diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 index b7b240a0c..e5a59dbcb 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 @@ -52,7 +52,7 @@ # To create a new repository in an organization, the authenticated user must be a member of the specified organization. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the new repository. [Parameter(Mandatory)] diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index fef14ccf1..1f8c969c2 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -64,7 +64,7 @@ filter New-GitHubRepositoryOrg { # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository. [Parameter(Mandatory)] diff --git a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 index 9fe267110..ded382b88 100644 --- a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 @@ -6,10 +6,10 @@ [CmdletBinding()] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter( Mandatory, diff --git a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 index 9a577fe53..a18258708 100644 --- a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 @@ -6,10 +6,10 @@ [CmdletBinding()] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter( Mandatory, diff --git a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 b/src/functions/public/Actions/Get-GitHubWorkflow.ps1 index 9d7579a07..657690ec8 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflow.ps1 @@ -24,10 +24,10 @@ [CmdletBinding(DefaultParameterSetName = 'ByName')] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 index e822d26bc..60af3bb19 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -8,10 +8,10 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter(ParameterSetName = 'ByName')] [string] $Name, diff --git a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 index 6f569924f..1bcdec709 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -26,10 +26,10 @@ )] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter( Mandatory, diff --git a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 index b76928c96..723e8d809 100644 --- a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the workflow run. [Parameter( diff --git a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 b/src/functions/public/Actions/Start-GitHubWorkflow.ps1 index ccef74f94..1a50ddb7c 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Start-GitHubWorkflow.ps1 @@ -21,11 +21,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The ID of the workflow. [Alias('workflow_id')] diff --git a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 index f9e95b180..f4dc66dc3 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -16,11 +16,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the workflow run. [Alias('workflow_id')] diff --git a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 index 0d42b6a83..181293df4 100644 --- a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -18,10 +18,10 @@ [alias('Cancel-GitHubWorkflowRun')] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Alias('workflow_id')] [Parameter( diff --git a/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 b/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 index 2b98f1304..331bbe848 100644 --- a/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 @@ -18,11 +18,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/License/Get-GitHubLicense.ps1 b/src/functions/public/License/Get-GitHubLicense.ps1 index 565d4fb3d..5a4efc21b 100644 --- a/src/functions/public/License/Get-GitHubLicense.ps1 +++ b/src/functions/public/License/Get-GitHubLicense.ps1 @@ -38,11 +38,11 @@ filter Get-GitHubLicense { param ( # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'Repository')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(ParameterSetName = 'Repository')] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) dynamicparam { diff --git a/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 index b98a4ed9e..f2086ee52 100644 --- a/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 @@ -49,11 +49,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 index 699be6046..90bb38cf8 100644 --- a/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 @@ -25,11 +25,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter( diff --git a/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 index 0c11f52ea..75bbcf0e0 100644 --- a/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index e7b4bf778..3bfb3c3ba 100644 --- a/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 index 8b1bdee84..038070ed2 100644 --- a/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 @@ -38,11 +38,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter(ParameterSetName = 'All')] diff --git a/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 index e5b607712..a3523734b 100644 --- a/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 @@ -25,11 +25,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the tag. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 b/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 index 2b0d3568a..07e64114f 100644 --- a/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 +++ b/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 @@ -59,11 +59,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The tag name for the release. This can be an existing tag or a new one. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 index c1593fa93..6a29a900d 100644 --- a/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter( diff --git a/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 index 34d378bff..2993b6f0c 100644 --- a/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 index c1f9bc093..d9c43dd25 100644 --- a/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 +++ b/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -28,11 +28,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the autolink. [Parameter( diff --git a/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 b/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 index 14246562a..7dff0bc03 100644 --- a/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 +++ b/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 index 0722bc0d9..580c24b4b 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index 351bb170e..cd6158d98 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 index d2d9d6c41..0b9eb8af6 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 index 884b887d5..0889ca16b 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 index f62a5c51c..66b608b79 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 index ce63b877c..f20658e26 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 8ce82e0e6..26ff63958 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -82,14 +82,14 @@ filter Get-GitHubRepository { # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'ByName')] [Parameter(ParameterSetName = 'ListByOrg')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter( Mandatory, ParameterSetName = 'ByName' )] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The handle for the GitHub user account. [Parameter( diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 index eeb98ad21..690710b74 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -54,11 +54,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The direction to sort the results by. [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 index 9fc9967d9..9d3fff276 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # A branch, tag or commit name used to determine which version of the CODEOWNERS file to use. # Default: the repository's default branch (e.g. main) diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 index 0c4475f3c..7e6477830 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 @@ -25,11 +25,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # Wether to include anonymous contributors in results. [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 index 8f699b9f0..35f2a2671 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 @@ -20,11 +20,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The direction to sort the results by. [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 index 97e7dd0e8..ee26ec371 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index 3cc87e91c..78005111d 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 index 9f01df1a6..264f51b3e 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 @@ -21,11 +21,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 index 56ef4948e..1b0d53e82 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 @@ -29,11 +29,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 index a5725700b..86139402e 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -17,11 +17,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 index 0bdd16791..bbd1cf1c3 100644 --- a/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 @@ -25,11 +25,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The username or organization name the repository will be transferred to. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 index 0a1c75c51..1f9e16f61 100644 --- a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -113,7 +113,7 @@ filter New-GitHubRepository { [Parameter(ParameterSetName = 'org')] [Parameter(ParameterSetName = 'fork')] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository. [Parameter(ParameterSetName = 'fork')] diff --git a/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index f0655a3ea..84321e3c6 100644 --- a/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -19,11 +19,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 b/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 index 841231d09..1351cf4ef 100644 --- a/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 +++ b/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 @@ -46,11 +46,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # A custom webhook event name. Must be 100 characters or fewer. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 index 20d7a15c8..dfb8ace31 100644 --- a/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 index a95b7c121..5df971400 100644 --- a/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 @@ -28,11 +28,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the repository. [Parameter()] diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 index f4a6db95b..b9bd1f72f 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 @@ -37,11 +37,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the ref. Cannot contain wildcard characters. # When specified, only rule evaluations triggered for this ref will be returned. diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 index 0c0d92b99..2e7e08306 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the rule suite result. To get this ID, you can use GET /repos/ { owner }/ { repo }/rulesets/rule-suites for repositories and GET /orgs/ { org }/rulesets/rule-suites for organizations. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 index 4544d818c..1168ce9c4 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 @@ -31,11 +31,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the ref. Cannot contain wildcard characters. # When specified, only rule evaluations triggered for this ref will be returned. diff --git a/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 index 5fb0b0f62..ad089c4ac 100644 --- a/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 index 3549d5a03..df107bb7b 100644 --- a/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 @@ -21,11 +21,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # An optional glob pattern to match against when enforcing tag protection. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 index cd59eadd2..414af87f4 100644 --- a/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the tag protection. [Parameter(Mandatory)] diff --git a/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 b/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 index 1431fa83e..c472512a5 100644 --- a/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 @@ -6,10 +6,10 @@ filter Get-GitHubRepoTeam { [CmdletBinding()] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 7a2881f8c..dbf456756 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -39,9 +39,24 @@ # } } + Context 'Config' { + It 'Get-GitHubConfig function exists' { + Get-Command Get-GitHubConfig | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubConfig gets the DefaultContext' { + Write-Verbose (Get-GitHubConfig -Name 'DefaultContext') -Verbose + { Get-GitHubConfig -Name 'DefaultContext' } | Should -Not -Throw + } + It 'Can be called without a parameter' { + $config = Get-GitHubConfig + Write-Verbose ($config | Format-Table | Out-String) -Verbose + { Get-GitHubConfig } | Should -Not -Throw + $config.ContextID | Should -Be 'GitHub' + } + } - Context 'Invoke-GitHubAPI' { + Context 'API' { It 'Invoke-GitHubAPI function exists' { Get-Command Invoke-GitHubAPI | Should -Not -BeNullOrEmpty } @@ -50,22 +65,7 @@ { Invoke-GitHubAPI -ApiEndpoint '/rate_limit' -Method GET } | Should -Not -Throw } } - Context 'Get-GitHubConfig' { - It 'Get-GitHubConfig function exists' { - Get-Command Get-GitHubConfig | Should -Not -BeNullOrEmpty - } - It 'Can be called directly to get the ApiBaseUri' { - Write-Verbose (Get-GitHubConfig -Name ApiBaseUri) -Verbose - { Get-GitHubConfig -Name ApiBaseUri } | Should -Not -Throw - } - It 'Can be called without a parameter' { - $config = Get-GitHubConfig - Write-Verbose ($config.Secrets | Format-List | Out-String) -Verbose - Write-Verbose ($config.Variables | Format-List | Out-String) -Verbose - { Get-GitHubConfig } | Should -Not -Throw - } - } Context 'Get-GitHubViewer' { It 'Get-GitHubViewer function exists' { Get-Command Get-GitHubViewer | Should -Not -BeNullOrEmpty From edcffc6596eda892af93b405839ec9cf000e44bf Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 13:43:41 +0100 Subject: [PATCH 088/134] Fix test structure --- tests/GitHub.Tests.ps1 | 45 ++++++++----------- .../Auth/Connect-GitHubAccount.Tests.ps1 | 15 ------- .../Auth/Disconnect-GitHubAccount.Tests.ps1 | 13 ------ 3 files changed, 19 insertions(+), 54 deletions(-) delete mode 100644 tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 delete mode 100644 tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index dbf456756..3cae5938a 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -1,21 +1,28 @@ Describe 'GitHub' { Context 'Auth' { - It 'Connect-GitHubAccount function exists' { - Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty + It 'Can connect and disconnect without parameters in GitHubActions' { + { Connect-GitHubAccount } | Should -Not -Throw + { Disconnect-GitHubAccount } | Should -Not -Throw } - It 'Can be called without parameters on GitHub Actions' { + It 'Can connect and disconnect - a second time' { + { Connect-GitHubAccount } | Should -Not -Throw { Connect-GitHubAccount } | Should -Not -Throw Write-Verbose (Get-GitHubContext | Out-String) -Verbose + { Disconnect-GitHubAccount } | Should -Not -Throw } - It 'Can be called with a classic PAT token' { + It 'Can connect multiple sessions, GITHUB_TOKEN + classic PAT token' { { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw + { Connect-GitHubAccount } | Should -Not -Throw + (Get-GitHubContext).Count | Should -Be 2 + Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions[bot]' Write-Verbose (Get-GitHubContext | Out-String) -Verbose } - It 'Can be called with a fine-grained PAT token' { + It 'Can reconfigure an existing context to be fine-grained PAT token' { { Connect-GitHubAccount -Token $env:TEST_FG_PAT } | Should -Not -Throw + (Get-GitHubContext).Count | Should -Be 2 Write-Verbose (Get-GitHubContext | Out-String) -Verbose } @@ -37,11 +44,9 @@ # It 'Can be called with a GitHub App Installation Access Token' { # { Connect-GitHubAccount -Token $env:TEST_APP_INSTALLATION_ACCESS_TOKEN } | Should -Not -Throw # } - } - Context 'Config' { - It 'Get-GitHubConfig function exists' { - Get-Command Get-GitHubConfig | Should -Not -BeNullOrEmpty + It 'Get-GitHubViewer can be called' { + Get-GitHubViewer | Should -Not -BeNullOrEmpty } It 'Get-GitHubConfig gets the DefaultContext' { @@ -55,24 +60,12 @@ $config.ContextID | Should -Be 'GitHub' } } +} - Context 'API' { - It 'Invoke-GitHubAPI function exists' { - Get-Command Invoke-GitHubAPI | Should -Not -BeNullOrEmpty - } - - It 'Can be called directly to get ratelimits' { - { Invoke-GitHubAPI -ApiEndpoint '/rate_limit' -Method GET } | Should -Not -Throw - } - } - - Context 'Get-GitHubViewer' { - It 'Get-GitHubViewer function exists' { - Get-Command Get-GitHubViewer | Should -Not -BeNullOrEmpty - } - It 'Get-GiTubViewer can be called' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty - } +Context 'API' { + It 'Can be called directly to get ratelimits' { + { $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' } | Should -Not -Throw + Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose } } diff --git a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 deleted file mode 100644 index 164e0be21..000000000 --- a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -Describe 'Connect-GitHubAccount' { - It 'Function exists' { - Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty - } - - Context 'Parameter Set: autologon IAT' { - It 'Can be called with without parameters' { - { Connect-GitHubAccount } | Should -Not -Throw - } - - It 'Can be called with without parameters - a second time' { - { Connect-GitHubAccount } | Should -Not -Throw - } - } -} diff --git a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 deleted file mode 100644 index 811bcd1f3..000000000 --- a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -Describe 'Disconnect-GitHubAccount' { - It 'Function exists' { - Get-Command Disconnect-GitHubAccount | Should -Not -BeNullOrEmpty - } - - It 'Can be called with no parameters' { - { Disconnect-GitHubAccount } | Should -Not -Throw - } - - It 'Can reconnect after disconnecting' { - { Connect-GitHubAccount } | Should -Not -Throw - } -} From 7ae6dff738c0c91efa3c5b2737009ef84c1d973c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 14:16:57 +0100 Subject: [PATCH 089/134] Add Remove-GitHubContext function to manage context removal --- .../Auth/Context/Remove-GitHubContext.ps1 | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/functions/public/Auth/Context/Remove-GitHubContext.ps1 diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 new file mode 100644 index 000000000..b47706dc9 --- /dev/null +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -0,0 +1,37 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } + +filter Remove-GitHubContext { + <# + .SYNOPSIS + Removes a context from the context vault. + + .DESCRIPTION + This function removes a context from the vault. It supports removing a single context by name, + multiple contexts using wildcard patterns, and can also accept input from the pipeline. + If the specified context(s) exist, they will be removed from the vault. + + .EXAMPLE + Remove-Context + + Removes all contexts from the vault. + + .EXAMPLE + Remove-Context -ID 'MySecret' + + Removes the context called 'MySecret' from the vault. + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The name of the context. + [Parameter(Mandatory)] + [Alias('Name')] + [string] $Context + ) + + $ID = "$($script:Config.Name)/$Context" + + if ($PSCmdlet.ShouldProcess('Remove-Secret', $context.Name)) { + Remove-Context -ID $ID + } +} From dc98156cffed6572c252c0a1c95d41b3a94e83ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 14:21:26 +0100 Subject: [PATCH 090/134] Fix disconnect --- src/functions/public/Auth/Disconnect-GitHubAccount.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 22cc51bbc..a839a2fc7 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -40,8 +40,8 @@ ) $Context = Get-GitHubConfig -Name 'DefaultContext' - Remove-Context -ID "$($script:Config.Name)/$Context" - Remove-GitHubConfig -Name $Context + Remove-GitHubContext -ID $Context + Remove-GitHubConfig -Name 'DefaultContext' Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged out of GitHub! [$Context]" From 2fe1da95792665cb0175924037af44efd4b68cda Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 14:31:44 +0100 Subject: [PATCH 091/134] Refactor Disconnect-GitHubAccount to use context parameter and improve test structure --- src/functions/public/Auth/Disconnect-GitHubAccount.ps1 | 2 +- tests/GitHub.Tests.ps1 | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index a839a2fc7..adf96f9c6 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -40,7 +40,7 @@ ) $Context = Get-GitHubConfig -Name 'DefaultContext' - Remove-GitHubContext -ID $Context + Remove-GitHubContext -Context $Context Remove-GitHubConfig -Name 'DefaultContext' Write-Host '✓ ' -ForegroundColor Green -NoNewline diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 3cae5938a..7b2d42284 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -64,8 +64,11 @@ Context 'API' { It 'Can be called directly to get ratelimits' { - { $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' } | Should -Not -Throw - Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose + { + $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' + Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose + } | Should -Not -Throw + } } From 02cf8ce833dcecd369a27a594c9a28fecee737df Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 14:44:42 +0100 Subject: [PATCH 092/134] Test --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 5 +++++ src/functions/public/Auth/Disconnect-GitHubAccount.ps1 | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 261c4ef0c..058ec1ab4 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -132,6 +132,10 @@ [Alias('s')] [switch] $Silent ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + try { if ($Token -is [System.Security.SecureString]) { $Token = ConvertFrom-SecureString $Token -AsPlainText @@ -308,4 +312,5 @@ Remove-Variable -Name context -ErrorAction SilentlyContinue [System.GC]::Collect() } + Write-Verbose "[$commandName] - Start" } diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index adf96f9c6..dc3b948a2 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -39,12 +39,17 @@ [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + $Context = Get-GitHubConfig -Name 'DefaultContext' Remove-GitHubContext -Context $Context Remove-GitHubConfig -Name 'DefaultContext' Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged out of GitHub! [$Context]" + + Write-Verbose "[$commandName] - Start" } Register-ArgumentCompleter -CommandName Disconnect-GitHubAccount -ParameterName Context -ScriptBlock { From d7e15469500fdac9b3b90fe7e95a712ba7edabd2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 15:09:34 +0100 Subject: [PATCH 093/134] Add verbose logging for command execution start and end in GitHub context functions --- .../public/Auth/Connect-GitHubAccount.ps1 | 2 +- .../public/Auth/Context/Get-GitHubContext.ps1 | 5 +++++ .../Auth/Context/Remove-GitHubContext.ps1 | 5 +++++ .../public/Auth/Context/Set-GitHubContext.ps1 | 5 +++++ .../Auth/Context/Set-GitHubDefaultContext.ps1 | 5 +++++ .../ContextSetting/Get-GitHubContextSetting.ps1 | 5 +++++ .../ContextSetting/Set-GitHubContextSetting.ps1 | 5 +++++ .../public/Auth/Disconnect-GitHubAccount.ps1 | 2 +- src/functions/public/Auth/Get-GitHubViewer.ps1 | 17 ++++++++++++++--- 9 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 058ec1ab4..ed67b4a46 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -312,5 +312,5 @@ Remove-Variable -Name context -ErrorAction SilentlyContinue [System.GC]::Collect() } - Write-Verbose "[$commandName] - Start" + Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 99329120d..fef9763a0 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -36,6 +36,9 @@ function Get-GitHubContext { [switch] $ListAvailable ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + if ($ListAvailable) { $ID = "$($script:Config.Name)/*" Write-Verbose "Getting available contexts for [$ID]" @@ -55,6 +58,8 @@ function Get-GitHubContext { Get-Context -ID $ID | ForEach-Object { [GitHubContext]$_ } + + Write-Verbose "[$commandName] - End" } Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index b47706dc9..f60d7d6dd 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -29,9 +29,14 @@ filter Remove-GitHubContext { [string] $Context ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + $ID = "$($script:Config.Name)/$Context" if ($PSCmdlet.ShouldProcess('Remove-Secret', $context.Name)) { Remove-Context -ID $ID } + + Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 891346878..2fd54e61c 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -89,6 +89,9 @@ function Set-GitHubContext { [switch] $Default ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + $tempContextName = 'tempContext' $tempContextID = "$($script:Config.Name)/$tempContextName" @@ -158,4 +161,6 @@ function Set-GitHubContext { Set-GitHubDefaultContext -Context $newContextID } } + + Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 index db6012fa7..67eaae4b4 100644 --- a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 @@ -17,9 +17,14 @@ [string] $Context ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + if ($PSCmdlet.ShouldProcess("$Context", 'Set default context')) { Set-GitHubConfig -Name 'DefaultContext' -Value $Context } + + Write-Verbose "[$commandName] - End" } Register-ArgumentCompleter -CommandName Set-GitHubDefaultContext -ParameterName Context -ScriptBlock { diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 54997569c..14bf4bbf7 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -25,6 +25,9 @@ function Get-GitHubContextSetting { [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + $contextID = "$($script:Config.Name)/$Context" if (-not $Name) { @@ -32,4 +35,6 @@ function Get-GitHubContextSetting { } Get-ContextSetting -Name $Name -ID $contextID + + Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 6b6155efb..6da1c951e 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -90,6 +90,9 @@ function Set-GitHubContextSetting { [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + $contextID = "$($Script:Config.Name)/$Context" if ($PSCmdlet.ShouldProcess('Config', 'Set')) { @@ -103,4 +106,6 @@ function Set-GitHubContextSetting { } } } + + Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index dc3b948a2..4b489b865 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -49,7 +49,7 @@ Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged out of GitHub! [$Context]" - Write-Verbose "[$commandName] - Start" + Write-Verbose "[$commandName] - End" } Register-ArgumentCompleter -CommandName Disconnect-GitHubAccount -ParameterName Context -ScriptBlock { diff --git a/src/functions/public/Auth/Get-GitHubViewer.ps1 b/src/functions/public/Auth/Get-GitHubViewer.ps1 index b748c7fd2..cf19ee17a 100644 --- a/src/functions/public/Auth/Get-GitHubViewer.ps1 +++ b/src/functions/public/Auth/Get-GitHubViewer.ps1 @@ -23,13 +23,24 @@ [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) - $query = @" + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + } + + process { + $query = @" query { viewer { $($Fields -join "`n") } } "@ - $results = Invoke-GitHubGraphQLQuery -Query $query -Context $Context - return $results.data.viewer + $results = Invoke-GitHubGraphQLQuery -Query $query -Context $Context + + return $results.data.viewer + } + end { + Write-Verbose "[$commandName] - End" + } } From 7a66aedc15043b7b453e7102a667dce1b9a2be65 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 15:27:15 +0100 Subject: [PATCH 094/134] Add verbose logging for command execution in Get-GitHubViewer, Get-GitHubConfig, and Remove-GitHubConfig functions --- src/functions/public/Auth/Get-GitHubViewer.ps1 | 1 + .../public/Config/Get-GitHubConfig.ps1 | 17 ++++++++++++++--- .../public/Config/Remove-GitHubConfig.ps1 | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Get-GitHubViewer.ps1 b/src/functions/public/Auth/Get-GitHubViewer.ps1 index cf19ee17a..1b3292ac3 100644 --- a/src/functions/public/Auth/Get-GitHubViewer.ps1 +++ b/src/functions/public/Auth/Get-GitHubViewer.ps1 @@ -40,6 +40,7 @@ query { return $results.data.viewer } + end { Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 062f83244..a4a17882e 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -21,9 +21,20 @@ function Get-GitHubConfig { [string] $Name ) - if (-not $Name) { - return Get-Context -ID $script:Config.Name + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" } - Get-ContextSetting -Name $Name -ID $script:Config.Name + process { + if (-not $Name) { + return Get-Context -ID $script:Config.Name + } + + Get-ContextSetting -Name $Name -ID $script:Config.Name + } + + end { + Write-Verbose "[$commandName] - End" + } } diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 3d2e041a0..555d7ce41 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -20,7 +20,12 @@ function Remove-GitHubConfig { [string] $Name ) + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) { Set-ContextSetting -Name $Name -Value $null -ID $script:Config.Name } + + Write-Verbose "[$commandName] - End" } From 0e047ba80749ef371466c88b8c403dfcea244aa9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 15:57:32 +0100 Subject: [PATCH 095/134] Error with PSCallStack --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index ed67b4a46..149da7224 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -305,6 +305,7 @@ Write-Host "Logged in as $name!" } } catch { + Write-Error (Get-PSCallStack | Format-Table | Out-String) Write-Error $_ throw 'Failed to connect to GitHub.' } finally { From 9c676e795ad57006f44ac1bded84106661a52f49 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 16:12:29 +0100 Subject: [PATCH 096/134] Enhance error handling in Connect-GitHubAccount and Remove-GitHubConfig functions; add New-Function utility script --- .../public/Auth/Connect-GitHubAccount.ps1 | 2 +- .../public/Config/Remove-GitHubConfig.ps1 | 10 +++- tools/utilities/New-Function.ps1 | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tools/utilities/New-Function.ps1 diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 149da7224..0b89c1372 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -305,8 +305,8 @@ Write-Host "Logged in as $name!" } } catch { - Write-Error (Get-PSCallStack | Format-Table | Out-String) Write-Error $_ + Write-Error (Get-PSCallStack | Format-Table | Out-String) throw 'Failed to connect to GitHub.' } finally { Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 555d7ce41..92de303db 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -23,8 +23,14 @@ function Remove-GitHubConfig { $commandName = $MyInvocation.MyCommand.Name Write-Verbose "[$commandName] - Start" - if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) { - Set-ContextSetting -Name $Name -Value $null -ID $script:Config.Name + try { + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) { + Remove-ContextSetting -Name $Name -ID $script:Config.Name + } + } catch { + Write-Error $_ + Write-Error (Get-PSCallStack | Format-Table | Out-String) + throw 'Failed to connect to GitHub.' } Write-Verbose "[$commandName] - End" diff --git a/tools/utilities/New-Function.ps1 b/tools/utilities/New-Function.ps1 new file mode 100644 index 000000000..845d0cac8 --- /dev/null +++ b/tools/utilities/New-Function.ps1 @@ -0,0 +1,53 @@ +function New-Function { + <# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .EXAMPLE + An example + + .NOTES + General notes + #> + [CmdletBinding(SupportsShouldProcess)] + param( + # This parameter is mandatory + [Parameter(Mandatory)] + [string]$Name, + + # This parameter is mandatory + [Parameter(Mandatory)] + [string]$Value + ) + + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + Write-Host 'Begin' + } + + process { + try { + Write-Host 'Process' + if ($PSCmdlet.ShouldProcess('Target', 'Operation')) { + Write-Host "Name: $Name" + Write-Host "Value: $Value" + } + } catch { + Write-Host "Error: $_" + } finally { + Write-Host 'Finally' + } + } + + end { + Write-Verbose "[$commandName] - End" + } + + clean { + Write-Host 'Clean' + } +} From 44427565d60f6533ed9780801ef2c6f63f60b576 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 18:33:19 +0100 Subject: [PATCH 097/134] test --- .../public/Auth/Context/Set-GitHubContext.ps1 | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 2fd54e61c..153a8b6af 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -148,19 +148,20 @@ function Set-GitHubContext { } } Write-Verbose "Found user with username: [$($context['Username'])]" - } catch { - Remove-Context -ID $tempContextID - Write-Error $_ - throw 'Failed to get info on the context.' - } - if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context - Remove-Context -ID $tempContextID - if ($Default) { - Set-GitHubDefaultContext -Context $newContextID + if ($PSCmdlet.ShouldProcess('Context', 'Set')) { + Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context + if ($Default) { + Set-GitHubDefaultContext -Context $newContextID + } } - } - Write-Verbose "[$commandName] - End" + Write-Verbose "[$commandName] - End" + + } catch { + Write-Error 'Failed to get info on the context.' + throw $_ + } finally { + Remove-Context -ID $tempContextID + } } From 476c2e57d42ff690d1fe344eb2caa5388d0228b3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 18:48:46 +0100 Subject: [PATCH 098/134] test throw get error --- .../public/Auth/Context/Set-GitHubContext.ps1 | 137 +++++++++--------- 1 file changed, 71 insertions(+), 66 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 153a8b6af..6c4d92665 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -89,79 +89,84 @@ function Set-GitHubContext { [switch] $Default ) - $commandName = $MyInvocation.MyCommand.Name - Write-Verbose "[$commandName] - Start" - - $tempContextName = 'tempContext' - $tempContextID = "$($script:Config.Name)/$tempContextName" - - # Set a temporary context. - $context = @{ - ApiBaseUri = $ApiBaseUri # https://api.github.com - ApiVersion = $ApiVersion # 2022-11-28 - AuthClientID = $AuthClientID # Client ID for UAT - AuthType = $AuthType # UAT / PAT / App / IAT - ClientID = $ClientID # Client ID for GitHub Apps - DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp - HostName = $HostName # github.com / msx.ghe.com / github.local - NodeID = $NodeID # User ID / app ID (GraphQL Node ID) - DatabaseID = $DatabaseID # Database ID - ContextID = $tempContextName # HostName/Username or HostName/AppSlug - UserName = $UserName # User name - Owner = $Owner # Owner name - Repo = $Repo # Repo name - Scope = $Scope # 'gist read:org repo workflow' - #----------------------------------------------------------------------------------------- - TokenType = $TokenType # ghu / gho / ghp / github_pat / PEM / ghs / - Token = $Token # Access token - TokenExpirationDate = $TokenExpirationDate # 2024-01-01-00:00:00 - RefreshToken = $RefreshToken # Refresh token - RefreshTokenExpirationDate = $RefreshTokenExpirationDate # 2024-01-01-00:00:00 + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" } - $context | Remove-HashtableEntry -NullOrEmptyValues - - Set-Context -ID $tempContextID -Context $context - - # Run functions to get info on the temporary context. - try { - Write-Verbose 'Getting info on the context.' - switch -Regex ($context['AuthType']) { - 'PAT|UAT|IAT' { - $viewer = Get-GitHubViewer -Context $tempContextName - $newContextID = "$HostName/$($viewer.login)" - $context['ContextID'] = $newContextID - $context['Username'] = $viewer.login - $context['NodeID'] = $viewer.id - $context['DatabaseID'] = ($viewer.databaseId).ToString() - } - 'App' { - $app = Get-GitHubApp -Context $tempContextName - $newContextID = "$HostName/$($app.slug)" - $context['ContextID'] = $newContextID - $context['Username'] = $app.slug - $context['NodeID'] = $app.node_id - $context['DatabaseID'] = $app.id - } - default { - throw 'Failed to get info on the context. Unknown logon type.' - } + process { + $tempContextName = 'tempContext' + $tempContextID = "$($script:Config.Name)/$tempContextName" + + # Set a temporary context. + $context = @{ + ApiBaseUri = $ApiBaseUri # https://api.github.com + ApiVersion = $ApiVersion # 2022-11-28 + AuthClientID = $AuthClientID # Client ID for UAT + AuthType = $AuthType # UAT / PAT / App / IAT + ClientID = $ClientID # Client ID for GitHub Apps + DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp + HostName = $HostName # github.com / msx.ghe.com / github.local + NodeID = $NodeID # User ID / app ID (GraphQL Node ID) + DatabaseID = $DatabaseID # Database ID + ContextID = $tempContextName # HostName/Username or HostName/AppSlug + UserName = $UserName # User name + Owner = $Owner # Owner name + Repo = $Repo # Repo name + Scope = $Scope # 'gist read:org repo workflow' + #----------------------------------------------------------------------------------------- + TokenType = $TokenType # ghu / gho / ghp / github_pat / PEM / ghs / + Token = $Token # Access token + TokenExpirationDate = $TokenExpirationDate # 2024-01-01-00:00:00 + RefreshToken = $RefreshToken # Refresh token + RefreshTokenExpirationDate = $RefreshTokenExpirationDate # 2024-01-01-00:00:00 } - Write-Verbose "Found user with username: [$($context['Username'])]" - if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context - if ($Default) { - Set-GitHubDefaultContext -Context $newContextID + $context | Remove-HashtableEntry -NullOrEmptyValues + + Set-Context -ID $tempContextID -Context $context + + # Run functions to get info on the temporary context. + try { + Write-Verbose 'Getting info on the context.' + switch -Regex ($context['AuthType']) { + 'PAT|UAT|IAT' { + $viewer = Get-GitHubViewer -Context $tempContextName + $newContextID = "$HostName/$($viewer.login)" + $context['ContextID'] = $newContextID + $context['Username'] = $viewer.login + $context['NodeID'] = $viewer.id + $context['DatabaseID'] = ($viewer.databaseId).ToString() + } + 'App' { + $app = Get-GitHubApp -Context $tempContextName + $newContextID = "$HostName/$($app.slug)" + $context['ContextID'] = $newContextID + $context['Username'] = $app.slug + $context['NodeID'] = $app.node_id + $context['DatabaseID'] = $app.id + } + default { + throw 'Failed to get info on the context. Unknown logon type.' + } } + Write-Verbose "Found user with username: [$($context['Username'])]" + + if ($PSCmdlet.ShouldProcess('Context', 'Set')) { + Write-Verbose "Setting the GitHub context [$newContextID]" + Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context + if ($Default) { + Set-GitHubDefaultContext -Context $newContextID + } + } + } catch { + throw (Get-Error | Out-String) + } finally { + Remove-Context -ID $tempContextID } + } + end { Write-Verbose "[$commandName] - End" - - } catch { - Write-Error 'Failed to get info on the context.' - throw $_ - } finally { - Remove-Context -ID $tempContextID } } From 2550442001b18182a22ebed813a9694a15068d33 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 18:58:19 +0100 Subject: [PATCH 099/134] throw record --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 6c4d92665..1e42d2424 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,7 +160,13 @@ function Set-GitHubContext { } } } catch { - throw (Get-Error | Out-String) + $err = [System.Management.Automation.ErrorRecord]::new( + $_, + 'Failed to set the GitHub context.', + [System.Management.Automation.ErrorCategory]::NotSpecified, + $null + ) + throw $err } finally { Remove-Context -ID $tempContextID } From 33f456b5300a0c358737f285b4fa895ddb3f34d8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 19:32:32 +0100 Subject: [PATCH 100/134] Enhance verbose logging in loader.ps1 to include module name, version, and script path --- src/loader.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index bfd06ad6f..0e38b8889 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -1,7 +1,10 @@ $scriptFilePath = $MyInvocation.MyCommand.Path - - -Write-Verbose "[$scriptFilePath] - Initializing GitHub PowerShell module..." +$moduleName = $MyInvocation.MyCommand.Module.Name +$moduleVersion = $MyInvocation.MyCommand.Module.Version +Write-Verbose "Initializing GitHub PowerShell module..." +Write-Verbose "Name: $moduleName" +Write-Verbose "Version: $moduleVersion" +Write-Verbose "Path: $scriptFilePath" if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' From 58b8a745b244b172465e38f35be0a94edcd8834b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 19:41:43 +0100 Subject: [PATCH 101/134] Refactor verbose logging in loader.ps1 to output detailed invocation information as JSON --- src/loader.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index 0e38b8889..b460ef0e7 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -2,9 +2,7 @@ $moduleName = $MyInvocation.MyCommand.Module.Name $moduleVersion = $MyInvocation.MyCommand.Module.Version Write-Verbose "Initializing GitHub PowerShell module..." -Write-Verbose "Name: $moduleName" -Write-Verbose "Version: $moduleVersion" -Write-Verbose "Path: $scriptFilePath" +Write-Verbose ($MyInvocation | ConvertTo-Json -Depth 5 | Out-String) if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' From a2717b5e7ba1eea7f376426b130a184ba6f1472e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 19:59:57 +0100 Subject: [PATCH 102/134] Fix --- src/loader.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/loader.ps1 b/src/loader.ps1 index b460ef0e7..30ee41f10 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -1,8 +1,6 @@ $scriptFilePath = $MyInvocation.MyCommand.Path -$moduleName = $MyInvocation.MyCommand.Module.Name -$moduleVersion = $MyInvocation.MyCommand.Module.Version Write-Verbose "Initializing GitHub PowerShell module..." -Write-Verbose ($MyInvocation | ConvertTo-Json -Depth 5 | Out-String) +Write-Verbose "Path: $scriptFilePath" if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' From 6f2631e467813e6e353d268de16c0ac7482cd007 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:00:41 +0100 Subject: [PATCH 103/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 1e42d2424..e7ffee314 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,13 +160,7 @@ function Set-GitHubContext { } } } catch { - $err = [System.Management.Automation.ErrorRecord]::new( - $_, - 'Failed to set the GitHub context.', - [System.Management.Automation.ErrorCategory]::NotSpecified, - $null - ) - throw $err + throw $_ } finally { Remove-Context -ID $tempContextID } From 7e3b796929688ab35ebcad8728eff2c0274f49be Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:12:11 +0100 Subject: [PATCH 104/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index e7ffee314..df42c5a1e 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,7 +160,7 @@ function Set-GitHubContext { } } } catch { - throw $_ + throw ($_ | ConvertTo-Json -Depth 3 | Out-String) } finally { Remove-Context -ID $tempContextID } From 027f298f1fe96681ce85b93ffab56448a4923c44 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:23:07 +0100 Subject: [PATCH 105/134] Simplify error handling in Set-GitHubContext by removing JSON conversion from thrown exceptions --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index df42c5a1e..ef417bf93 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,7 +160,7 @@ function Set-GitHubContext { } } } catch { - throw ($_ | ConvertTo-Json -Depth 3 | Out-String) + throw ($_ | Out-String) } finally { Remove-Context -ID $tempContextID } From 4892855b6f3f07c44a856e13ef9f530cb91cc217 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:25:37 +0100 Subject: [PATCH 106/134] Improve error handling in Set-GitHubContext by using Get-Error for more informative exception messages --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index ef417bf93..1f1023a74 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,7 +160,8 @@ function Set-GitHubContext { } } } catch { - throw ($_ | Out-String) + $err = Get-Error + throw ($err | Out-String) } finally { Remove-Context -ID $tempContextID } From 9c92524023a72b2c401bbb8b97973761f8b150fd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:35:35 +0100 Subject: [PATCH 107/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 1f1023a74..4b5039fee 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -161,7 +161,7 @@ function Set-GitHubContext { } } catch { $err = Get-Error - throw ($err | Out-String) + throw ($err | Out-String -Stream) } finally { Remove-Context -ID $tempContextID } From efdbe6012d38e38d52e674f900dfb307adffbc06 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:45:36 +0100 Subject: [PATCH 108/134] Test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 4b5039fee..46f7b1304 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -161,7 +161,7 @@ function Set-GitHubContext { } } catch { $err = Get-Error - throw ($err | Out-String -Stream) + throw ($err | Out-String -NoNewline) } finally { Remove-Context -ID $tempContextID } From 6dc82ac52bcfe1ca3d595712e5d86e73a120d06f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:46:17 +0100 Subject: [PATCH 109/134] Enhance error reporting in Set-GitHubContext by adding verbose output for exceptions --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 46f7b1304..9d8737e8f 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -161,6 +161,7 @@ function Set-GitHubContext { } } catch { $err = Get-Error + Write-Verbose ($err | Out-String) throw ($err | Out-String -NoNewline) } finally { Remove-Context -ID $tempContextID From 1db140ea2e1e2584f095a142d51274b752af2dec Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 20:54:57 +0100 Subject: [PATCH 110/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 9d8737e8f..cb8e3db66 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,9 +160,8 @@ function Set-GitHubContext { } } } catch { - $err = Get-Error - Write-Verbose ($err | Out-String) - throw ($err | Out-String -NoNewline) + Write-Verbose (Get-Error | Out-String) + throw $_ } finally { Remove-Context -ID $tempContextID } From 30ea3f9d6e4c6d415133bc52e9edfcd3c967755c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 21:05:42 +0100 Subject: [PATCH 111/134] run tests --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 1 - tests/GitHub.Tests.ps1 | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index cb8e3db66..e7ffee314 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -160,7 +160,6 @@ function Set-GitHubContext { } } } catch { - Write-Verbose (Get-Error | Out-String) throw $_ } finally { Remove-Context -ID $tempContextID diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 7b2d42284..c96d0d895 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -6,8 +6,8 @@ } It 'Can connect and disconnect - a second time' { - { Connect-GitHubAccount } | Should -Not -Throw - { Connect-GitHubAccount } | Should -Not -Throw + { Connect-GitHubAccount -Debug } | Should -Not -Throw + { Connect-GitHubAccount -Debug } | Should -Not -Throw Write-Verbose (Get-GitHubContext | Out-String) -Verbose { Disconnect-GitHubAccount } | Should -Not -Throw } From 11bb94d8c9a7d1e201540ad14a892c3ac375394c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 21:17:50 +0100 Subject: [PATCH 112/134] test --- tests/GitHub.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index c96d0d895..f3693ffd5 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -6,10 +6,12 @@ } It 'Can connect and disconnect - a second time' { + $DebugPreference = 'Continue' { Connect-GitHubAccount -Debug } | Should -Not -Throw { Connect-GitHubAccount -Debug } | Should -Not -Throw Write-Verbose (Get-GitHubContext | Out-String) -Verbose { Disconnect-GitHubAccount } | Should -Not -Throw + $DebugPreference = 'SilentlyContinue' } It 'Can connect multiple sessions, GITHUB_TOKEN + classic PAT token' { From fa87025981e205e1292dead3dfc99de5877e8c45 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 21:30:02 +0100 Subject: [PATCH 113/134] Refactor GitHub connection tests to remove debug preference and add verbose output for context and config --- tests/GitHub.Tests.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index f3693ffd5..32ee8fa31 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -6,12 +6,13 @@ } It 'Can connect and disconnect - a second time' { - $DebugPreference = 'Continue' - { Connect-GitHubAccount -Debug } | Should -Not -Throw - { Connect-GitHubAccount -Debug } | Should -Not -Throw + { Connect-GitHubAccount } | Should -Not -Throw + Write-Verbose (Get-GitHubContext | Out-String) -Verbose + Write-Verbose (Get-GitHubConfig | Out-String) -Verbose + { Connect-GitHubAccount } | Should -Not -Throw Write-Verbose (Get-GitHubContext | Out-String) -Verbose + Write-Verbose (Get-GitHubConfig | Out-String) -Verbose { Disconnect-GitHubAccount } | Should -Not -Throw - $DebugPreference = 'SilentlyContinue' } It 'Can connect multiple sessions, GITHUB_TOKEN + classic PAT token' { From 8a504fdb074a6018ce56f5aabe3b46d279b0557d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 22:15:43 +0100 Subject: [PATCH 114/134] Update required module version to 3.0.4 in GitHub context functions --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Remove-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index fef9763a0..928c43cfa 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index f60d7d6dd..a16007138 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } filter Remove-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index e7ffee314..0b9b80c20 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 14bf4bbf7..1aa40fc04 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 6da1c951e..68c11cfe5 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index a4a17882e..270ea5fc9 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 92de303db..161c4e2ef 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 68d37359a..74b96673e 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.3' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } function Set-GitHubConfig { <# From b1c90d2e4df6efd3b48a55b1283aa5c3828de8da Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 22:25:57 +0100 Subject: [PATCH 115/134] Remove if the context exists --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 0b9b80c20..40ea9650b 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -154,6 +154,11 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Write-Verbose "Setting the GitHub context [$newContextID]" + Get-GitHubContext -ListAvailable | ForEach-Object { + if ($_.ContextID -eq $newContextID) { + Remove-Context -ID $newContextID + } + } Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context if ($Default) { Set-GitHubDefaultContext -Context $newContextID From dc6c56e12d3fe7bcd517ea19c19a875dbdd79eb7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 22:37:20 +0100 Subject: [PATCH 116/134] test --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 40ea9650b..c2a4b4c4f 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -154,11 +154,8 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Write-Verbose "Setting the GitHub context [$newContextID]" - Get-GitHubContext -ListAvailable | ForEach-Object { - if ($_.ContextID -eq $newContextID) { - Remove-Context -ID $newContextID - } - } + Write-Verbose ($context | Format-Table | Out-String) + $context | Remove-HashtableEntry -NullOrEmptyValues Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context if ($Default) { Set-GitHubDefaultContext -Context $newContextID From bca62de8886662c548dfad3f0259a5b99af23f80 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 22:47:53 +0100 Subject: [PATCH 117/134] Fix --- .../public/Auth/Context/Set-GitHubContext.ps1 | 2 +- tools/utilities/New-Function.ps1 | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index c2a4b4c4f..30cd895f4 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -156,7 +156,7 @@ function Set-GitHubContext { Write-Verbose "Setting the GitHub context [$newContextID]" Write-Verbose ($context | Format-Table | Out-String) $context | Remove-HashtableEntry -NullOrEmptyValues - Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context + Set-Context -ID "$($script:Config.Name)/$newContextID" -Context [PSCustomObject]$context if ($Default) { Set-GitHubDefaultContext -Context $newContextID } diff --git a/tools/utilities/New-Function.ps1 b/tools/utilities/New-Function.ps1 index 845d0cac8..f58eafa12 100644 --- a/tools/utilities/New-Function.ps1 +++ b/tools/utilities/New-Function.ps1 @@ -26,20 +26,20 @@ begin { $commandName = $MyInvocation.MyCommand.Name Write-Verbose "[$commandName] - Start" - Write-Host 'Begin' + Write-Verbose 'Begin' } process { try { - Write-Host 'Process' + Write-Verbose 'Process' if ($PSCmdlet.ShouldProcess('Target', 'Operation')) { - Write-Host "Name: $Name" - Write-Host "Value: $Value" + Write-Verbose "Name: $Name" + Write-Verbose "Value: $Value" } } catch { - Write-Host "Error: $_" + Write-Verbose "Error: $_" } finally { - Write-Host 'Finally' + Write-Verbose 'Finally' } } @@ -48,6 +48,6 @@ } clean { - Write-Host 'Clean' + Write-Verbose 'Clean' } } From 9bb623b0d3a29ce5715d3053b067d26ee014aca3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 23:09:47 +0100 Subject: [PATCH 118/134] Simplify context setting in Set-GitHubContext function and improve error handling --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 30cd895f4..53c4a7942 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -154,15 +154,13 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Write-Verbose "Setting the GitHub context [$newContextID]" - Write-Verbose ($context | Format-Table | Out-String) - $context | Remove-HashtableEntry -NullOrEmptyValues - Set-Context -ID "$($script:Config.Name)/$newContextID" -Context [PSCustomObject]$context + Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context if ($Default) { Set-GitHubDefaultContext -Context $newContextID } } } catch { - throw $_ + throw ($_ -join ';') } finally { Remove-Context -ID $tempContextID } From c079d43df28d9e038b8b8dc446c3e47bed5ae278 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 23:30:39 +0100 Subject: [PATCH 119/134] Refactor GitHub connection tests to remove unnecessary script blocks --- tests/GitHub.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 32ee8fa31..793d9be12 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -6,10 +6,10 @@ } It 'Can connect and disconnect - a second time' { - { Connect-GitHubAccount } | Should -Not -Throw + Connect-GitHubAccount Write-Verbose (Get-GitHubContext | Out-String) -Verbose Write-Verbose (Get-GitHubConfig | Out-String) -Verbose - { Connect-GitHubAccount } | Should -Not -Throw + Connect-GitHubAccount Write-Verbose (Get-GitHubContext | Out-String) -Verbose Write-Verbose (Get-GitHubConfig | Out-String) -Verbose { Disconnect-GitHubAccount } | Should -Not -Throw From 3bccd0c7ccd422520c0b78fab6b6c3e0c7a0479a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 23 Nov 2024 23:48:52 +0100 Subject: [PATCH 120/134] Add verbose logging for secret information in Set-GitHubContext function --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 53c4a7942..64e7a543b 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -154,6 +154,8 @@ function Set-GitHubContext { if ($PSCmdlet.ShouldProcess('Context', 'Set')) { Write-Verbose "Setting the GitHub context [$newContextID]" + Write-Verbose (Get-SecretInfo | Out-String) + Write-Verbose (Get-SecretInfo | Get-Secret -AsPlainText | Out-String) Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context if ($Default) { Set-GitHubDefaultContext -Context $newContextID From 82c7ea881e81fb5ccd85c4f0b88c697873bba7a9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 00:07:16 +0100 Subject: [PATCH 121/134] test double pat --- tests/GitHub.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 793d9be12..f52a7b19a 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -16,6 +16,7 @@ } It 'Can connect multiple sessions, GITHUB_TOKEN + classic PAT token' { + { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw { Connect-GitHubAccount } | Should -Not -Throw (Get-GitHubContext).Count | Should -Be 2 From 2bec0038449663023e6fdae4f62b7a4621408393 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 00:21:44 +0100 Subject: [PATCH 122/134] Update GitHub context tests to use Get-GitHubContext with ListAvailable and add support for GitHub App authentication --- tests/GitHub.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index f52a7b19a..e18deb186 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -19,7 +19,7 @@ { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw { Connect-GitHubAccount } | Should -Not -Throw - (Get-GitHubContext).Count | Should -Be 2 + (Get-GitHubContext -ListAvailable).Count | Should -Be 2 Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions[bot]' Write-Verbose (Get-GitHubContext | Out-String) -Verbose } @@ -31,6 +31,7 @@ } It 'Can be called with a GitHub App' { + { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw Write-Verbose (Get-GitHubContext | Out-String) -Verbose } From 6577d63534787b95d286c362a97ac324b4fea4db Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 11:40:57 +0100 Subject: [PATCH 123/134] Refactor Get-GitHubContext to streamline context retrieval and enhance argument completion --- .../public/Auth/Context/Get-GitHubContext.ps1 | 9 ++++----- .../public/Auth/Context/Remove-GitHubContext.ps1 | 11 +++++++++++ .../public/Auth/Context/Set-GitHubContext.ps1 | 1 + .../public/Auth/Context/Set-GitHubDefaultContext.ps1 | 7 ++++--- .../Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 10 ++++++++++ .../Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 10 ++++++++++ .../public/Auth/Disconnect-GitHubAccount.ps1 | 9 +++++---- 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 928c43cfa..e7676525d 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -66,9 +66,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - - Get-Context -ID "$wordToComplete*" -Verbose:$false | Where-Object { $_.ContextID -ne $defaultContext } | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) - } + Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } } diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index a16007138..d00d08166 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -40,3 +40,14 @@ filter Remove-GitHubContext { Write-Verbose "[$commandName] - End" } + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } +} + diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 64e7a543b..b4183154c 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -156,6 +156,7 @@ function Set-GitHubContext { Write-Verbose "Setting the GitHub context [$newContextID]" Write-Verbose (Get-SecretInfo | Out-String) Write-Verbose (Get-SecretInfo | Get-Secret -AsPlainText | Out-String) + Remove-Context -ID $tempContextID Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context if ($Default) { Set-GitHubDefaultContext -Context $newContextID diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 index 67eaae4b4..6916fdbac 100644 --- a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 @@ -33,7 +33,8 @@ Register-ArgumentCompleter -CommandName Set-GitHubDefaultContext -ParameterName $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - Get-Context -ID "$wordToComplete*" -Verbose:$false | Where-Object { $_.ContextID -ne $defaultContext } | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) - } + Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" -and $_.ContextID -ne $defaultContext } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } } diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 1aa40fc04..d4bda7c38 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -38,3 +38,13 @@ function Get-GitHubContextSetting { Write-Verbose "[$commandName] - End" } + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } +} diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 68c11cfe5..57ae89804 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -109,3 +109,13 @@ function Set-GitHubContextSetting { Write-Verbose "[$commandName] - End" } + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } +} diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 4b489b865..07a95dcde 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -52,11 +52,12 @@ Write-Verbose "[$commandName] - End" } -Register-ArgumentCompleter -CommandName Disconnect-GitHubAccount -ParameterName Context -ScriptBlock { +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - Get-Context -ID "$wordToComplete*" -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) - } + Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + } } From 4bd249f870185b03a0c4dc4ae6528283650cc688 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 15:44:06 +0100 Subject: [PATCH 124/134] Update module requirement for GitHub context functions to version 3.1.0 --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Remove-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index e7676525d..91eaa4128 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index d00d08166..a4e70e600 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } filter Remove-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index b4183154c..2ea0fc25b 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index d4bda7c38..70ba174e8 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 57ae89804..6eaa7cb0c 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 270ea5fc9..d179d1d4b 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 161c4e2ef..6946208ef 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 74b96673e..99bf6b449 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } function Set-GitHubConfig { <# From bee95b9c96c538e973e60c84f47383b415cfbe47 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 16:07:13 +0100 Subject: [PATCH 125/134] Let it rip... --- src/classes/public/GitHubContext.ps1 | 6 +++--- src/formats/GitHubContext.Format.ps1xml | 2 +- .../public/Auth/Context/Get-GitHubContext.ps1 | 4 ++-- .../public/Auth/Context/Remove-GitHubContext.ps1 | 4 ++-- .../public/Auth/Context/Set-GitHubContext.ps1 | 14 ++++---------- .../Auth/Context/Set-GitHubDefaultContext.ps1 | 4 ++-- .../ContextSetting/Get-GitHubContextSetting.ps1 | 10 +++++----- .../ContextSetting/Set-GitHubContextSetting.ps1 | 4 ++-- .../public/Auth/Disconnect-GitHubAccount.ps1 | 4 ++-- src/loader.ps1 | 2 +- tests/GitHub.Tests.ps1 | 2 +- 11 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 index 1a2b50c32..7bf882711 100644 --- a/src/classes/public/GitHubContext.ps1 +++ b/src/classes/public/GitHubContext.ps1 @@ -34,7 +34,7 @@ # The context ID. # HostName/Username or HostName/AppSlug - [string] $ContextID + [string] $ID # The user name. [string] $UserName @@ -67,8 +67,8 @@ # 2024-01-01-00:00:00 [datetime] $RefreshTokenExpirationDate - GitHubContext([string]$ContextID) { - $this.ContextID = $ContextID + GitHubContext([string]$ID) { + $this.ID = $ID } GitHubContext([hashtable]$Properties) { diff --git a/src/formats/GitHubContext.Format.ps1xml b/src/formats/GitHubContext.Format.ps1xml index fae31a1c3..14fef32a3 100644 --- a/src/formats/GitHubContext.Format.ps1xml +++ b/src/formats/GitHubContext.Format.ps1xml @@ -114,7 +114,7 @@ DatabaseID - ContextID + ID Owner diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 91eaa4128..c4ed83f5d 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -66,8 +66,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) } } diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index a4e70e600..d874e4db3 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -45,9 +45,9 @@ Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) } } diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 2ea0fc25b..99557af85 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -109,7 +109,7 @@ function Set-GitHubContext { HostName = $HostName # github.com / msx.ghe.com / github.local NodeID = $NodeID # User ID / app ID (GraphQL Node ID) DatabaseID = $DatabaseID # Database ID - ContextID = $tempContextName # HostName/Username or HostName/AppSlug + ID = $tempContextID # HostName/Username or HostName/AppSlug UserName = $UserName # User name Owner = $Owner # Owner name Repo = $Repo # Repo name @@ -132,16 +132,14 @@ function Set-GitHubContext { switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName - $newContextID = "$HostName/$($viewer.login)" - $context['ContextID'] = $newContextID + $newContextID = "$($script:Config.Name)/$HostName/$($viewer.login)" $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id $context['DatabaseID'] = ($viewer.databaseId).ToString() } 'App' { $app = Get-GitHubApp -Context $tempContextName - $newContextID = "$HostName/$($app.slug)" - $context['ContextID'] = $newContextID + $newContextID = "$($script:Config.Name)/$HostName/$($app.slug)" $context['Username'] = $app.slug $context['NodeID'] = $app.node_id $context['DatabaseID'] = $app.id @@ -153,11 +151,7 @@ function Set-GitHubContext { Write-Verbose "Found user with username: [$($context['Username'])]" if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Write-Verbose "Setting the GitHub context [$newContextID]" - Write-Verbose (Get-SecretInfo | Out-String) - Write-Verbose (Get-SecretInfo | Get-Secret -AsPlainText | Out-String) - Remove-Context -ID $tempContextID - Set-Context -ID "$($script:Config.Name)/$newContextID" -Context $context + Rename-Context -ID $tempContextID -NewID $newContextID if ($Default) { Set-GitHubDefaultContext -Context $newContextID } diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 index 6916fdbac..00f5a98d7 100644 --- a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 @@ -33,8 +33,8 @@ Register-ArgumentCompleter -CommandName Set-GitHubDefaultContext -ParameterName $defaultContext = Get-GitHubConfig -Name 'DefaultContext' - Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" -and $_.ContextID -ne $defaultContext } -Verbose:$false | + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" -and $_.ID -ne $defaultContext } -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) } } diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index 70ba174e8..eb0850015 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -28,13 +28,13 @@ function Get-GitHubContextSetting { $commandName = $MyInvocation.MyCommand.Name Write-Verbose "[$commandName] - Start" - $contextID = "$($script:Config.Name)/$Context" + $ID = "$($script:Config.Name)/$Context" if (-not $Name) { - Get-Context -ID $contextID + Get-Context -ID $ID } - Get-ContextSetting -Name $Name -ID $contextID + Get-ContextSetting -Name $Name -ID $ID Write-Verbose "[$commandName] - End" } @@ -43,8 +43,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) } } diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 6eaa7cb0c..507679045 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -114,8 +114,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) } } diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 07a95dcde..e6d5cd254 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -56,8 +56,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - Get-GitHubContext -ListAvailable | Where-Object { $_.ContextID -like "$wordToComplete*" } -Verbose:$false | + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_.ContextID, $_.ContextID, 'ParameterValue', $_.ContextID) + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) } } diff --git a/src/loader.ps1 b/src/loader.ps1 index 30ee41f10..d3d47b9ee 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -13,5 +13,5 @@ if ($env:GITHUB_ACTIONS -eq 'true') { $context = (Get-Context -ID $script:Config.Name) if (-not $context) { Write-Verbose 'No context found, creating a new context...' - Set-Context -ID $script:Config.Name -Context @{ ContextID = 'GitHub' } + Set-Context -ID $script:Config.Name -Context @{ Name = 'GitHub' } } diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index e18deb186..c8c093bc4 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -62,7 +62,7 @@ $config = Get-GitHubConfig Write-Verbose ($config | Format-Table | Out-String) -Verbose { Get-GitHubConfig } | Should -Not -Throw - $config.ContextID | Should -Be 'GitHub' + $config.ID | Should -Be 'GitHub' } } } From 3d9671ed328fa946771768f82836f703c123ae20 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 17:19:15 +0100 Subject: [PATCH 126/134] Update module requirement for Context to version 3.1.1 and enhance context ID documentation --- src/classes/public/GitHubContext.ps1 | 1 + src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Remove-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 7 +++---- .../Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 index 7bf882711..550923125 100644 --- a/src/classes/public/GitHubContext.ps1 +++ b/src/classes/public/GitHubContext.ps1 @@ -34,6 +34,7 @@ # The context ID. # HostName/Username or HostName/AppSlug + # Context:PSModule.Github/github.com/Octocat [string] $ID # The user name. diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index c4ed83f5d..3e05cdc20 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index d874e4db3..c72a9814b 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } filter Remove-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 99557af85..ff6b0bb99 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Set-GitHubContext { <# @@ -95,7 +95,7 @@ function Set-GitHubContext { } process { - $tempContextName = 'tempContext' + $tempContextName = "$HostName/tempContext" $tempContextID = "$($script:Config.Name)/$tempContextName" # Set a temporary context. @@ -109,7 +109,6 @@ function Set-GitHubContext { HostName = $HostName # github.com / msx.ghe.com / github.local NodeID = $NodeID # User ID / app ID (GraphQL Node ID) DatabaseID = $DatabaseID # Database ID - ID = $tempContextID # HostName/Username or HostName/AppSlug UserName = $UserName # User name Owner = $Owner # Owner name Repo = $Repo # Repo name @@ -151,7 +150,7 @@ function Set-GitHubContext { Write-Verbose "Found user with username: [$($context['Username'])]" if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Rename-Context -ID $tempContextID -NewID $newContextID + Rename-Context -ID $tempContextID -NewID $newContextID -Force if ($Default) { Set-GitHubDefaultContext -Context $newContextID } diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index eb0850015..d77494e35 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 507679045..2fef965ea 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index d179d1d4b..de03701a5 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index 6946208ef..d6e2325e5 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 99bf6b449..96a0f0b7b 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.0' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } function Set-GitHubConfig { <# From 865ae0bef1bb928551f1bd4e66b375f0477bf59c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 17:35:43 +0100 Subject: [PATCH 127/134] Refactor Get-GitHubContext to improve default context retrieval and error handling --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 3e05cdc20..3a5f37b6b 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -47,11 +47,10 @@ function Get-GitHubContext { Write-Verbose "Getting available contexts for [$ID]" } else { $config = Get-GitHubConfig - $Context = $config.DefaultContext - if ([string]::IsNullOrEmpty($Context)) { + $ID = $config.DefaultContext + if ([string]::IsNullOrEmpty($ID )) { throw "No default GitHub context found. Please run 'Set-GitHubDefaultContext' or 'Connect-GitHub' to configure a GitHub context." } - $ID = "$($script:Config.Name)/$Context" Write-Verbose "Getting the default context: [$ID]" } From 1b456e0a8bb87ffca2f303be3e6004354e49f6e2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 17:47:08 +0100 Subject: [PATCH 128/134] Get context --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 0b89c1372..040919f85 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -299,6 +299,7 @@ } Set-GitHubContext @context -Default $context = Get-GitHubContext + Write-Verbose ($context | Format-List | Out-String) if (-not $Silent) { $name = $context.Username Write-Host '✓ ' -ForegroundColor Green -NoNewline From b42277a216f0f5e9e33576472c71cdc834bb32ea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 17:57:27 +0100 Subject: [PATCH 129/134] Replace Rename-Context with Set-Context for improved context management in Set-GitHubContext --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index ff6b0bb99..8b9bc2149 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -150,7 +150,7 @@ function Set-GitHubContext { Write-Verbose "Found user with username: [$($context['Username'])]" if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Rename-Context -ID $tempContextID -NewID $newContextID -Force + Set-Context -ID $newContextID -Context $context if ($Default) { Set-GitHubDefaultContext -Context $newContextID } From 67cc8f1d84713104bee8f7d5e8fc6039a9d3e688 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 21:54:31 +0100 Subject: [PATCH 130/134] Update Context module requirement to version 4.0.0 across all relevant scripts --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Remove-GitHubContext.ps1 | 2 +- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 2 +- .../public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 | 2 +- .../public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 | 2 +- src/functions/public/Config/Get-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Remove-GitHubConfig.ps1 | 2 +- src/functions/public/Config/Set-GitHubConfig.ps1 | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 3a5f37b6b..acededb07 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 index c72a9814b..ac4b0381e 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } filter Remove-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 8b9bc2149..293278231 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 index d77494e35..d6ef02820 100644 --- a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Get-GitHubContextSetting { <# diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 index 2fef965ea..d29c689ea 100644 --- a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Set-GitHubContextSetting { <# diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index de03701a5..524579deb 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index d6e2325e5..0389ce1d9 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 96a0f0b7b..2be9e9a55 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '3.1.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Set-GitHubConfig { <# From 256b6f609a237254e9e3bb26181013f4629e0428 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 22:11:32 +0100 Subject: [PATCH 131/134] Fix default context name --- src/functions/public/Auth/Context/Set-GitHubContext.ps1 | 8 ++++---- tests/GitHub.Tests.ps1 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 293278231..d002eca31 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -131,14 +131,14 @@ function Set-GitHubContext { switch -Regex ($context['AuthType']) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $tempContextName - $newContextID = "$($script:Config.Name)/$HostName/$($viewer.login)" + $contextName = "$HostName/$($viewer.login)" $context['Username'] = $viewer.login $context['NodeID'] = $viewer.id $context['DatabaseID'] = ($viewer.databaseId).ToString() } 'App' { $app = Get-GitHubApp -Context $tempContextName - $newContextID = "$($script:Config.Name)/$HostName/$($app.slug)" + $contextName = "$HostName/$($app.slug)" $context['Username'] = $app.slug $context['NodeID'] = $app.node_id $context['DatabaseID'] = $app.id @@ -150,9 +150,9 @@ function Set-GitHubContext { Write-Verbose "Found user with username: [$($context['Username'])]" if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Set-Context -ID $newContextID -Context $context + Set-Context -ID "$($script:Config.Name)/$contextName" -Context $context if ($Default) { - Set-GitHubDefaultContext -Context $newContextID + Set-GitHubDefaultContext -Context $contextName } } } catch { diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index c8c093bc4..856560f5c 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -18,7 +18,7 @@ It 'Can connect multiple sessions, GITHUB_TOKEN + classic PAT token' { { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw - { Connect-GitHubAccount } | Should -Not -Throw + { Connect-GitHubAccount } | Should -Not -Throw # Logs on with GitHub Actions' token (Get-GitHubContext -ListAvailable).Count | Should -Be 2 Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions[bot]' Write-Verbose (Get-GitHubContext | Out-String) -Verbose From 7e5ca69b1fdfb7bf24f53da8855e4c3215fb50bc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 22:21:09 +0100 Subject: [PATCH 132/134] Improve default context retrieval in Get-GitHubContext function --- src/functions/public/Auth/Context/Get-GitHubContext.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index acededb07..8feed3405 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -47,8 +47,9 @@ function Get-GitHubContext { Write-Verbose "Getting available contexts for [$ID]" } else { $config = Get-GitHubConfig - $ID = $config.DefaultContext - if ([string]::IsNullOrEmpty($ID )) { + $defaultContext = $config.DefaultContext + $ID = "$($script:Config.Name)/$defaultContext" + if ([string]::IsNullOrEmpty($ID)) { throw "No default GitHub context found. Please run 'Set-GitHubDefaultContext' or 'Connect-GitHub' to configure a GitHub context." } Write-Verbose "Getting the default context: [$ID]" From 7f9ab58fb604bd0a59ffa4db2252933c2b4d6fde Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 22:36:31 +0100 Subject: [PATCH 133/134] Update test to use Get-GitHubContext with -ListAvailable for accurate context count --- tests/GitHub.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 856560f5c..8b7c7c11c 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -26,8 +26,8 @@ It 'Can reconfigure an existing context to be fine-grained PAT token' { { Connect-GitHubAccount -Token $env:TEST_FG_PAT } | Should -Not -Throw - (Get-GitHubContext).Count | Should -Be 2 - Write-Verbose (Get-GitHubContext | Out-String) -Verbose + (Get-GitHubContext -ListAvailable).Count | Should -Be 2 + Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose } It 'Can be called with a GitHub App' { From 1e60f4013ed521b7ef05027c843fe291fedeb3d7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 24 Nov 2024 22:38:48 +0100 Subject: [PATCH 134/134] Update test to reflect correct GitHub config ID --- tests/GitHub.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 8b7c7c11c..067d52ee3 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -62,7 +62,7 @@ $config = Get-GitHubConfig Write-Verbose ($config | Format-Table | Out-String) -Verbose { Get-GitHubConfig } | Should -Not -Throw - $config.ID | Should -Be 'GitHub' + $config.ID | Should -Be 'PSModule.GitHub' } } }