Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
da7a926
Environments and Variables (#320)
pmatthews05 Mar 16, 2025
796956e
Auto-generated changes
github-actions[bot] Mar 16, 2025
ede147d
Merge branch 'main' of https://github.com/PSModule/GitHub into variables
MariusStorhaug Mar 17, 2025
eb851e1
🩹 [Patch]: Refactor variable handling and improve code consistency in…
MariusStorhaug Mar 17, 2025
d52ac4f
Auto-generated changes
github-actions[bot] Mar 17, 2025
e35e252
🩹 [Patch]: Standardize formatting and improve documentation for GitHu…
MariusStorhaug Mar 17, 2025
c26d9ba
Merge branch 'variables' of https://github.com/PSModule/GitHub into v…
MariusStorhaug Mar 17, 2025
6efd65d
Get-GitHubVariable
MariusStorhaug Mar 17, 2025
998f92e
🩹 [Patch]: Update parameter set names and add new functions for creat…
MariusStorhaug Mar 17, 2025
51b68a0
Auto-generated changes
github-actions[bot] Mar 17, 2025
83e1ec5
🩹 [Patch]: Add functions to remove GitHub variables from environments…
MariusStorhaug Mar 17, 2025
ab5180e
Merge branch 'variables' of https://github.com/PSModule/GitHub into v…
MariusStorhaug Mar 17, 2025
7c906a5
🩹 [Patch]: Enhance documentation for variable removal functions and i…
MariusStorhaug Mar 17, 2025
a6818fa
🩹 [Patch]: Enhance Remove-GitHubVariable function to support array in…
MariusStorhaug Mar 17, 2025
a7506b1
🩹 [Patch]: Update Remove-GitHubVariable to allow pipeline input for a…
MariusStorhaug Mar 17, 2025
c8df89a
🩹 [Patch]: Refactor variable removal functions to use ForEach-Object …
MariusStorhaug Mar 17, 2025
e18b4a2
cleanup
MariusStorhaug Mar 17, 2025
6ce319a
🩹 [Patch]: Rename SelectedRepository parameter to SelectedRepositorie…
MariusStorhaug Mar 17, 2025
5768274
Auto-generated changes
github-actions[bot] Mar 17, 2025
5549f87
🩹 [Patch]: Remove unused NewName parameter from Update-GitHubVariable…
MariusStorhaug Mar 17, 2025
b9c00fa
🩹 [Patch]: Remove Value parameter from Update-GitHubVariable function…
MariusStorhaug Mar 17, 2025
bc7090a
🩹 [Patch]: Remove mandatory requirement for Value parameter in Update…
MariusStorhaug Mar 17, 2025
9d2a8a8
🩹 [Patch]: Update APIEndpoint in Update-GitHubVariableOnRepository fu…
MariusStorhaug Mar 17, 2025
58b7111
Auto-generated changes
github-actions[bot] Mar 17, 2025
3dd6b55
🩹 [Patch]: Add PassThru parameter to New-GitHubVariable and Update-Gi…
MariusStorhaug Mar 17, 2025
850a6e1
Auto-generated changes
github-actions[bot] Mar 17, 2025
321a5c2
🩹 [Patch]: Simplify API invocation in variable update functions and a…
MariusStorhaug Mar 17, 2025
19f74ed
Merge branch 'variables' of https://github.com/PSModule/GitHub into v…
MariusStorhaug Mar 17, 2025
8138469
Add retry config
MariusStorhaug Mar 17, 2025
0f51cb0
🩹 [Patch]: Add RetryCount and RetryInterval parameters to Invoke-GitH…
MariusStorhaug Mar 17, 2025
ea00ed4
🩹 [Patch]: Refactor New-GitHubVariable and Update-GitHubVariable func…
MariusStorhaug Mar 17, 2025
bcb5731
🩹 [Patch]: Add AllowNull attribute to Context parameter in Resolve-Gi…
MariusStorhaug Mar 17, 2025
557ab9f
🩹 [Patch]: Remove unused PassThru parameter from New-GitHubVariable f…
MariusStorhaug Mar 17, 2025
83cb08f
🩹 [Patch]: Update Update-GitHubVariable function to conditionally use…
MariusStorhaug Mar 17, 2025
c83eb67
🩹 [Patch]: Restore Visibility parameter in New-GitHubVariable and Upd…
MariusStorhaug Mar 17, 2025
bccba76
🩹 [Patch]: Update OutputType for New-GitHubVariable, Remove-GitHubVar…
MariusStorhaug Mar 17, 2025
63466e0
🩹 [Patch]: Refactor Set-GitHubVariable function to filter Get-GitHubV…
MariusStorhaug Mar 18, 2025
82d778d
🩹 [Test]: Add Pester tests for Set-GitHubVariable function across use…
MariusStorhaug Mar 18, 2025
3f17c50
🩹 [Test]: Add Set-GitHubEnvironment calls in repository tests for imp…
MariusStorhaug Mar 18, 2025
d8f6f80
🩹 [Test]: Refactor and enhance Set-GitHubVariable tests for user and …
MariusStorhaug Mar 18, 2025
5b12cc8
Send exception to throw
MariusStorhaug Mar 18, 2025
2ae757a
Set a prefix for tests to avoid clobbering from other tests
MariusStorhaug Mar 18, 2025
24a7735
🩹 [Test]: Add Connect-GitHubApp calls for organization tests to impro…
MariusStorhaug Mar 18, 2025
a600c45
🩹 [Test]: Update test variable values for consistency across user and…
MariusStorhaug Mar 18, 2025
64fe4a6
🩹 [Test]: Add delay in Remove-GitHubVariable tests to ensure proper c…
MariusStorhaug Mar 18, 2025
cc28c93
🩹 [Test]: Replace Start-Sleep with Write-Verbose for improved variabl…
MariusStorhaug Mar 18, 2025
7d96cce
🩹 [Test]: Simplify assertions in Remove-GitHubVariable tests by check…
MariusStorhaug Mar 18, 2025
e844127
🩹 [Fix]: Improve variable cleanup in Remove-GitHubVariable by adding …
MariusStorhaug Mar 18, 2025
357b5f0
🩹 [Fix]: Enhance error logging in Connect-GithubCli and streamline pa…
MariusStorhaug Mar 18, 2025
048c26a
🩹 [Fix]: Improve error handling in Connect-GithubCli and enhance logg…
MariusStorhaug Mar 18, 2025
f225f4b
🩹 [Fix]: Enhance error handling in Connect-GithubCli by capturing com…
MariusStorhaug Mar 18, 2025
7942580
🩹 [Fix]: Improve warning output formatting in Connect-GithubCli and e…
MariusStorhaug Mar 18, 2025
2a42ef9
🩹 [Fix]: Improve warning output and debug logging in Connect-GithubCl…
MariusStorhaug Mar 18, 2025
03e6685
🩹 [Fix]: Simplify loop syntax in Remove-GitHubVariable for improved r…
MariusStorhaug Mar 18, 2025
a04421e
🩹 [Fix]: Replace Write-Verbose with Write-Host in Remove-GitHubVariab…
MariusStorhaug Mar 18, 2025
20e7ca2
🩹 [Refactor]: Migrate test files to new directory structure and updat…
MariusStorhaug Mar 18, 2025
b89a686
<describe the changes made in the code>
MariusStorhaug Mar 18, 2025
32e763e
Merge branch 'main' of https://github.com/PSModule/GitHub into variables
MariusStorhaug Mar 18, 2025
1434f79
🩹 [Refactor]: Move repository tests to a new directory and restructur…
MariusStorhaug Mar 18, 2025
4980908
Refactor: Update test structure and enhance documentation for better …
MariusStorhaug Mar 18, 2025
946be88
Refactor: Organize test files into a dedicated directory and improve …
MariusStorhaug Mar 18, 2025
1118bbd
Add initial test files for GitHub API interactions and enhance docume…
MariusStorhaug Mar 18, 2025
9112072
Add function to list organization variables and enhance Get-GitHubVar…
MariusStorhaug Mar 18, 2025
e193d9c
Auto-generated changes
github-actions[bot] Mar 18, 2025
5347951
Refactor: Improve formatting and readability in Get-GitHubVariableFro…
MariusStorhaug Mar 18, 2025
843ee53
Add testing framework files and documentation for GitHub API interact…
MariusStorhaug Mar 18, 2025
24f621b
Refactor: Update Set-GitHubVariable calls to use repoName for improve…
MariusStorhaug Mar 18, 2025
526b045
Refactor: Update variable naming in tests for consistency and clarity
MariusStorhaug Mar 18, 2025
5b0c646
Refactor: Update variable naming for clarity in Variables.Tests.ps1
MariusStorhaug Mar 18, 2025
2dce32c
Add tests for Get-GitHubVariable and Get-GitHubVariable -All with out…
MariusStorhaug Mar 18, 2025
0af6958
Refactor: Update Get-GitHubVariable to include Repository parameter f…
MariusStorhaug Mar 18, 2025
89b75d3
Enhance Get-GitHubVariable functions to include pagination in organiz…
MariusStorhaug Mar 18, 2025
29d0293
Implement retry logic in New-GitHubVariable for improved variable ret…
MariusStorhaug Mar 18, 2025
dbe1363
Remove unnecessary variable cleanup for contextData in Connect-GitHub…
MariusStorhaug Mar 18, 2025
561cf27
Add check for context type in Get-GitHubVariableFromOrganization to p…
MariusStorhaug Mar 18, 2025
50d933d
Implement error handling in Get-GitHubVariableFromOrganization to imp…
MariusStorhaug Mar 18, 2025
72965bb
Refactor Connect-GitHubAccount calls to remove unnecessary Format-Lis…
MariusStorhaug Mar 18, 2025
769b63a
Update Get-GitHubContext tests to use Write-Host for output display
MariusStorhaug Mar 18, 2025
a8aa052
Remove unnecessary user context check in Get-GitHubVariableFromOrgani…
MariusStorhaug Mar 18, 2025
9d9f20c
Remove GitHubVariable.Format.ps1xml file to simplify output formatting
MariusStorhaug Mar 18, 2025
9b3d3f6
Refactor output handling in Get-GitHubVariableFromOrganization for im…
MariusStorhaug Mar 18, 2025
f9505bd
Update LogGroup calls in Variables.Tests.ps1 to include 'Context' lab…
MariusStorhaug Mar 18, 2025
4e80ada
Update LogGroup calls in Variables.Tests.ps1 to use Out-String for im…
MariusStorhaug Mar 18, 2025
75a439d
Add GitHubVariable.Format.ps1xml for structured output formatting
MariusStorhaug Mar 18, 2025
411d5b2
Enable debug and verbose output preferences in Variables.Tests.ps1 fo…
MariusStorhaug Mar 19, 2025
3b6ff83
Add testing framework documentation and templates; enhance GitHub API…
MariusStorhaug Mar 19, 2025
08c6ff6
Remove commented-out configuration for skipping tests in Process-PSMo…
MariusStorhaug Mar 19, 2025
f66cf49
Remove deprecated GitHubVariable and GitHubRepository classes; enhanc…
MariusStorhaug Mar 19, 2025
71e71aa
Merge branch 'main' of https://github.com/PSModule/GitHub into updateAPI
MariusStorhaug Mar 19, 2025
a740b36
Auto-generated changes
github-actions[bot] Mar 19, 2025
5527f22
Remove AllowNull attribute from $Context parameter in Resolve-GitHubC…
MariusStorhaug Mar 19, 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
6 changes: 6 additions & 0 deletions src/classes/public/Config/GitHubConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
# The default value for the 'per_page' API parameter used in 'GET' functions that support paging.
[int] $PerPage

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

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

# Simple parameterless constructor
GitHubConfig() {}

Expand Down
3 changes: 0 additions & 3 deletions src/formats/GitHubContext.Format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<!-- Table View Definition -->
<View>
<Name>GitHubContextTableView</Name>
<ViewSelectedBy>
Expand Down Expand Up @@ -42,8 +41,6 @@
</TableRowEntries>
</TableControl>
</View>

<!-- List View Definition -->
<View>
<Name>GitHubContextListView</Name>
<ViewSelectedBy>
Expand Down
3 changes: 0 additions & 3 deletions src/formats/GitHubWebhook.Format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<!-- Table View -->
<View>
<Name>GitHubWebhookTable</Name>
<ViewSelectedBy>
Expand Down Expand Up @@ -79,8 +78,6 @@
</TableRowEntries>
</TableControl>
</View>

<!-- List View -->
<View>
<Name>GitHubWebhookList</Name>
<ViewSelectedBy>
Expand Down
3 changes: 0 additions & 3 deletions src/formats/GitHubWebhookRedelivery.Format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<!-- Table View -->
<View>
<Name>GitHubWebhookRedeliveryTable</Name>
<ViewSelectedBy>
Expand Down Expand Up @@ -60,8 +59,6 @@
</TableRowEntries>
</TableControl>
</View>

<!-- List View -->
<View>
<Name>GitHubWebhookRedeliveryList</Name>
<ViewSelectedBy>
Expand Down
11 changes: 8 additions & 3 deletions src/functions/private/Auth/Cli/Connect-GithubCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@
}

