From 7baf7901960edf5d72c0c820033f259426ea087d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 19 Dec 2024 21:37:34 +0100 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20GitHub?= =?UTF-8?q?=20webhook=20delivery=20functions=20with=20output=20type=20and?= =?UTF-8?q?=20structured=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/public/Webhooks/GitHubWebhook.ps1 | 63 ++++++++ src/formats/GitHubWebhook.format.ps1xml | 136 ++++++++++++++++++ .../Get-GitHubAppWebhookDeliveryByID.ps1 | 21 ++- .../Get-GitHubAppWebhookDeliveryByList.ps1 | 21 ++- .../Webhooks/Get-GitHubAppWebhookDelivery.ps1 | 1 + 5 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 src/classes/public/Webhooks/GitHubWebhook.ps1 create mode 100644 src/formats/GitHubWebhook.format.ps1xml diff --git a/src/classes/public/Webhooks/GitHubWebhook.ps1 b/src/classes/public/Webhooks/GitHubWebhook.ps1 new file mode 100644 index 000000000..baba79368 --- /dev/null +++ b/src/classes/public/Webhooks/GitHubWebhook.ps1 @@ -0,0 +1,63 @@ +class GitHubWebhook { + # Unique identifier of the delivery. + [int] $ID + + # Unique identifier for the event (shared with all deliveries for all webhooks that subscribe to this event). + [string] $GUID + + # Time when the delivery was delivered. + [datetime] $DeliveredAt + + # Whether the delivery is a redelivery. + [boolean] $Redelivery + + # Time spent delivering, in seconds. + [double] $Duration + + # Description of the status of the attempted delivery + [string] $Status + + # Status code received when delivery was made. + [int] $StatusCode + + # The event that triggered the delivery. + [string] $Event + + # The type of activity for the event that triggered the delivery. + [string] $Action + + # The id of the GitHub App installation associated with this event. + [int] $InstallationID + + # The id of the repository associated with this event. + [int] $RepositoryID + + # Time when the webhook delivery was throttled. + [datetime] $ThrottledAt + + # The URL target of the delivery. + [string] $URL + + # The request for the delivery. + [object] $Request + + # The response from the delivery. + [object] $Response + + # Simple parameterless constructor + GitHubWebhook() {} + + # Creates a context object from a hashtable of key-vaule pairs. + GitHubWebhook([hashtable]$Properties) { + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } + + # Creates a context object from a PSCustomObject. + GitHubWebhook([PSCustomObject]$Object) { + $Object.PSObject.Properties | ForEach-Object { + $this.($_.Name) = $_.Value + } + } +} diff --git a/src/formats/GitHubWebhook.format.ps1xml b/src/formats/GitHubWebhook.format.ps1xml new file mode 100644 index 000000000..b2dbb4603 --- /dev/null +++ b/src/formats/GitHubWebhook.format.ps1xml @@ -0,0 +1,136 @@ + + + + + + GitHubWebhookTable + + GitHubWebhook + + + + Status + ID + GUID + Event + StatusCode + DeliveredAt + Duration(s) + + + + + + + + if ($_.Status -eq 'ok') { + # Green checkmark + [char]0x2714 + } + else { + # Red heavy ballot X + [char]0x2718 + } + + + + ID + + + GUID + + + Event + + + StatusCode + + + DeliveredAt + + + Duration + + + + + + + + + + GitHubWebhookList + + GitHubWebhook + + + + + + + + ID + + + + GUID + + + + DeliveredAt + + + + Redelivery + + + + Duration + + + + Status + + + + StatusCode + + + + Event + + + + Action + + + + InstallationID + + + + RepositoryID + + + + ThrottledAt + + + + URL + + + + Request + + + + Response + + + + + + + + diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 index 9d0d0be35..6b6e77462 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 @@ -18,6 +18,7 @@ .NOTES [Get a delivery for an app webhook](https://docs.github.com/rest/apps/webhooks#get-a-delivery-for-an-app-webhook) #> + [OutputType([GitHubWebhook])] [CmdletBinding()] param( # The ID of the delivery. @@ -47,7 +48,25 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + [GitHubWebhook]( + @{ + ID = $_.id + GUID = $_.guid + DeliveredAt = $_.delivered_at + Redelivery = $_.redelivery + Duration = $_.duration + Status = $_.status + StatusCode = $_.status_code + Event = $_.event + Action = $_.action + InstallationID = $_.installation.id + RepositoryID = $_.repository.id + ThrottledAt = $_.throttled_at + URL = $_.url + Request = $_.request + Response = $_.response + } + ) } } catch { throw $_ diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 index 9aea3c270..03b3b45ad 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 @@ -17,6 +17,7 @@ .NOTES [Get a webhook configuration for an app](https://docs.github.com/rest/apps/webhooks#get-a-webhook-configuration-for-an-app) #> + [OutputType([GitHubWebhook[]])] [CmdletBinding()] param( # The context to run the command in. Used to get the details for the API call. @@ -41,7 +42,25 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + [GitHubWebhook]( + @{ + ID = $_.id + GUID = $_.guid + DeliveredAt = $_.delivered_at + Redelivery = $_.redelivery + Duration = $_.duration + Status = $_.status + StatusCode = $_.status_code + Event = $_.event + Action = $_.action + InstallationID = $_.installation.id + RepositoryID = $_.repository.id + ThrottledAt = $_.throttled_at + URL = $_.url + Request = $_.request + Response = $_.response + } + ) } } catch { throw $_ diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 index 8b8518977..e4719a71b 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 @@ -23,6 +23,7 @@ [Get a delivery for an app webhook](https://docs.github.com/rest/apps/webhooks#get-a-delivery-for-an-app-webhook) [Get a webhook configuration for an app](https://docs.github.com/rest/apps/webhooks#get-a-webhook-configuration-for-an-app) #> + [OutputType([GitHubWebhook[]])] [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The ID of the delivery. From 1dc3d45fd7e4c49c8d01f1c6b461d72fe917c28c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:38:54 +0000 Subject: [PATCH 2/8] Auto-generated changes --- Coverage.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Coverage.md b/Coverage.md index e65516446..27405ffa0 100644 --- a/Coverage.md +++ b/Coverage.md @@ -5,7 +5,7 @@ - + @@ -13,11 +13,11 @@ - + - +
Available functions992998
Covered functions
Missing functions833839
Coverage16.03%15.93%
@@ -218,6 +218,9 @@ | `/orgs/{org}/personal-access-tokens` | | :x: | | :x: | | | `/orgs/{org}/personal-access-tokens/{pat_id}` | | | | :x: | | | `/orgs/{org}/personal-access-tokens/{pat_id}/repositories` | | :x: | | | | +| `/orgs/{org}/private-registries` | | :x: | | :x: | | +| `/orgs/{org}/private-registries/public-key` | | :x: | | | | +| `/orgs/{org}/private-registries/{secret_name}` | :x: | :x: | :x: | | | | `/orgs/{org}/projects` | | :x: | | :x: | | | `/orgs/{org}/properties/schema` | | :x: | :x: | | | | `/orgs/{org}/properties/schema/{custom_property_name}` | :x: | :x: | | | :x: | From 5f2d700e3780caf2dfc9382d72df515fd3720752 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 19 Dec 2024 21:40:53 +0100 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20[Remove]:=20Delete?= =?UTF-8?q?=20GitHubWebhook.format.ps1xml=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {src/formats => examples}/GitHubWebhook.format.ps1xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src/formats => examples}/GitHubWebhook.format.ps1xml (100%) diff --git a/src/formats/GitHubWebhook.format.ps1xml b/examples/GitHubWebhook.format.ps1xml similarity index 100% rename from src/formats/GitHubWebhook.format.ps1xml rename to examples/GitHubWebhook.format.ps1xml From 9b3825d1001af74fbc3144da3069f2b043b6460f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 19 Dec 2024 22:06:25 +0100 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20GitHubWe?= =?UTF-8?q?bhook=20class=20to=20use=20appropriate=20unsigned=20integer=20t?= =?UTF-8?q?ypes=20and=20handle=20null=20dates=20in=20webhook=20delivery=20?= =?UTF-8?q?functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/public/Webhooks/GitHubWebhook.ps1 | 8 ++-- .../Get-GitHubAppWebhookDeliveryByID.ps1 | 4 +- .../Get-GitHubAppWebhookDeliveryByList.ps1 | 40 ++++++++++--------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/classes/public/Webhooks/GitHubWebhook.ps1 b/src/classes/public/Webhooks/GitHubWebhook.ps1 index baba79368..ecf7d630e 100644 --- a/src/classes/public/Webhooks/GitHubWebhook.ps1 +++ b/src/classes/public/Webhooks/GitHubWebhook.ps1 @@ -1,6 +1,6 @@ class GitHubWebhook { # Unique identifier of the delivery. - [int] $ID + [uint64] $ID # Unique identifier for the event (shared with all deliveries for all webhooks that subscribe to this event). [string] $GUID @@ -18,7 +18,7 @@ [string] $Status # Status code received when delivery was made. - [int] $StatusCode + [uint16] $StatusCode # The event that triggered the delivery. [string] $Event @@ -27,10 +27,10 @@ [string] $Action # The id of the GitHub App installation associated with this event. - [int] $InstallationID + [uint64] $InstallationID # The id of the repository associated with this event. - [int] $RepositoryID + [uint64] $RepositoryID # Time when the webhook delivery was throttled. [datetime] $ThrottledAt diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 index 6b6e77462..0a7aba9a4 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 @@ -52,7 +52,7 @@ @{ ID = $_.id GUID = $_.guid - DeliveredAt = $_.delivered_at + DeliveredAt = $null -eq $_.delivered_at ? [datetime]::MinValue : [DateTime]::Parse($_.delivered_at) Redelivery = $_.redelivery Duration = $_.duration Status = $_.status @@ -61,7 +61,7 @@ Action = $_.action InstallationID = $_.installation.id RepositoryID = $_.repository.id - ThrottledAt = $_.throttled_at + ThrottledAt = $null -eq $_.throttled_at ? [datetime]::MinValue : [DateTime]::Parse($_.throttled_at) URL = $_.url Request = $_.request Response = $_.response diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 index 03b3b45ad..ffb7de548 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 @@ -42,25 +42,27 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubWebhook]( - @{ - ID = $_.id - GUID = $_.guid - DeliveredAt = $_.delivered_at - Redelivery = $_.redelivery - Duration = $_.duration - Status = $_.status - StatusCode = $_.status_code - Event = $_.event - Action = $_.action - InstallationID = $_.installation.id - RepositoryID = $_.repository.id - ThrottledAt = $_.throttled_at - URL = $_.url - Request = $_.request - Response = $_.response - } - ) + $_.Response | ForEach-Object { + [GitHubWebhook]( + @{ + ID = $_.id + GUID = $_.guid + DeliveredAt = $null -eq $_.delivered_at ? [datetime]::MinValue : [DateTime]::Parse($_.delivered_at) + Redelivery = $_.redelivery + Duration = $_.duration + Status = $_.status + StatusCode = $_.status_code + Event = $_.event + Action = $_.action + InstallationID = $_.installation.id + RepositoryID = $_.repository.id + ThrottledAt = $null -eq $_.throttled_at ? [datetime]::MinValue : [DateTime]::Parse($_.throttled_at) + URL = $_.url + Request = $_.request + Response = $_.response + } + ) + } } } catch { throw $_ From 34830794663a3e3674feeeaf925492852e8b78ed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 19 Dec 2024 22:09:18 +0100 Subject: [PATCH 5/8] Fix --- src/classes/public/Webhooks/GitHubWebhook.ps1 | 12 ++++++------ .../Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 | 4 ++-- .../Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/classes/public/Webhooks/GitHubWebhook.ps1 b/src/classes/public/Webhooks/GitHubWebhook.ps1 index ecf7d630e..8b2a7cf7a 100644 --- a/src/classes/public/Webhooks/GitHubWebhook.ps1 +++ b/src/classes/public/Webhooks/GitHubWebhook.ps1 @@ -6,13 +6,13 @@ [string] $GUID # Time when the delivery was delivered. - [datetime] $DeliveredAt + [Nullable[datetime]] $DeliveredAt # Whether the delivery is a redelivery. - [boolean] $Redelivery + [Nullable[boolean]] $Redelivery # Time spent delivering, in seconds. - [double] $Duration + [Nullable[double]] $Duration # Description of the status of the attempted delivery [string] $Status @@ -27,13 +27,13 @@ [string] $Action # The id of the GitHub App installation associated with this event. - [uint64] $InstallationID + [Nullable[uint64]] $InstallationID # The id of the repository associated with this event. - [uint64] $RepositoryID + [Nullable[uint64]] $RepositoryID # Time when the webhook delivery was throttled. - [datetime] $ThrottledAt + [Nullable[datetime]] $ThrottledAt # The URL target of the delivery. [string] $URL diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 index 0a7aba9a4..6b6e77462 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 @@ -52,7 +52,7 @@ @{ ID = $_.id GUID = $_.guid - DeliveredAt = $null -eq $_.delivered_at ? [datetime]::MinValue : [DateTime]::Parse($_.delivered_at) + DeliveredAt = $_.delivered_at Redelivery = $_.redelivery Duration = $_.duration Status = $_.status @@ -61,7 +61,7 @@ Action = $_.action InstallationID = $_.installation.id RepositoryID = $_.repository.id - ThrottledAt = $null -eq $_.throttled_at ? [datetime]::MinValue : [DateTime]::Parse($_.throttled_at) + ThrottledAt = $_.throttled_at URL = $_.url Request = $_.request Response = $_.response diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 index ffb7de548..967d1edf2 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 @@ -47,7 +47,7 @@ @{ ID = $_.id GUID = $_.guid - DeliveredAt = $null -eq $_.delivered_at ? [datetime]::MinValue : [DateTime]::Parse($_.delivered_at) + DeliveredAt = $_.delivered_at Redelivery = $_.redelivery Duration = $_.duration Status = $_.status @@ -56,7 +56,7 @@ Action = $_.action InstallationID = $_.installation.id RepositoryID = $_.repository.id - ThrottledAt = $null -eq $_.throttled_at ? [datetime]::MinValue : [DateTime]::Parse($_.throttled_at) + ThrottledAt = $_.throttled_at URL = $_.url Request = $_.request Response = $_.response From ab6c5e5270fbeead413f658579e4d8e6ad8ab91d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 20 Dec 2024 14:55:48 +0100 Subject: [PATCH 6/8] Add pagination support to GitHub webhook delivery retrieval --- .../Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 index 967d1edf2..1be9aff19 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 @@ -15,11 +15,16 @@ Returns the webhook configuration for the authenticated app. .NOTES - [Get a webhook configuration for an app](https://docs.github.com/rest/apps/webhooks#get-a-webhook-configuration-for-an-app) + [List deliveries for an app webhook](https://docs.github.com/rest/apps/webhooks#list-deliveries-for-an-app-webhook) #> [OutputType([GitHubWebhook[]])] [CmdletBinding()] param( + # The number of results per page (max 100). + [Parameter()] + [ValidateRange(0, 100)] + [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()] @@ -35,10 +40,15 @@ process { try { + $body = @{ + per_page = $PerPage + } + $inputObject = @{ Context = $Context APIEndpoint = '/app/hook/deliveries' Method = 'GET' + Body = $body } Invoke-GitHubAPI @inputObject | ForEach-Object { From c5ee8a697af36b1171718ba160f97fa7a70f4334 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 20 Dec 2024 14:56:13 +0100 Subject: [PATCH 7/8] Remove default value comment for repository activity --- .../Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 index a540209fc..4c4bea32f 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -66,7 +66,6 @@ [string] $Direction = 'desc', # The number of results per page (max 100). - # Default: 30 [Parameter()] [ValidateRange(0, 100)] [int] $PerPage, From d2e9a27af315feeb0b6254d1fc102b1348f8bae9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 20 Dec 2024 14:56:34 +0100 Subject: [PATCH 8/8] Move GitHubWebhook.format.ps1xml and update table headers for improved readability --- .../formats}/GitHubWebhook.format.ps1xml | 91 +++++++++---------- 1 file changed, 45 insertions(+), 46 deletions(-) rename {examples => src/formats}/GitHubWebhook.format.ps1xml (59%) diff --git a/examples/GitHubWebhook.format.ps1xml b/src/formats/GitHubWebhook.format.ps1xml similarity index 59% rename from examples/GitHubWebhook.format.ps1xml rename to src/formats/GitHubWebhook.format.ps1xml index b2dbb4603..c5b96100e 100644 --- a/examples/GitHubWebhook.format.ps1xml +++ b/src/formats/GitHubWebhook.format.ps1xml @@ -9,27 +9,50 @@ - Status - ID - GUID - Event - StatusCode - DeliveredAt - Duration(s) + + + + + + + + + + + + + + + + + + + + + + + + - + if ($_.Status -eq 'ok') { - # Green checkmark - [char]0x2714 + [char]0x2705 + [char]0x200B + } else { + [char]0x274C + [char]0x200B } - else { - # Red heavy ballot X - [char]0x2718 + + + + + + + if ($_.Redelivery -eq 'true') { + "`u{1F504}" } @@ -68,65 +91,41 @@ - + ID - + GUID - + DeliveredAt - + Redelivery - + Duration - + Status - + StatusCode - + Event - + Action - - - InstallationID - - - - RepositoryID - - - - ThrottledAt - - - - URL - - - - Request - - - - Response -