From e722ddc88dd2b841d8df86ca8d0645d7aa3dd216 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 4 Nov 2024 23:28:10 +0100 Subject: [PATCH 1/5] Add Get-GitHubEnterpriseInstallableOrganization function to retrieve installable organizations for GitHub Apps --- ...tHubEnterpriseInstallableOrganizations.ps1 | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganizations.ps1 diff --git a/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganizations.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganizations.ps1 new file mode 100644 index 000000000..5b1dd7684 --- /dev/null +++ b/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganizations.ps1 @@ -0,0 +1,29 @@ +function Get-GitHubEnterpriseInstallableOrganization { + <# + .SYNOPSIS + Get enterprise-owned organizations that can have GitHub Apps installed + + .DESCRIPTION + List of organizations owned by the enterprise on which the authenticated GitHub App installation may install other GitHub Apps. + + The authenticated GitHub App must be installed on the enterprise and be granted the Enterprise/enterprise_organization_installations + (read) permission. + + .EXAMPLE + Get-GitHubEnterpriseInstallableOrganization -Enterprise 'msx' + #> + [CmdletBinding()] + param( + # The enterprise slug or id. + [Parameter(Mandatory)] + [string] $Enterprise + ) + $inputObject = @{ + APIEndpoint = "/enterprises/$Enterprise/apps/installable_organizations" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From 6f85386af472bcc3d9d367320f6da3a0b5d39f69 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 4 Nov 2024 23:28:23 +0100 Subject: [PATCH 2/5] Add Install-GitHubAppOnEnterpriseOrganization function to install apps on enterprise organizations --- ...tall-GitHubAppOnEnterpriseOrganization.ps1 | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 diff --git a/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 b/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 new file mode 100644 index 000000000..117fd79c7 --- /dev/null +++ b/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 @@ -0,0 +1,56 @@ +function Install-GitHubAppOnEnterpriseOrganization { + <# + .SYNOPSIS + Install an app on an Enterprise-owned organization + + .DESCRIPTION + Installs the provided GitHub App on the specified organization owned by the enterprise. + + The authenticated GitHub App must be installed on the enterprise and be granted the Enterprise/organization_installations (write) permission. + + .EXAMPLE + Install-GitHubAppOnEnterpriseOrganization -Enterprise 'msx' -Organization 'org' -ClientID '123456' + #> + [CmdletBinding()] + param( + # The enterprise slug or id. + [Parameter(Mandatory)] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Organization, + + # The client ID of the GitHub App to install. + [Parameter(Mandatory)] + [string] $ClientID, + + # The repository selection for the GitHub App. Can be one of: + # - all - all repositories that the authenticated GitHub App installation can access. + # - selected - select specific repositories. + [Parameter()] + [ValidateSet('all', 'selected')] + [string] $RepositorySelection = 'all', + + # The names of the repositories to which the installation will be granted access. + [Parameter()] + [string[]] $Repositories + ) + + $body = @{ + client_id = $ClientID + repository_selection = $RepositorySelection + repositories = $Repositories + } + $body | Remove-HashtableEntry -NullOrEmptyValues + + $inputObject = @{ + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations" + Method = 'Post' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From da1339137605a60a6083ea6c55bd7731ed1c4b26 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 4 Nov 2024 23:34:13 +0100 Subject: [PATCH 3/5] Fix --- .../Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 b/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 index 117fd79c7..ea37d84ab 100644 --- a/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 +++ b/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 @@ -13,7 +13,7 @@ #> [CmdletBinding()] param( - # The enterprise slug or id. + # The enterprise slug or ID. [Parameter(Mandatory)] [string] $Enterprise, From e5fcaaa9dabbb4395576d4ac88df5dec0f1b3c26 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 4 Nov 2024 23:57:40 +0100 Subject: [PATCH 4/5] Fix command name --- ...ations.ps1 => Get-GitHubEnterpriseInstallableOrganization.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/functions/public/Enterprise/{Get-GitHubEnterpriseInstallableOrganizations.ps1 => Get-GitHubEnterpriseInstallableOrganization.ps1} (100%) diff --git a/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganizations.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 similarity index 100% rename from src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganizations.ps1 rename to src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 From 8bd3682247befeb0c0ac4180490b6dd623fbbd2b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 5 Nov 2024 00:02:44 +0100 Subject: [PATCH 5/5] Fix --- .../Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 index 5b1dd7684..b973c0467 100644 --- a/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 +++ b/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 @@ -14,7 +14,7 @@ #> [CmdletBinding()] param( - # The enterprise slug or id. + # The enterprise slug or ID. [Parameter(Mandatory)] [string] $Enterprise )