Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
50a7e07
🩹 [Patch]: Update module requirements to version 8.0.0 across multipl…
MariusStorhaug Jun 7, 2025
cbe78c6
🩹 [Patch]: Update context handling to include Vault parameter in mult…
MariusStorhaug Jun 7, 2025
157ab89
🩹 [Patch]: Refactor context handling in `Initialize-GitHubConfig` and…
MariusStorhaug Jun 7, 2025
03e2c38
🩹 [Patch]: Update `Remove-GitHubContext` to include Vault parameter i…
MariusStorhaug Jun 7, 2025
7d892dd
🩹 [Patch]: Add separator output in AfterAll blocks for better test re…
MariusStorhaug Jun 7, 2025
7950518
🩹 [Patch]: Simplify context handling in Remove-GitHubContext, Get-Git…
MariusStorhaug Jun 7, 2025
40b42fe
🩹 [Patch]: Update verbose messages in Get-GitHubContext for clarity a…
MariusStorhaug Jun 8, 2025
e4a4c0c
🩹 [Patch]: Exclude ID property from output in Get-GitHubConfig when n…
MariusStorhaug Jun 8, 2025
6b2e6a3
🩹 [Patch]: Update verbose output in Connect-GitHubAccount to use -Str…
MariusStorhaug Jun 8, 2025
75bfe71
🩹 [Patch]: Fix typo in Connect-GitHubAccount to use -Stream for outpu…
MariusStorhaug Jun 8, 2025
296bb46
🩹 [Patch]: Update context handling in Update-GitHubUserAccessToken an…
MariusStorhaug Jun 8, 2025
42049b8
🩹 [Patch]: Update required module version from 8.0.0 to 8.0.1 in mult…
MariusStorhaug Jun 8, 2025
0a327a2
🩹 [Patch]: Enhance debugging output in Connect-GitHubAccount and Conn…
MariusStorhaug Jun 8, 2025
4c8c3e3
🩹 [Patch]: Refactor context retrieval in Get-GitHubContext for improv…
MariusStorhaug Jun 8, 2025
dbf7954
🩹 [Patch]: Update required module version from 8.0.1 to 8.0.2 in mult…
MariusStorhaug Jun 8, 2025
62f9a12
🩹 [Patch]: Update required module version from 8.0.1 to 8.0.2 in Conn…
MariusStorhaug Jun 8, 2025
aeaabae
🩹 [Patch]: Replace Set-GitHubDefaultContext with Switch-GitHubContext…
MariusStorhaug Jun 8, 2025
c101d81
🩹 [Patch]: Filter out default context from Get-Context results in Get…
MariusStorhaug Jun 8, 2025
4b8fb9d
🩹 [Patch]: Add -Debug and -Verbose parameters to Get-GitHubRateLimit …
MariusStorhaug Jun 8, 2025
2388dc0
Fixes
MariusStorhaug Jun 8, 2025
939891b
🩹 [Patch]: Standardize formatting of the Context parameter assignment…
MariusStorhaug Jun 8, 2025
3afd933
Removing -Anonymous
MariusStorhaug Jun 8, 2025
490357f
Fix whitespace issues in PowerShell scripts by removing invisible cha…
MariusStorhaug Jun 8, 2025
aa2cd52
🩹 [Patch]: Replace Write-Verbose with Write-Host for context messages…
MariusStorhaug Jun 8, 2025
f049d75
🩹 [Patch]: Add Write-Host for context output in Get-GitHubContext for…
MariusStorhaug Jun 8, 2025
0ed1a87
🩹 [Patch]: Replace Write-Debug with Write-Host for context output in …
MariusStorhaug Jun 8, 2025
364beff
🩹 [Patch]: Replace Write-Debug with Write-Host for context messages i…
MariusStorhaug Jun 8, 2025
6ff47fa
🩹 [Patch]: Replace Write-Host with Write-Debug for context output in …
MariusStorhaug Jun 8, 2025
ad6151d
🩹 [Patch]: Remove unused Anonymous parameter from Get-GitHubLicenseBy…
MariusStorhaug Jun 9, 2025
6234c27
🩹 [Patch]: Remove unused Anonymous parameter from Get-GitHubGitignore…
MariusStorhaug Jun 9, 2025
686ae4d
🩹 [Patch]: Remove -Debug and -Verbose parameters from Invoke-GitHubAP…
MariusStorhaug Jun 9, 2025
aa3dd3e
🩹 [Patch]: Add check for 'Anonymous' AuthType in Assert-GitHubContext…
MariusStorhaug Jun 9, 2025
09c5188
🩹 [Patch]: Update Resolve-GitHubContext to allow bypassing context va…
MariusStorhaug Jun 9, 2025
a5e2fef
🩹 [Patch]: Fix condition in Resolve-GitHubContext to correctly check …
MariusStorhaug Jun 9, 2025
7ab7186
🩹 [Patch]: Add verbose logging for context and AuthType in Assert-Git…
MariusStorhaug Jun 9, 2025
a7d4005
🩹 [Patch]: Refactor context validation in Assert-GitHubContext to imp…
MariusStorhaug Jun 9, 2025
b1c0fd6
🩹 [Patch]: Enhance Resolve-GitHubContext to return a structured 'Anon…
MariusStorhaug Jun 9, 2025
7fc6c3f
🩹 [Patch]: Update GitHubConfig to use nullable types for AccessTokenG…
MariusStorhaug Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Apps/Get-WebhookDelivery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $deliveries | Where-Object { $_.Event -eq 'team' } | Format-Table -AutoSize