process {
$Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName
$return = ($Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName) 2>&1
$return = $return -join [System.Environment]::NewLine
if ($LASTEXITCODE -ne 0) {
Write-Warning 'Unable to log on with the GitHub Cli.'
if ($return.Contains('GITHUB_TOKEN environment variable is being used for authentication')) {
Write-Debug $return
} else {
Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)"
Write-Warning "$($return)"
}
$Global:LASTEXITCODE = 0
Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE"
return
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@
if ([string]::IsNullOrEmpty($Value)) {
$Value = $Context.$Name
}
Write-Debug "$Name`: [$Value]"
return $Value
}
81 changes: 54 additions & 27 deletions src/functions/public/API/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ filter Invoke-GitHubAPI {
[Parameter()]
[string] $ApiVersion,

# Specifies how many times PowerShell retries a connection when a failure code between 400 and 599, inclusive or 304 is received.
[Parameter()]
[int] $RetryCount = $script:GitHub.Config.RetryCount,

# Specifies the interval between retries for the connection when a failure code between 400 and 599, inclusive or 304 is received.
# When the failure code is 429 and the response includes the Retry-After property in its headers, the cmdlet uses that value for the retry
# interval, even if this parameter is specified.
[Parameter()]
[int] $RetryInterval = $script:GitHub.Config.RetryInterval,

# The number of results per page for paginated GitHub API responses.
[Parameter()]
[int] $PerPage,

# 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 @@ -92,20 +106,26 @@ filter Invoke-GitHubAPI {
Write-Debug "[$stackPath] - Start"
$Context = Resolve-GitHubContext -Context $Context
Write-Debug 'Invoking GitHub API...'
Write-Debug 'Parameters:'
Get-FunctionParameter | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ }
Write-Debug 'Parent function parameters:'
Get-FunctionParameter -Scope 1 | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ }
Write-Debug 'Parameters:'
Get-FunctionParameter | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ }
}

