Skip to content

Commit 3d2399c

Browse files
🚀 [Feature]: Added class GitHubAppInstallationRequest and added ToString() method to the GitHubApp class (#409)
## Description This pull request introduces several enhancements to the GitHub App class, including new functionality, renaming for clarity, and updates to existing tests. ### New class: * `GitHubAppInstallationRequest`: Added a new class `GitHubAppInstallationRequest` to represent installation requests for GitHub Apps. This includes properties for the requester, target account, and creation date, along with constructors for initialization. * `Get-GitHubAppInstallationRequest`: Added a new filter `Get-GitHubAppInstallationRequest` to list pending installation requests for the authenticated GitHub App. ### Function renaming for clarity: * `Get-GitHubAppBySlug`: Renamed the private function from `Get-GitHubAppByName` to `Get-GitHubAppBySlug` to better reflect its input. Updated parameter names and internal logic accordingly. ### Updates to existing tests: * `GitHub.Tests.ps1`: Added new test cases for `Get-GitHubAppInstallationRequest` and restored tests for `Get-GitHubApp` to validate fetching an app by slug. ### Minor improvements: * `GitHubApp`: Added a `ToString()` method to return the slug of the GitHub App. * `Get-GitHubApp`: Updated output type to `GitHubApp` and improved parameter handling for pipeline input. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent ed0dc5d commit 3d2399c

File tree

7 files changed

+114
-22
lines changed

7 files changed

+114
-22
lines changed

src/classes/public/App/GitHubApp.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ class GitHubApp : GitHubNode {
6363
$this.Events = , ($Object.events)
6464
$this.Installations = $Object.installations_count
6565
}
66+
67+
[string] ToString() {
68+
return $this.Slug
69+
}
6670
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class GitHubAppInstallationRequest : GitHubNode {
2+
# The user who requested the installation.
3+
[GitHubUser] $RequestedBy
4+
5+
# The target of the installation.
6+
[GitHubOwner] $Target
7+
8+
# The creation date of the installation.
9+
# Example: 2008-01-14T04:33:35Z
10+
[System.Nullable[datetime]] $CreatedAt
11+
12+
GitHubAppInstallationRequest() {}
13+
14+
GitHubAppInstallationRequest([PSCustomObject]$Object) {
15+
$this.ID = $Object.id
16+
$this.NodeID = $Object.node_id
17+
$this.RequestedBy = [GitHubUser]::new($Object.requester)
18+
$this.Target = [GitHubOwner]::new($Object.account)
19+
$this.CreatedAt = $Object.created_at
20+
}
21+
}

src/functions/private/Apps/GitHub Apps/Get-GitHubAppByName.ps1 renamed to src/functions/private/Apps/GitHub Apps/Get-GitHubAppBySlug.ps1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
filter Get-GitHubAppByName {
1+
function Get-GitHubAppBySlug {
22
<#
33
.SYNOPSIS
44
Get an app
@@ -21,8 +21,7 @@
2121
# You can find this on the settings page for your GitHub App (e.g., https://github.com/settings/apps/<app_slug>).
2222
# Example: 'github-actions'
2323
[Parameter(Mandatory)]
24-
[Alias('Name')]
25-
[string] $AppSlug,
24+
[string] $Slug,
2625

2726
# The context to run the command in. Used to get the details for the API call.
2827
[Parameter(Mandatory)]
@@ -37,9 +36,9 @@
3736

3837
process {
3938
$inputObject = @{
40-
Context = $Context
41-
APIEndpoint = "/apps/$AppSlug"
4239
Method = 'GET'
40+
APIEndpoint = "/apps/$Slug"
41+
Context = $Context
4342
}
4443

4544
Invoke-GitHubAPI @inputObject | ForEach-Object {

src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040

4141
process {
4242
$inputObject = @{
43-
Context = $Context
43+
Method = 'GET'
4444
APIEndpoint = '/app/installations'
4545
PerPage = $PerPage
46-
Method = 'GET'
46+
Context = $Context
4747
}
4848

4949
Invoke-GitHubAPI @inputObject | ForEach-Object {

src/functions/public/Apps/GitHub App/Get-GitHubApp.ps1

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@
1616
1717
Get the GitHub App with the slug 'github-actions'.
1818
19-
.NOTES
20-
[Get an app](https://docs.github.com/rest/apps/apps#get-an-app)
21-
[Get the authenticated app | GitHub Docs](https://docs.github.com/rest/apps/apps#get-the-authenticated-app)
19+
.OUTPUTS
20+
GitHubApp
2221
2322
.LINK
2423
https://psmodule.io/GitHub/Functions/Apps/GitHub%20App/Get-GitHubApp
24+
25+
.NOTES
26+
[Get an app](https://docs.github.com/rest/apps/apps#get-an-app)
27+
[Get the authenticated app | GitHub Docs](https://docs.github.com/rest/apps/apps#get-the-authenticated-app)
2528
#>
26-
[OutputType([pscustomobject])]
29+
[OutputType([GitHubApp])]
2730
[CmdletBinding(DefaultParameterSetName = 'Get the authenticated app')]
2831
param(
2932
# The AppSlug is just the URL-friendly name of a GitHub App.
3033
# You can find this on the settings page for your GitHub App (e.g., <https://github.com/settings/apps/{app_slug}>).
3134
# Example: 'github-actions'
3235
[Parameter(
3336
Mandatory,
34-
ParameterSetName = 'Get an app by slug'
37+
ParameterSetName = 'Get an app by slug',
38+
ValueFromPipeline,
39+
ValueFromPipelineByPropertyName
3540
)]
36-
[Alias('AppSlug', 'Slug')]
37-
[string] $Name,
41+
[string] $Slug,
3842

3943
# The context to run the command in. Used to get the details for the API call.
4044
# Can be either a string or a GitHubContext object.
@@ -51,7 +55,7 @@
5155
process {
5256
switch ($PSCmdlet.ParameterSetName) {
5357
'Get an app by slug' {
54-
Get-GitHubAppByName -AppSlug $Name -Context $Context
58+
Get-GitHubAppBySlug -Slug $Slug -Context $Context
5559
}
5660
default {
5761
Get-GitHubAuthenticatedApp -Context $Context
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
filter Get-GitHubAppInstallationRequest {
2+
<#
3+
.SYNOPSIS
4+
List installation requests for the authenticated app.
5+
6+
.DESCRIPTION
7+
Lists all the pending installation requests for the authenticated GitHub App.
8+
9+
.EXAMPLE
10+
Get-GitHubAppInstallationRequest
11+
12+
Lists all the pending installation requests for the authenticated GitHub App.
13+
14+
.NOTES
15+
[List installation requests for the authenticated app](https://docs.github.com/rest/apps/apps#list-installation-requests-for-the-authenticated-app)
16+
17+
.LINK
18+
https://psmodule.io/GitHub/Functions/Apps/GitHub%20App/Get-GitHubAppInstallationRequest
19+
#>
20+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
21+
'PSAvoidLongLines', '', Justification = 'Contains a long link.'
22+
)]
23+
[OutputType([GitHubAppInstallationRequest])]
24+
[CmdletBinding()]
25+
param(
26+
# The context to run the command in. Used to get the details for the API call.
27+
# Can be either a string or a GitHubContext object.
28+
[Parameter()]
29+
[object] $Context
30+
)
31+
32+
begin {
33+
$stackPath = Get-PSCallStackPath
34+
Write-Debug "[$stackPath] - Start"
35+
$Context = Resolve-GitHubContext -Context $Context
36+
Assert-GitHubContext -Context $Context -AuthType APP
37+
}
38+
39+
process {
40+
$inputObject = @{
41+
Method = 'GET'
42+
APIEndpoint = '/app/installation-requests'
43+
Context = $Context
44+
}
45+
46+
Invoke-GitHubAPI @inputObject | ForEach-Object {
47+
$_.Response | ForEach-Object {
48+
[GitHubAppInstallationRequest]::new($_)
49+
}
50+
}
51+
}
52+
53+
end {
54+
Write-Debug "[$stackPath] - End"
55+
}
56+
}

tests/GitHub.Tests.ps1

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,6 @@ Describe 'Apps' {
419419
$app.Events | Should -BeOfType 'string'
420420
$app.Installations | Should -Not -BeNullOrEmpty
421421
}
422-
# It 'Get-GitHubApp - Get an app by slug' {
423-
# $app = Get-GitHubApp -Name 'github-actions'
424-
# LogGroup 'App by slug' {
425-
# Write-Host ($app | Format-Table | Out-String)
426-
# }
427-
# $app | Should -Not -BeNullOrEmpty
428-
# }
429422

430423
It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' {
431424
$jwt = Get-GitHubAppJSONWebToken @connectParams
@@ -435,6 +428,13 @@ Describe 'Apps' {
435428
$jwt | Should -Not -BeNullOrEmpty
436429
}
437430

431+
It 'Get-GitHubAppInstallationRequest - Can get installation requests' {
432+
$installationRequests = Get-GitHubAppInstallationRequest
433+
LogGroup 'Installation requests' {
434+
Write-Host ($installationRequests | Format-List | Out-String)
435+
}
436+
}
437+
438438
It 'Get-GitHubAppInstallation - Can get app installations' {
439439
$installations = Get-GitHubAppInstallation
440440
LogGroup 'Installations' {
@@ -460,6 +460,7 @@ Describe 'Apps' {
460460
$installation.SuspendedBy | Should -BeOfType 'GitHubUser'
461461
}
462462
}
463+
463464
It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' {
464465
$installations = Get-GitHubAppInstallation
465466
LogGroup 'Tokens' {
@@ -525,6 +526,13 @@ Describe 'Apps' {
525526
if ($Type -eq 'GitHub Actions') {}
526527

527528
# Tests for IAT UAT and PAT goes here
529+
It 'Get-GitHubApp - Get an app by slug' {
530+
$app = Get-GitHubApp -Slug 'github-actions'
531+
LogGroup 'App by slug' {
532+
Write-Host ($app | Format-List | Out-String)
533+
}
534+
$app | Should -Not -BeNullOrEmpty
535+
}
528536
}
529537
}
530538

0 commit comments

Comments
 (0)