Skip to content

Commit 66a92bf

Browse files
🩹 [Patch]: Add URL generation and default formatting for GitHubAppInstallations (#443)
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 <marstor@hotmail.com>
1 parent b220468 commit 66a92bf

File tree

4 files changed

+143
-4
lines changed

4 files changed

+143
-4
lines changed

‎src/classes/public/App/GitHubAppInstallation.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
# The account that suspended the installation.
3939
[GitHubUser] $SuspendedBy
4040

41+
# The URL to the target's profile based on the target type.
42+
[string] $Url
43+
4144
GitHubAppInstallation() {}
4245

4346
GitHubAppInstallation([PSCustomObject] $Object) {
@@ -59,9 +62,10 @@
5962
$this.UpdatedAt = $Object.updated_at
6063
$this.SuspendedAt = $Object.suspended_at
6164
$this.SuspendedBy = [GitHubUser]::new($Object.suspended_by)
65+
$this.Url = $Object.html_url
6266
}
6367

64-
GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type) {
68+
GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) {
6569
$this.ID = $Object.id
6670
$this.App = [GitHubApp]::new(
6771
[PSCustomObject]@{
@@ -70,7 +74,11 @@
7074
app_slug = $Object.app_slug
7175
}
7276
)
73-
$this.Target = [GitHubOwner]::new($Target)
77+
$this.Target = [GitHubOwner]@{
78+
Name = $Target
79+
Type = $Type
80+
Url = "https://$HostName/$Target"
81+
}
7482
$this.Type = $Type
7583
$this.RepositorySelection = $Object.repository_selection
7684
$this.Permissions = $Object.permissions
@@ -80,5 +88,6 @@
8088
$this.UpdatedAt = $Object.updated_at
8189
$this.SuspendedAt = $Object.suspended_at
8290
$this.SuspendedBy = [GitHubUser]::new($Object.suspended_by)
91+
$this.Url = "https://$HostName/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)"
8392
}
8493
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Configuration>
3+
<ViewDefinitions>
4+
<View>
5+
<Name>GitHubAppInstallationTable</Name>
6+
<ViewSelectedBy>
7+
<TypeName>GitHubAppInstallation</TypeName>
8+
</ViewSelectedBy>
9+
<TableControl>
10+
<TableHeaders>
11+
<TableColumnHeader>
12+
<Label>ID</Label>
13+
</TableColumnHeader>
14+
<TableColumnHeader>
15+
<Label>App</Label>
16+
</TableColumnHeader>
17+
<TableColumnHeader>
18+
<Label>Target</Label>
19+
</TableColumnHeader>
20+
<TableColumnHeader>
21+
<Label>Type</Label>
22+
</TableColumnHeader>
23+
<TableColumnHeader>
24+
<Label>CreatedAt</Label>
25+
</TableColumnHeader>
26+
<TableColumnHeader>
27+
<Label>UpdatedAt</Label>
28+
</TableColumnHeader>
29+
</TableHeaders>
30+
<TableRowEntries>
31+
<TableRowEntry>
32+
<TableColumnItems>
33+
<TableColumnItem>
34+
<ScriptBlock>
35+
if ($Host.UI.SupportsVirtualTerminal -and
36+
($env:GITHUB_ACTIONS -ne 'true')) {
37+
$PSStyle.FormatHyperlink($_.ID,$_.Url)
38+
} else {
39+
$_.ID
40+
}
41+
</ScriptBlock>
42+
</TableColumnItem>
43+
<TableColumnItem>
44+
<ScriptBlock>$_.App.Slug</ScriptBlock>
45+
</TableColumnItem>
46+
<TableColumnItem>
47+
<ScriptBlock>
48+
if ($Host.UI.SupportsVirtualTerminal -and
49+
($env:GITHUB_ACTIONS -ne 'true')) {
50+
$PSStyle.FormatHyperlink($_.Target.Name,$_.Target.Url)
51+
} else {
52+
$_.Target.Name
53+
}
54+
</ScriptBlock>
55+
</TableColumnItem>
56+
<TableColumnItem>
57+
<PropertyName>Type</PropertyName>
58+
</TableColumnItem>
59+
<TableColumnItem>
60+
<PropertyName>CreatedAt</PropertyName>
61+
</TableColumnItem>
62+
<TableColumnItem>
63+
<PropertyName>UpdatedAt</PropertyName>
64+
</TableColumnItem>
65+
</TableColumnItems>
66+
</TableRowEntry>
67+
</TableRowEntries>
68+
</TableControl>
69+
</View>
70+
<View>
71+
<Name>GitHubAppInstallationList</Name>
72+
<ViewSelectedBy>
73+
<TypeName>GitHubAppInstallation</TypeName>
74+
</ViewSelectedBy>
75+
<ListControl>
76+
<ListEntries>
77+
<ListEntry>
78+
<ListItems>
79+
<ListItem>
80+
<PropertyName>ID</PropertyName>
81+
</ListItem>
82+
<ListItem>
83+
<PropertyName>App</PropertyName>
84+
</ListItem>
85+
<ListItem>
86+
<PropertyName>Target</PropertyName>
87+
</ListItem>
88+
<ListItem>
89+
<PropertyName>Type</PropertyName>
90+
</ListItem>
91+
<ListItem>
92+
<PropertyName>Url</PropertyName>
93+
</ListItem>
94+
<ListItem>
95+
<PropertyName>RepositorySelection</PropertyName>
96+
</ListItem>
97+
<ListItem>
98+
<PropertyName>Permissions</PropertyName>
99+
</ListItem>
100+
<ListItem>
101+
<PropertyName>Events</PropertyName>
102+
</ListItem>
103+
<ListItem>
104+
<PropertyName>FilePaths</PropertyName>
105+
</ListItem>
106+
<ListItem>
107+
<PropertyName>CreatedAt</PropertyName>
108+
</ListItem>
109+
<ListItem>
110+
<PropertyName>UpdatedAt</PropertyName>
111+
</ListItem>
112+
<ListItem>
113+
<PropertyName>SuspendedAt</PropertyName>
114+
</ListItem>
115+
<ListItem>
116+
<PropertyName>SuspendedBy</PropertyName>
117+
</ListItem>
118+
</ListItems>
119+
</ListEntry>
120+
</ListEntries>
121+
</ListControl>
122+
</View>
123+
</ViewDefinitions>
124+
</Configuration>

‎src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
1414
Gets all GitHub Apps in the organization `github` in the enterprise `msx`.
1515
16+
.OUTPUTS
17+
GitHubAppInstallation
18+
1619
.NOTES
1720
[List GitHub Apps installed on an enterprise-owned organization]()
1821
#>
@@ -58,8 +61,8 @@
5861
}
5962

6063
Invoke-GitHubAPI @inputObject | ForEach-Object {
61-
foreach ($installation in $_.Response.installations) {
62-
[GitHubAppInstallation]::new($installation, $Organization, 'Organization')
64+
foreach ($installation in $_.Response) {
65+
[GitHubAppInstallation]::new($installation, $Organization, 'Organization', $context.HostName)
6366
}
6467
}
6568
}

‎src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
1313
Gets all GitHub Apps in the organization `github`.
1414
15+
.OUTPUTS
16+
GitHubAppInstallation
17+
1518
.NOTES
1619
[List app installations for an organization](https://docs.github.com/rest/orgs/orgs#list-app-installations-for-an-organization)
1720
#>

0 commit comments

Comments
 (0)