Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b95f120
Add initial test scripts for GitHub API interactions
MariusStorhaug Jun 10, 2025
5d4e6c2
🪲 [Fix]: Correct parameter set names in `Get-GitHubAppInstallation` f…
MariusStorhaug Jun 10, 2025
6db222e
🩹 [Patch]: Add `PerPage` parameter to `Get-GitHubAppInstallation` and…
MariusStorhaug Jun 10, 2025
ca1871b
🪲 [Fix]: Update references from `target_type` to `Type` and `account`…
MariusStorhaug Jun 10, 2025
faf2a42
🩹 [Patch]: Enhance logging in authentication tests by adding debug an…
MariusStorhaug Jun 10, 2025
f757b43
🩹 [Patch]: Refactor response handling in Get-GitHubAppInstallationFor…
MariusStorhaug Jun 10, 2025
2405ea2
🩹 [Patch]: Fix formatting in GitHubAppInstallation and update output …
MariusStorhaug Jun 10, 2025
c579845
🩹 [Patch]: Improve logging for app installation access tokens by grou…
MariusStorhaug Jun 10, 2025
15eb2f4
🩹 [Enhancement]: Extend GitHubApp class with additional properties an…
MariusStorhaug Jun 10, 2025
7d54226
🩹 [Patch]: Fix property casing for GitHub App attributes in Set-GitHu…
MariusStorhaug Jun 10, 2025
68f76bc
🩹 [Patch]: Rename InstallationsCount property to Installations for co…
MariusStorhaug Jun 10, 2025
95e2260
🩹 [Patch]: Update parameter set names for consistency in Get-GitHubAp…
MariusStorhaug Jun 10, 2025
2b1077b
🩹 [Enhancement]: Refactor GitHub configuration and event data tests t…
MariusStorhaug Jun 10, 2025
48e964a
🩹 [Patch]: Remove AppID null check from GitHubApp tests and update lo…
MariusStorhaug Jun 10, 2025
12398ff
🩹 [Enhancement]: Update event handling in GitHubApp class and improve…
MariusStorhaug Jun 10, 2025
83ecd8c
🩹 [Patch]: Update event assignment in GitHubApp constructor for consi…
MariusStorhaug Jun 10, 2025
d38be5c
🩹 [Fix]: Adjust event assignment in GitHubApp and GitHubAppInstallati…
MariusStorhaug Jun 10, 2025
1347edb
🩹 [Patch]: Update type assertions for Permissions and Events in Apps …
MariusStorhaug Jun 10, 2025
c62f342
Add initial test scripts for GitHub API interactions
MariusStorhaug Jun 10, 2025
18ea816
🩹 [Cleanup]: Remove unnecessary skip configurations from PSModule.yml
MariusStorhaug Jun 10, 2025
32e24b9
asd
MariusStorhaug Jun 11, 2025
0c50725
qwe
MariusStorhaug Jun 11, 2025
b8b7770
asd
MariusStorhaug Jun 12, 2025
bc80b48
wqer
MariusStorhaug Jun 12, 2025
1067c4f
Fix debug
MariusStorhaug Jun 12, 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: 3 additions & 3 deletions examples/Apps/EnterpriseApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ filter Install-GithubApp {
)