$Return.Response | Format-Table -AutoSize

Set-GitHubDefaultContext -Context 'msx.ghe.com/Marius-Storhaug'
Switch-GitHubContext -Context 'msx.ghe.com/Marius-Storhaug'

1..10 | ForEach-Object {
New-GitHubTeam -Organization 'my-org' -Name "Test$_"
Expand Down
11 changes: 4 additions & 7 deletions examples/Connecting.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

###
###
### CONNECTING
###

Expand Down Expand Up @@ -40,16 +38,15 @@ Get-GitHubContext -ListAvailable
Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'

# Take a name dynamically from Get-GitHubContext? Autocomplete the name
Set-GitHubDefaultContext -Context 'msx.ghe.com/MariusStorhaug'
Switch-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'

# Set a specific context as the default context using pipeline
'msx.ghe.com/MariusStorhaug' | Set-GitHubDefaultContext
'msx.ghe.com/MariusStorhaug' | Switch-GitHubContext

Get-GitHubContext -Context 'github.com/MariusStorhaug' | Set-GitHubDefaultContext
Get-GitHubContext -Context 'github.com/MariusStorhaug' | Switch-GitHubContext

# Abstraction layers on GitHubContexts
Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'
Get-Context -ID 'PSModule.GitHub/msx.ghe.com/MariusStorhaug'

###
### DISCONNECTING
Expand Down
10 changes: 5 additions & 5 deletions src/classes/public/Config/GitHubConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[string] $ID

# The access token grace period in hours.
[int] $AccessTokenGracePeriodInHours
[System.Nullable[int]] $AccessTokenGracePeriodInHours

# The default context.
[string] $DefaultContext
Expand All @@ -27,16 +27,16 @@
[string] $HttpVersion

# The default value for the 'per_page' API parameter used in 'GET' functions that support paging.
[int] $PerPage
[System.Nullable[int]] $PerPage

# The default value for retry count.
[int] $RetryCount
[System.Nullable[int]] $RetryCount

# The default value for retry interval in seconds.
[int] $RetryInterval
[System.Nullable[int]] $RetryInterval

# The tolerance time in seconds for JWT token validation.
[int] $JwtTimeTolerance
[System.Nullable[int]] $JwtTimeTolerance

# Simple parameterless constructor
GitHubConfig() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
begin {
$stackPath = Get-PSCallStackPath
Write-Debug "[$stackPath] - Start"
$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType IAT, UAT
# enterprise_organization_installations=read
}
Expand Down
29 changes: 14 additions & 15 deletions src/functions/private/Auth/Context/Assert-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,32 @@

process {
$command = (Get-PSCallStack)[1].Command
Write-Verbose "Context: $Context"
Write-Verbose "AuthType: $AuthType"

if ($Context) {
if ($Context.AuthType -in $AuthType) {
return
}
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new("The context '$($Context.Name)' does not match the required AuthTypes [$AuthType] for [$command]."),
"InvalidContextAuthType",
[System.Management.Automation.ErrorCategory]::InvalidArgument,
$Context
)
)
} else {
if (-not $Context) {
if ('Anonymous' -in $AuthType) {
return
}
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new("Please provide a valid context or log in using 'Connect-GitHub'."),
"InvalidContext",
'InvalidContext',
[System.Management.Automation.ErrorCategory]::InvalidArgument,
$Context
)
)
}