process {
$Token = $Context.Token
Write-Debug "Token: [$Token]"

$HttpVersion = Resolve-GitHubContextSetting -Name 'HttpVersion' -Value $HttpVersion -Context $Context
$ApiBaseUri = Resolve-GitHubContextSetting -Name 'ApiBaseUri' -Value $ApiBaseUri -Context $Context
$ApiVersion = Resolve-GitHubContextSetting -Name 'ApiVersion' -Value $ApiVersion -Context $Context
$TokenType = Resolve-GitHubContextSetting -Name 'TokenType' -Value $TokenType -Context $Context
[pscustomobject]@{
Token = $Token
HttpVersion = $HttpVersion
ApiBaseUri = $ApiBaseUri
ApiVersion = $ApiVersion
TokenType = $TokenType
} | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ }
$jwt = $null
switch ($TokenType) {
'ghu' {
Expand All @@ -132,32 +152,39 @@ filter Invoke-GitHubAPI {
}

$APICall = @{
Uri = $Uri
Method = [string]$Method
Headers = $Headers
Authentication = 'Bearer'
Token = $Token
ContentType = $ContentType
InFile = $UploadFilePath
OutFile = $DownloadFilePath
HttpVersion = [string]$HttpVersion
Uri = $Uri
Method = [string]$Method
Headers = $Headers
Authentication = 'Bearer'
Token = $Token
ContentType = $ContentType
InFile = $UploadFilePath
OutFile = $DownloadFilePath
HttpVersion = [string]$HttpVersion
MaximumRetryCount = $RetryCount
RetryIntervalSec = $RetryInterval
}
$APICall | Remove-HashtableEntry -NullOrEmptyValues

if ($Body) {
# Use body to create the query string for certain situations
if ($Method -eq 'GET') {
# If body conatins 'per_page' and its is null, set it to $context.PerPage
if ($Body['per_page'] -eq 0) {
Write-Debug "Setting per_page to the default value in context [$($Context.PerPage)]."
$Body['per_page'] = $Context.PerPage
}
$APICall.Uri = New-Uri -BaseUri $Uri -Query $Body -AsString
} elseif ($Body -is [string]) {
# Use body to create the form data
$APICall.Body = $Body
} else {
if ($Method -eq 'GET') {
if (-not $Body) {
$Body = @{}
}

if ($PSBoundParameters.ContainsKey('PerPage')) {
Write-Debug "Using provided PerPage parameter value [$PerPage]."
$Body['per_page'] = $PerPage
} elseif (-not $Body.ContainsKey('per_page') -or $Body['per_page'] -eq 0) {
Write-Debug "Setting per_page to the default value in context [$($Context.PerPage)]."
$Body['per_page'] = $Context.PerPage
}

$APICall.Uri = New-Uri -BaseUri $Uri -Query $Body -AsString
} elseif ($Body) {
if ($Body -is [hashtable]) {
$APICall.Body = $Body | ConvertTo-Json -Depth 100
} else {
$APICall.Body = $Body
}
}

Expand Down Expand Up @@ -289,7 +316,7 @@ filter Invoke-GitHubAPI {
$APICall.Headers = $APICall.Headers | ConvertTo-Json
$APICall.Method = $APICall.Method.ToString()

Write-Warning @"
$exception = @"

----------------------------------
Error details:
Expand All @@ -300,7 +327,7 @@ $($errorResult | Format-List | Out-String -Stream | ForEach-Object { " $_`n"

$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new('GitHub API call failed. See error details above.'),
[System.Exception]::new($exception),
'GitHubAPIError',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$errorResult
Expand Down
1 change: 0 additions & 1 deletion src/functions/public/Auth/Connect-GitHubAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@
clean {
Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue
Remove-Variable -Name context -ErrorAction SilentlyContinue
Remove-Variable -Name contextData -ErrorAction SilentlyContinue
Remove-Variable -Name Token -ErrorAction SilentlyContinue
[System.GC]::Collect()
}
Expand Down
2 changes: 2 additions & 0 deletions src/variables/private/GitHub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
ApiVersion = '2022-11-28'
HttpVersion = '2.0'
PerPage = 100
RetryCount = 0
RetryInterval = 1
}
Config = $null
Event = $null
Expand Down
2 changes: 2 additions & 0 deletions tests/TEMPLATE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' {
BeforeAll {
Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY
$owner = 'psmodule-test-org3'
Connect-GitHubApp -Organization $owner -Default
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
Expand All @@ -84,6 +85,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' {
BeforeAll {
Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY
$owner = 'psmodule-test-org'
Connect-GitHubApp -Organization $owner -Default
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount
Expand Down