process {
$installableOrgs = Get-GitHubOrganization -Enterprise $Enterprise -Debug -Verbose
$installableOrgs = Get-GitHubOrganization -Enterprise $Enterprise
$orgs = $installableOrgs | Where-Object { $_.login -like $organization }
foreach ($org in $orgs) {
foreach ($appIDitem in $AppID) {
Install-GitHubAppOnEnterpriseOrganization -Enterprise $Enterprise -Organization $org.login -ClientID $appIDitem -RepositorySelection all | ForEach-Object {
Install-GitHubApp -Enterprise $Enterprise -Organization $org.login -ClientID $appIDitem -RepositorySelection all | ForEach-Object {
[PSCustomObject]@{
Organization = $org.login
AppID = $appIDitem
Expand All @@ -35,6 +35,6 @@ filter Install-GithubApp {
}
}

$appIDs | Install-GitHubApp -Organization $organization -Debug -Verbose
$appIDs | Install-GitHubApp -Organization $organization

$installation = Get-GitHubAppInstallation
66 changes: 66 additions & 0 deletions src/classes/public/App/GitHubApp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class GitHubApp : GitHubNode {
# The unique ID of the app
[System.Nullable[UInt64]] $ID

# The Client ID of the app
[string] $ClientID

# The App ID of the app
[System.Nullable[UInt64]] $AppID

# The Slug of the app
[string] $Slug

# The node_id of the app
[string] $NodeID

# The owner of the app.
[GitHubOwner] $Owner

# The name of the app
[string] $Name

# The description of the app
[string] $Description

# The external URL of the app
[string] $ExternalUrl

# The HTML URL of the app
[string] $Url

# The creation date of the app
[System.Nullable[datetime]] $CreatedAt

# The last update date of the app
[System.Nullable[datetime]] $UpdatedAt

# The permissions that the app is requesting.
[pscustomobject] $Permissions

# The events that the app is subscribing to on its target.
[string[]] $Events

# The number of installations
[System.Nullable[int]] $Installations

GitHubApp() {}

GitHubApp([object]$Object) {
$this.ID = $Object.id
$this.ClientID = $Object.client_id
$this.AppID = $Object.app_id
$this.Slug = $Object.app_slug ?? $Object.slug
$this.NodeID = $Object.node_id
$this.Owner = [GitHubOwner]::new($Object.owner)
$this.Name = $Object.name
$this.Description = $Object.description
$this.ExternalUrl = $Object.external_url
$this.Url = $Object.html_url
$this.CreatedAt = $Object.created_at
$this.UpdatedAt = $Object.updated_at
$this.Permissions = $Object.permissions
$this.Events = , ($Object.events)
$this.Installations = $Object.installations_count
}
}
63 changes: 63 additions & 0 deletions src/classes/public/App/GitHubAppInstallation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class GitHubAppInstallation {
# The installation ID on the target.
[System.Nullable[UInt64]] $ID

# The app that is installed.
[GitHubApp] $App

# The target of the installation.
[GitHubOwner] $Target

# The type of target.
[string] $Type

# The type of repository selection.
[string] $RepositorySelection

# The permissions that the app has on the target.
[pscustomobject] $Permissions

# The events that the app is subscribing to.
[string[]] $Events

# The file paths that the app has access to.
[string[]] $FilePaths

# The creation date of the installation.
# Example: 2008-01-14T04:33:35Z
[System.Nullable[datetime]] $CreatedAt

# The last update date of the installation.
# Example: 2008-01-14T04:33:35Z
[System.Nullable[datetime]] $UpdatedAt

# The date the installation was suspended.
# Example: 2008-01-14T04:33:35Z
[System.Nullable[datetime]] $SuspendedAt

# The account that suspended the installation.
[GitHubUser] $SuspendedBy

GitHubAppInstallation() {}

GitHubAppInstallation([PSCustomObject]$Object) {
$this.ID = $Object.id
$this.App = [GitHubApp]::new(
[PSCustomObject]@{
client_id = $Object.client_id
app_id = $Object.app_id
app_slug = $Object.app_slug
}
)
$this.Target = [GitHubOwner]::new($Object.account)
$this.Type = $Object.target_type
$this.RepositorySelection = $Object.repository_selection
$this.Permissions = $Object.permissions
$this.Events = , ($Object.events)
$this.FilePaths = $Object.single_file_paths
$this.CreatedAt = $Object.created_at
$this.UpdatedAt = $Object.updated_at
$this.SuspendedAt = $Object.suspended_at
$this.SuspendedBy = [GitHubUser]::new($Object.suspended_by)
}
}
4 changes: 2 additions & 2 deletions src/classes/public/Owner/GitHubOwner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
$this.NodeID = $Object.node_id

# From GitHubOwner
$this.Name = $Object.login
$this.Name = $Object.slug ?? $Object.login
$this.DisplayName = $Object.name
$this.AvatarUrl = $Object.avatar_url
$this.Url = $Object.html_url
$this.Type = $Object.type
$this.Company = $Object.company
$this.Blog = $Object.blog
$this.Blog = $Object.website_url ?? $Object.blog
$this.Location = $Object.location
$this.Email = $Object.email
$this.TwitterUsername = $Object.twitter_username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.NOTES
[Get an app](https://docs.github.com/rest/apps/apps#get-an-app)
#>
[OutputType([pscustomobject])]
[OutputType([GitHubApp])]
[CmdletBinding()]
param(
# The AppSlug is just the URL-friendly name of a GitHub App.
Expand Down Expand Up @@ -43,7 +43,7 @@
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
[GitHubApp]::new($_.Response)
}
}
end {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
.EXAMPLE
Get-GitHubAppInstallableOrganization -Enterprise 'msx'

.OUTPUTS
GitHubOrganization[]

.LINK
https://psmodule.io/GitHub/Functions/Apps/GitHub%20App/Get-GitHubAppInstallableOrganization
#>
[OutputType([GitHubOrganization[]])]
[CmdletBinding()]
param(
# The enterprise slug or ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@

List installations for the authenticated app.

.OUTPUTS
GitHubAppInstallation[]

.NOTES
[List installations for the authenticated app](https://docs.github.com/rest/apps/apps#list-installations-for-the-authenticated-app)
#>
[OutputType([GitHubAppInstallation])]
[CmdletBinding()]
param(
# The number of results per page (max 100).
[Parameter()]
[System.Nullable[int]] $PerPage,

# The context to run the command in. Used to get the details for the API call.
[Parameter(Mandatory)]
[object] $Context
Expand All @@ -34,11 +42,14 @@
$inputObject = @{
Context = $Context
APIEndpoint = '/app/installations'
PerPage = $PerPage
Method = 'GET'
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
$_.Response | ForEach-Object {
[GitHubAppInstallation]::new($_)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
.NOTES
[Get the authenticated app](https://docs.github.com/rest/apps/apps#get-an-app)
#>
[OutputType([pscustomobject])]
[OutputType([GitHubApp])]
[CmdletBinding()]
param(
# The context to run the command in. Used to get the details for the API call.
Expand All @@ -42,7 +42,7 @@
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
[GitHubApp]::new($_.Response)
}
}
end {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.NOTES
[List GitHub Apps installed on an enterprise-owned organization]()
#>
[OutputType([pscustomobject])]
[OutputType([GitHubAppInstallation])]
[CmdletBinding()]
param(
# The enterprise slug or ID.
Expand Down Expand Up @@ -58,7 +58,7 @@
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
[GitHubAppInstallation]::new($_.Response)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.NOTES
[List app installations for an organization](https://docs.github.com/rest/orgs/orgs#list-app-installations-for-an-organization)
#>
[OutputType([pscustomobject])]
[OutputType([GitHubAppInstallation])]
[CmdletBinding()]
param(
# The organization name. The name is not case sensitive.
Expand Down Expand Up @@ -50,7 +50,9 @@
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response.installations
$_.Response.installations | ForEach-Object {
[GitHubAppInstallation]::new($_)
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/functions/private/Auth/Context/Set-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
if ([string]::IsNullOrEmpty($contextObj['DisplayName'])) {
try {
$app = Get-GitHubApp -Name $contextObj['Username'] -Context $contextObj
$contextObj['DisplayName'] = [string]$app.name
$contextObj['DisplayName'] = [string]$app.Name
} catch {
Write-Debug "Failed to get the GitHub App with the slug: [$($contextObj['Username'])]."
}
Expand Down Expand Up @@ -122,15 +122,15 @@
}
'App' {
$app = Get-GitHubApp -Context $contextObj
$contextObj['Name'] = "$($contextObj['HostName'])/$($app.slug)"
$contextObj['DisplayName'] = [string]$app.name
$contextObj['Username'] = [string]$app.slug
$contextObj['NodeID'] = [string]$app.node_id
$contextObj['DatabaseID'] = [string]$app.id
$contextObj['Permissions'] = [PSCustomObject]$app.permissions
$contextObj['Events'] = [string[]]$app.events
$contextObj['OwnerName'] = [string]$app.owner.login
$contextObj['OwnerType'] = [string]$app.owner.type
$contextObj['Name'] = "$($contextObj['HostName'])/$($app.Slug)"
$contextObj['DisplayName'] = [string]$app.Name
$contextObj['Username'] = [string]$app.Slug
$contextObj['NodeID'] = [string]$app.NodeID
$contextObj['DatabaseID'] = [string]$app.ID
$contextObj['Permissions'] = [PSCustomObject]$app.Permissions
$contextObj['Events'] = [string[]]$app.Events
$contextObj['OwnerName'] = [string]$app.Owner.Name
$contextObj['OwnerType'] = [string]$app.Owner.Type
$contextObj['Type'] = 'App'
}
default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@

Get the repositories that can be made accessible to a GitHub App installed on the organization 'PSModule' in the enterprise 'msx'.

.OUTPUTS
GitHubRepository[]

.LINK
https://psmodule.io/GitHub/Functions/Apps/GitHub%20App%20Installations/Get-GitHubAppAccessibleRepository

.NOTES

#>
[OutputType([GitHubRepository[]])]
[CmdletBinding(SupportsShouldProcess)]
param(
# The enterprise slug or ID.
Expand Down Expand Up @@ -65,7 +72,7 @@
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
[GitHubRepository]::($_.Response)
}
}

Expand Down
Loading