if ($Context -eq 'Anonymous' -and $AuthType -contains 'Anonymous') { return }
if ($Context.AuthType -in $AuthType) { return }
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new("The context '$($Context.Name)' does not match the required AuthTypes [$AuthType] for [$command]."),
'InvalidContextAuthType',
[System.Management.Automation.ErrorCategory]::InvalidArgument,
$Context
)
)
# TODO: Implement permission check
# if ($Context.AuthType -in 'IAT' -and $Context.Permission -notin $Permission) {
# throw "The context '$($Context.Name)' does not match the required Permission [$Permission] for [$command]."
Expand Down
9 changes: 3 additions & 6 deletions src/functions/private/Auth/Context/Remove-GitHubContext.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

filter Remove-GitHubContext {
filter Remove-GitHubContext {
<#
.SYNOPSIS
Removes a context from the context vault.
Expand Down Expand Up @@ -36,14 +34,13 @@ filter Remove-GitHubContext {
}

process {
$ID = "$($script:GitHub.Config.ID)/$Context"

if ($PSCmdlet.ShouldProcess($context.Name, 'Remove context')) {
Remove-Context -ID $ID
Remove-Context -ID $Context -Vault $script:GitHub.ContextVault
}
}

end {
Write-Debug "[$stackPath] - End"
}
}
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '8.0.2' }
25 changes: 22 additions & 3 deletions src/functions/private/Auth/Context/Resolve-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
# Can be either a string or a GitHubContext object.
[Parameter(Mandatory, ValueFromPipeline)]
[AllowNull()]
[object] $Context
[object] $Context,

# If specified, makes an anonymous request to the GitHub API without authentication.
[Parameter()]
[bool] $Anonymous
)

begin {
Expand All @@ -37,10 +41,25 @@
}

