diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 0d130b7e0..a76dd4845 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -5,17 +5,19 @@ Test: CodeCoverage: PercentTarget: 50 -# TestResults: -# Skip: true -# SourceCode: -# Skip: true -# PSModule: -# Skip: true -# Module: -# Windows: -# Skip: true -# MacOS: -# Skip: true + # Skip: true + # TestResults: + # Skip: true + # SourceCode: + # Skip: true + # PSModule: + # Skip: true + # Module: + # Skip: true + # Windows: + # Skip: true + # MacOS: + # Skip: true # Build: # Docs: # Skip: true diff --git a/src/classes/public/GitHubStamp.ps1 b/src/classes/public/GitHubStamp.ps1 new file mode 100644 index 000000000..e7ddb514e --- /dev/null +++ b/src/classes/public/GitHubStamp.ps1 @@ -0,0 +1,20 @@ +class GitHubStamp { + # The name of the stamp (region). + # Example: 'Public' + [string] $Name + + # The base URL of the status page for this stamp. + # Example: 'https://www.githubstatus.com' + [string] $BaseUrl + + GitHubStamp() {} + + GitHubStamp([string]$Name, [string]$BaseUrl) { + $this.Name = $Name + $this.BaseUrl = $BaseUrl + } + + [string] ToString() { + return $this.Name + } +} diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index aa7248b2e..3f943efab 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -13,8 +13,6 @@ Get the DefaultContext value from the GitHub module configuration. - - .LINK https://psmodule.io/GitHub/Functions/Config/Get-GitHubConfig #> diff --git a/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 b/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 index cdf08cde3..230452fdb 100644 --- a/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 +++ b/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 @@ -54,8 +54,8 @@ # The stamp to check status for. [Parameter()] - [ValidateSet('Public', 'Europe', 'Australia', 'US')] - [string] $Stamp = 'Public' + [Alias('Stamp')] + [string] $Name = 'Public' ) begin { @@ -64,7 +64,8 @@ } process { - $baseURL = $script:StatusBaseURL[$Stamp] + $stamp = Get-GitHubStamp -Name $Name + $baseURL = $stamp.BaseUrl if ($Active) { $APIURI = "$baseURL/api/v2/scheduled-maintenances/active.json" diff --git a/src/functions/public/Status/Get-GitHubStamp.ps1 b/src/functions/public/Status/Get-GitHubStamp.ps1 new file mode 100644 index 000000000..bd4d04419 --- /dev/null +++ b/src/functions/public/Status/Get-GitHubStamp.ps1 @@ -0,0 +1,62 @@ +function Get-GitHubStamp { + <# + .SYNOPSIS + Gets the available GitHub Status page stamps (regions). + + .DESCRIPTION + Returns the available GitHub Status page stamps, which represent different regional status pages. + Each stamp includes the name and base URL of the status page. + + .EXAMPLE + ```powershell + Get-GitHubStamp + ``` + + Gets all available GitHub Status page stamps. + + .EXAMPLE + ```powershell + Get-GitHubStamp -Name 'Europe' + ``` + + Gets the GitHub Status page stamp for 'Europe'. + + .NOTES + [GitHub Status API](https://www.githubstatus.com/api) + + .LINK + https://psmodule.io/GitHub/Functions/Status/Get-GitHubStamp + #> + [OutputType([GitHubStamp[]])] + [CmdletBinding()] + param( + # The name of the stamp to get. If not specified, all stamps are returned. + [Parameter()] + [ValidateNotNullOrEmpty()] + [Alias('Stamp')] + [string] $Name + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + } + + process { + if ([string]::IsNullOrEmpty($Name)) { + $script:GitHub.Stamps + return + } + + $stamp = $script:GitHub.Stamps | Where-Object { $_.Name -eq $Name } + if (-not $stamp) { + $available = $script:GitHub.Stamps.Name -join ', ' + throw "Stamp '$Name' not found. Available stamps: $available" + } + $stamp + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Status/Get-GitHubStatus.ps1 b/src/functions/public/Status/Get-GitHubStatus.ps1 index 94ac1dec6..96dbe2d62 100644 --- a/src/functions/public/Status/Get-GitHubStatus.ps1 +++ b/src/functions/public/Status/Get-GitHubStatus.ps1 @@ -42,8 +42,8 @@ # The stamp to check status for. [Parameter()] - [ValidateSet('Public', 'Europe', 'Australia', 'US')] - [string] $Stamp = 'Public' + [Alias('Stamp')] + [string] $Name = 'Public' ) begin { $stackPath = Get-PSCallStackPath @@ -51,7 +51,7 @@ } process { - $baseURL = $script:StatusBaseURL[$Stamp] + $baseURL = (Get-GitHubStamp -Name $Name).BaseUrl if ($Summary) { $APIURI = "$baseURL/api/v2/summary.json" diff --git a/src/functions/public/Status/Get-GitHubStatusComponent.ps1 b/src/functions/public/Status/Get-GitHubStatusComponent.ps1 index 10d341740..1365160f8 100644 --- a/src/functions/public/Status/Get-GitHubStatusComponent.ps1 +++ b/src/functions/public/Status/Get-GitHubStatusComponent.ps1 @@ -26,8 +26,8 @@ param( # The stamp to check status for. [Parameter()] - [ValidateSet('Public', 'Europe', 'Australia', 'US')] - [string] $Stamp = 'Public' + [Alias('Stamp')] + [string] $Name = 'Public' ) begin { @@ -36,7 +36,7 @@ } process { - $baseURL = $script:StatusBaseURL[$Stamp] + $baseURL = (Get-GitHubStamp -Name $Name).BaseUrl $APIURI = "$baseURL/api/v2/components.json" $response = Invoke-RestMethod -Uri $APIURI -Method Get diff --git a/src/functions/public/Status/Get-GitHubStatusIncident.ps1 b/src/functions/public/Status/Get-GitHubStatusIncident.ps1 index fc89706de..8789b5b93 100644 --- a/src/functions/public/Status/Get-GitHubStatusIncident.ps1 +++ b/src/functions/public/Status/Get-GitHubStatusIncident.ps1 @@ -41,8 +41,8 @@ # The stamp to check status for. [Parameter()] - [ValidateSet('Public', 'Europe', 'Australia', 'US')] - [string] $Stamp = 'Public' + [Alias('Stamp')] + [string] $Name = 'Public' ) begin { @@ -51,7 +51,7 @@ } process { - $baseURL = $script:StatusBaseURL[$Stamp] + $baseURL = (Get-GitHubStamp -Name $Name).BaseUrl if ($Unresolved) { $APIURI = "$baseURL/api/v2/incidents/unresolved.json" diff --git a/src/functions/public/Status/completers.ps1 b/src/functions/public/Status/completers.ps1 new file mode 100644 index 000000000..9d7543cc6 --- /dev/null +++ b/src/functions/public/Status/completers.ps1 @@ -0,0 +1,26 @@ +Register-ArgumentCompleter -CommandName @( + 'Get-GitHubScheduledMaintenance' + 'Get-GitHubStamp' + 'Get-GitHubStatus' + 'Get-GitHubStatusComponent' + 'Get-GitHubStatusIncident' +) -ParameterName Name -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + + $stamps = Get-GitHubStamp + if (-not $stamps) { + return $null + } + + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + $filteredOptions = $stamps | Where-Object { $_.Name -like $pattern } + + if (-not $filteredOptions) { + return $null + } + + $filteredOptions | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) + } +} diff --git a/src/variables/private/GitHub.ps1 b/src/variables/private/GitHub.ps1 index 67f82414e..67e103c8b 100644 --- a/src/variables/private/GitHub.ps1 +++ b/src/variables/private/GitHub.ps1 @@ -23,4 +23,9 @@ $script:GitHub = [pscustomobject]@{ Config = $null Event = $null Runner = $null + Stamps = @( + [GitHubStamp]::new('Public', 'https://www.githubstatus.com') + [GitHubStamp]::new('Europe', 'https://eu.githubstatus.com') + [GitHubStamp]::new('US', 'https://us.githubstatus.com') + ) } diff --git a/src/variables/private/StatusBaseURL.ps1 b/src/variables/private/StatusBaseURL.ps1 deleted file mode 100644 index a5ddbabdd..000000000 --- a/src/variables/private/StatusBaseURL.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -$script:StatusBaseURL = @{ - Public = 'https://www.githubstatus.com' - Europe = 'https://eu.githubstatus.com' - Australia = 'https://au.githubstatus.com' - US = 'https://us.githubstatus.com' -} diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 177d53235..fb16e1c3c 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -283,30 +283,60 @@ Describe 'GitHub' { $runnerData | Should -Not -BeNullOrEmpty } } - Context 'Status' -ForEach @('Public', 'Europe', 'Australia', 'US') { - It 'Get-GitHubScheduledMaintenance - Gets scheduled maintenance for <_>' { - { Get-GitHubScheduledMaintenance -Stamp $_ } | Should -Not -Throw + Context 'Stamps' { + It 'Get-GitHubStamp - Gets all available stamps' { + $stamps = Get-GitHubStamp + LogGroup 'All Stamps' { + Write-Host ($stamps | Format-Table -AutoSize | Out-String) + } + $stamps | Should -Not -BeNullOrEmpty + $stamps.Count | Should -BeGreaterThan 0 + } + It 'Get-GitHubStamp - Each stamp has Name and BaseUrl properties' { + LogGroup "Stamps - Details" { + Get-GitHubStamp | ForEach-Object { + Write-Host ($_ | Format-List | Out-String) + $_.Name | Should -Not -BeNullOrEmpty + $_.BaseUrl | Should -Not -BeNullOrEmpty + } + } + } + It 'Get-GitHubStamp - Gets a specific stamp by name' { + $stamp = Get-GitHubStamp -Name 'Public' + LogGroup 'Stamp - Public' { + Write-Host ($stamp | Format-List | Out-String) + } + $stamp | Should -Not -BeNullOrEmpty + $stamp.Name | Should -Be 'Public' + } + It 'Get-GitHubStamp - Throws for invalid stamp name' { + { Get-GitHubStamp -Name 'InvalidStampName' } | Should -Throw + } + } + Context 'Status - ' -ForEach @(Get-GitHubStamp | ForEach-Object { @{ Name = $_.Name } }) { + It 'Get-GitHubScheduledMaintenance - Gets scheduled maintenance for ' { + { Get-GitHubScheduledMaintenance -Name $Name } | Should -Not -Throw } - It 'Get-GitHubScheduledMaintenance - Gets active maintenance for <_>' { - { Get-GitHubScheduledMaintenance -Stamp $_ -Active } | Should -Not -Throw + It 'Get-GitHubScheduledMaintenance - Gets active maintenance for ' { + { Get-GitHubScheduledMaintenance -Name $Name -Active } | Should -Not -Throw } - It 'Get-GitHubScheduledMaintenance - Gets upcoming maintenance for <_>' { - { Get-GitHubScheduledMaintenance -Stamp $_ -Upcoming } | Should -Not -Throw + It 'Get-GitHubScheduledMaintenance - Gets upcoming maintenance for ' { + { Get-GitHubScheduledMaintenance -Name $Name -Upcoming } | Should -Not -Throw } - It 'Get-GitHubStatus - Gets all status for <_>' { - { Get-GitHubStatus -Stamp $_ } | Should -Not -Throw + It 'Get-GitHubStatus - Gets all status for ' { + { Get-GitHubStatus -Name $Name } | Should -Not -Throw } - It 'Get-GitHubStatus - Gets summary status for <_>' { - { Get-GitHubStatus -Stamp $_ -Summary } | Should -Not -Throw + It 'Get-GitHubStatus - Gets summary status for ' { + { Get-GitHubStatus -Name $Name -Summary } | Should -Not -Throw } - It 'Get-GitHubStatusComponent - Gets the status of GitHub components for <_>' { - { Get-GitHubStatusComponent -Stamp $_ } | Should -Not -Throw + It 'Get-GitHubStatusComponent - Gets the status of GitHub components for ' { + { Get-GitHubStatusComponent -Name $Name } | Should -Not -Throw } - It 'Get-GitHubStatusIncident - Gets the status of all GitHub incidents for <_>' { - { Get-GitHubStatusIncident -Stamp $_ } | Should -Not -Throw + It 'Get-GitHubStatusIncident - Gets the status of all GitHub incidents for ' { + { Get-GitHubStatusIncident -Name $Name } | Should -Not -Throw } - It 'Get-GitHubStatusIncident - Gets the status of unresolved GitHub incidents for <_>' { - { Get-GitHubStatusIncident -Stamp $_ -Unresolved } | Should -Not -Throw + It 'Get-GitHubStatusIncident - Gets the status of unresolved GitHub incidents for ' { + { Get-GitHubStatusIncident -Name $Name -Unresolved } | Should -Not -Throw } } Context 'Commands' {