Skip to content

Commit

Permalink
Let it rip...
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Nov 24, 2024
1 parent 4bd249f commit bee95b9
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/classes/public/GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

# The context ID.
# HostName/Username or HostName/AppSlug
[string] $ContextID
[string] $ID

# The user name.
[string] $UserName
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/formats/GitHubContext.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<PropertyName>DatabaseID</PropertyName>
</ListItem>
<ListItem>
<PropertyName>ContextID</PropertyName>
<PropertyName>ID</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Owner</PropertyName>
Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Auth/Context/Get-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions src/functions/public/Auth/Context/Remove-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

14 changes: 4 additions & 10 deletions src/functions/public/Auth/Context/Set-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions src/functions/public/Auth/Disconnect-GitHubAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/loader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
}
2 changes: 1 addition & 1 deletion tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
Expand Down

0 comments on commit bee95b9

Please sign in to comment.