process {
Write-Verbose "Context: [$Context]"
Write-Verbose "Anonymous: [$Anonymous]"
if ($Anonymous -or $Context -eq 'Anonymous') {
Write-Verbose 'Returning Anonymous context.'
return [GitHubContext]@{
Name = 'Anonymous'
AuthType = 'Anonymous'
}
}

if ($Context -is [string]) {
$contextName = $Context
Write-Debug "Getting context: [$contextName]"
$Context = Get-GitHubContext -Context $contextName
Write-Verbose "Getting context: [$contextName]"
return Get-GitHubContext -Context $contextName
}

if ($null -eq $Context) {
Write-Verbose 'Context is null, returning default context.'
return Get-GitHubContext
}

# TODO: Implement App installation context resolution
Expand Down
9 changes: 4 additions & 5 deletions src/functions/private/Auth/Context/Set-GitHubContext.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Set-GitHubContext {
function Set-GitHubContext {
<#
.SYNOPSIS
Sets the GitHub context and stores it in the context vault.
Expand Down Expand Up @@ -143,8 +141,8 @@ function Set-GitHubContext {
$contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ }
Write-Debug '----------------------------------------------------'
if ($PSCmdlet.ShouldProcess('Context', 'Set')) {
Write-Debug "Saving context: [$($script:GitHub.Config.ID)/$($contextObj['Name'])]"
Set-Context -ID "$($script:GitHub.Config.ID)/$($contextObj['Name'])" -Context $contextObj
Write-Debug "Saving context: [$($contextObj['Name'])]"
Set-Context -ID $($contextObj['Name']) -Context $contextObj -Vault $script:GitHub.ContextVault
if ($Default) {
Switch-GitHubContext -Context $contextObj['Name']
}
Expand All @@ -170,3 +168,4 @@ function Set-GitHubContext {
Write-Debug "[$stackPath] - End"
}
}
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '8.0.2' }
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$Context.RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in)

if ($PSCmdlet.ShouldProcess('Access token', 'Update/refresh')) {
Set-Context -Context $Context -ID $Context.ID
Set-Context -Context $Context -Vault $script:GitHub.ContextVault
}

if ($PassThru) {
Expand All @@ -98,4 +98,4 @@
Write-Debug "[$stackPath] - End"
}
}
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '8.0.2' }
15 changes: 7 additions & 8 deletions src/functions/private/Config/Initialize-GitHubConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Initialize-GitHubConfig {
function Initialize-GitHubConfig {
<#
.SYNOPSIS
Initialize the GitHub module configuration.
Expand Down Expand Up @@ -34,7 +32,7 @@ function Initialize-GitHubConfig {
Write-Debug "Force: [$Force]"
if ($Force) {
Write-Debug 'Forcing initialization of GitHubConfig.'
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru
$context = Set-Context -Context $script:GitHub.DefaultConfig -Vault $script:GitHub.ContextVault -PassThru
$script:GitHub.Config = [GitHubConfig]$context
return
}
Expand All @@ -46,11 +44,11 @@ function Initialize-GitHubConfig {
}

Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault'
$context = Get-Context -ID $script:GitHub.DefaultConfig.ID
$context = Get-Context -ID $script:GitHub.DefaultConfig.ID -Vault $script:GitHub.ContextVault
if ($context) {
Write-Debug 'GitHubConfig loaded into memory.'

Write-Debug "Checking if new default properties are available in the stored context."
Write-Debug 'Checking if new default properties are available in the stored context.'
$needsUpdate = $false
$defaultProperties = $script:GitHub.DefaultConfig.PSObject.Properties.Name
foreach ($propName in $defaultProperties) {
Expand All @@ -62,18 +60,19 @@ function Initialize-GitHubConfig {
}
if ($needsUpdate) {
Write-Debug 'Updating stored context with new default properties'
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $context -PassThru
$context = Set-Context -Context $context -Vault $script:GitHub.ContextVault -PassThru
}

$script:GitHub.Config = [GitHubConfig]$context
return
}
Write-Debug 'Initializing GitHubConfig from defaults'
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru
$context = Set-Context -Context $script:GitHub.DefaultConfig -Vault $script:GitHub.ContextVault -PassThru
$script:GitHub.Config = [GitHubConfig]$context
}

end {
Write-Debug "[$stackPath] - End"
}
}
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '8.0.2' }
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
[Parameter(Mandatory)]
[string] $Name,

# If specified, makes an anonymous request to the GitHub API without authentication.
[Parameter()]
[switch] $Anonymous,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
Expand All @@ -42,7 +38,6 @@
Method = 'GET'
APIEndpoint = "/gitignore/templates/$Name"
Accept = 'application/vnd.github.raw+json'
Anonymous = $Anonymous
Context = $Context
}

Expand Down
5 changes: 0 additions & 5 deletions src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
[OutputType([string[]])]
[CmdletBinding()]
param(
# If specified, makes an anonymous request to the GitHub API without authentication.
[Parameter()]
[switch] $Anonymous,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
Expand All @@ -39,7 +35,6 @@
$inputObject = @{
Method = 'GET'
APIEndpoint = '/gitignore/templates'
Anonymous = $Anonymous
Context = $Context
}

Expand Down
5 changes: 0 additions & 5 deletions src/functions/private/License/Get-GitHubLicenseByName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
[Parameter(Mandatory)]
[string] $Name,

# If specified, makes an anonymous request to the GitHub API without authentication.
[Parameter()]
[switch] $Anonymous,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
Expand All @@ -44,7 +40,6 @@
Method = 'GET'
APIEndpoint = "/licenses/$Name"
Accept = 'application/vnd.github+json'
Anonymous = $Anonymous
Context = $Context
}

Expand Down
5 changes: 0 additions & 5 deletions src/functions/private/License/Get-GitHubLicenseList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
[OutputType([GitHubLicense[]])]
[CmdletBinding()]
param(
# If specified, makes an anonymous request to the GitHub API without authentication.
[Parameter()]
[switch] $Anonymous,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
Expand All @@ -42,7 +38,6 @@
$inputObject = @{
Method = 'GET'
APIEndpoint = '/licenses'
Anonymous = $Anonymous
Context = $Context
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
[ValidateSet('raw', 'html')]
[string] $Type = 'raw',

# If specified, makes an anonymous request to the GitHub API without authentication.
[Parameter()]
[switch] $Anonymous,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter(Mandatory)]
Expand All @@ -62,7 +58,6 @@
Method = 'GET'
APIEndpoint = "/repos/$Owner/$Repository/license"
ContentType = $contentType
Anonymous = $Anonymous
Context = $Context
}

Expand Down
Loading