From 66a92bfa0ace42808e14c75439f7cfee6f823e48 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Jun 2025 16:03:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20URL=20generatio?= =?UTF-8?q?n=20and=20default=20formatting=20for=20GitHubAppInstallations?= =?UTF-8?q?=20(#443)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pull request introduces enhancements to the `GitHubAppInstallation` class, updates related functions to support new features, and adds a new format configuration for displaying `GitHubAppInstallation` objects. The changes improve the handling of URLs, streamline object creation, and enhance the output formatting for better usability. - Fixes #442 ### Enhancements to `GitHubAppInstallation` class: * Added a new `$Url` property to store the profile URL of the target based on its type, and updated the constructor to populate this property using `html_url` from the API response. * Modified the `$Target` property to include `Name`, `Type`, and `Url`, dynamically constructing the URL based on the `HostName` parameter. * Updated the `$Url` property to provide a direct link to the installation settings page using the `HostName`, `Type`, and `Target`. ### Format configuration for `GitHubAppInstallation`: * Added a new XML-based format file to define table and list views for `GitHubAppInstallation` objects. The table view includes hyperlinks for `ID` and `Target.Name` when supported, and the list view includes all relevant properties such as `Url`, `Permissions`, and `Events`. ### Updates to related functions: * Updated `Get-GitHubEnterpriseOrganizationAppInstallation` to pass the `HostName` parameter when creating `GitHubAppInstallation` objects, and defined the `.OUTPUTS` section to specify the output type. * Updated `Get-GitHubOrganizationAppInstallation` to define the `.OUTPUTS` section, specifying that the function outputs `GitHubAppInstallation` objects. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> Co-authored-by: Marius Storhaug --- .../public/App/GitHubAppInstallation.ps1 | 13 +- .../GitHubAppInstallation.Format.ps1xml | 124 ++++++++++++++++++ ...bEnterpriseOrganizationAppInstallation.ps1 | 7 +- .../Get-GitHubOrganizationAppInstallation.ps1 | 3 + 4 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/formats/GitHubAppInstallation.Format.ps1xml diff --git a/src/classes/public/App/GitHubAppInstallation.ps1 b/src/classes/public/App/GitHubAppInstallation.ps1 index c0071d3ad..5335e4830 100644 --- a/src/classes/public/App/GitHubAppInstallation.ps1 +++ b/src/classes/public/App/GitHubAppInstallation.ps1 @@ -38,6 +38,9 @@ # The account that suspended the installation. [GitHubUser] $SuspendedBy + # The URL to the target's profile based on the target type. + [string] $Url + GitHubAppInstallation() {} GitHubAppInstallation([PSCustomObject] $Object) { @@ -59,9 +62,10 @@ $this.UpdatedAt = $Object.updated_at $this.SuspendedAt = $Object.suspended_at $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) + $this.Url = $Object.html_url } - GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type) { + GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) { $this.ID = $Object.id $this.App = [GitHubApp]::new( [PSCustomObject]@{ @@ -70,7 +74,11 @@ app_slug = $Object.app_slug } ) - $this.Target = [GitHubOwner]::new($Target) + $this.Target = [GitHubOwner]@{ + Name = $Target + Type = $Type + Url = "https://$HostName/$Target" + } $this.Type = $Type $this.RepositorySelection = $Object.repository_selection $this.Permissions = $Object.permissions @@ -80,5 +88,6 @@ $this.UpdatedAt = $Object.updated_at $this.SuspendedAt = $Object.suspended_at $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) + $this.Url = "https://$HostName/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" } } diff --git a/src/formats/GitHubAppInstallation.Format.ps1xml b/src/formats/GitHubAppInstallation.Format.ps1xml new file mode 100644 index 000000000..876cc43b7 --- /dev/null +++ b/src/formats/GitHubAppInstallation.Format.ps1xml @@ -0,0 +1,124 @@ + + + + + GitHubAppInstallationTable + + GitHubAppInstallation + + + + + + + + + + + + + + + + + + + + + + + + + + + + if ($Host.UI.SupportsVirtualTerminal -and + ($env:GITHUB_ACTIONS -ne 'true')) { + $PSStyle.FormatHyperlink($_.ID,$_.Url) + } else { + $_.ID + } + + + + $_.App.Slug + + + + if ($Host.UI.SupportsVirtualTerminal -and + ($env:GITHUB_ACTIONS -ne 'true')) { + $PSStyle.FormatHyperlink($_.Target.Name,$_.Target.Url) + } else { + $_.Target.Name + } + + + + Type + + + CreatedAt + + + UpdatedAt + + + + + + + + GitHubAppInstallationList + + GitHubAppInstallation + + + + + + + ID + + + App + + + Target + + + Type + + + Url + + + RepositorySelection + + + Permissions + + + Events + + + FilePaths + + + CreatedAt + + + UpdatedAt + + + SuspendedAt + + + SuspendedBy + + + + + + + + diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 index 79b2f94d5..4609f1fe1 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -13,6 +13,9 @@ Gets all GitHub Apps in the organization `github` in the enterprise `msx`. + .OUTPUTS + GitHubAppInstallation + .NOTES [List GitHub Apps installed on an enterprise-owned organization]() #> @@ -58,8 +61,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - foreach ($installation in $_.Response.installations) { - [GitHubAppInstallation]::new($installation, $Organization, 'Organization') + foreach ($installation in $_.Response) { + [GitHubAppInstallation]::new($installation, $Organization, 'Organization', $context.HostName) } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 index 5c63a6866..5df95b3fd 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 @@ -12,6 +12,9 @@ Gets all GitHub Apps in the organization `github`. + .OUTPUTS + GitHubAppInstallation + .NOTES [List app installations for an organization](https://docs.github.com/rest/orgs/orgs#list-app-installations-for-an-organization) #>