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 + } +} diff --git a/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 b/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 new file mode 100644 index 000000000..ea37d84ab --- /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 + } +}