Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 13 additions & 11 deletions .github/PSModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/classes/public/GitHubStamp.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 0 additions & 2 deletions src/functions/public/Config/Get-GitHubConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

Get the DefaultContext value from the GitHub module configuration.



.LINK
https://psmodule.io/GitHub/Functions/Config/Get-GitHubConfig
#>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
Expand Down
62 changes: 62 additions & 0 deletions src/functions/public/Status/Get-GitHubStamp.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
}
6 changes: 3 additions & 3 deletions src/functions/public/Status/Get-GitHubStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@

# The stamp to check status for.
[Parameter()]
[ValidateSet('Public', 'Europe', 'Australia', 'US')]
[string] $Stamp = 'Public'
[Alias('Stamp')]
[string] $Name = 'Public'
)
begin {
$stackPath = Get-PSCallStackPath
Write-Debug "[$stackPath] - Start"
}

process {
$baseURL = $script:StatusBaseURL[$Stamp]
$baseURL = (Get-GitHubStamp -Name $Name).BaseUrl

if ($Summary) {
$APIURI = "$baseURL/api/v2/summary.json"
Expand Down
6 changes: 3 additions & 3 deletions src/functions/public/Status/Get-GitHubStatusComponent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/functions/public/Status/Get-GitHubStatusIncident.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -51,7 +51,7 @@
}

process {
$baseURL = $script:StatusBaseURL[$Stamp]
$baseURL = (Get-GitHubStamp -Name $Name).BaseUrl

if ($Unresolved) {
$APIURI = "$baseURL/api/v2/incidents/unresolved.json"
Expand Down
26 changes: 26 additions & 0 deletions src/functions/public/Status/completers.ps1
Original file line number Diff line number Diff line change
@@ -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)
}
}
5 changes: 5 additions & 0 deletions src/variables/private/GitHub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
}
6 changes: 0 additions & 6 deletions src/variables/private/StatusBaseURL.ps1

This file was deleted.

64 changes: 47 additions & 17 deletions tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 - <Name>' -ForEach @(Get-GitHubStamp | ForEach-Object { @{ Name = $_.Name } }) {
It 'Get-GitHubScheduledMaintenance - Gets scheduled maintenance for <Name>' {
{ 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 <Name>' {
{ 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 <Name>' {
{ 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 <Name>' {
{ 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 <Name>' {
{ 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 <Name>' {
{ 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 <Name>' {
{ 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 <Name>' {
{ Get-GitHubStatusIncident -Name $Name -Unresolved } | Should -Not -Throw
}
}
Context 'Commands' {
Expand Down
Loading