Skip to content

Commit 3b31737

Browse files
🚀 [Refactor]: Update GitHubAppInstallation constructor to use hashtable for property assignment; enhance GitHubAppContext to handle null permissions and app objects; improve parameter sets in Get-GitHubAppInstallation function for clarity.
1 parent 7e39c35 commit 3b31737

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848

4949
GitHubAppInstallation([PSCustomObject] $Object) {
5050
$this.ID = $Object.id
51-
$this.App = [GitHubApp]::new()
52-
$this.App.ClientID = $Object.client_id
53-
$this.App.Slug = $Object.app_slug
51+
$this.App = [GitHubApp]@{
52+
ClientID = $Object.client_id
53+
Slug = $Object.app_slug
54+
}
5455
$this.Target = [GitHubOwner]::new($Object.account)
5556
$this.Type = $Object.target_type
5657
$this.RepositorySelection = $Object.repository_selection
@@ -84,9 +85,10 @@
8485

8586
GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) {
8687
$this.ID = $Object.id
87-
$this.App = [GitHubApp]::new()
88-
$this.App.ClientID = $Object.client_id
89-
$this.App.Slug = $Object.app_slug
88+
$this.App = [GitHubApp]@{
89+
ClientID = $Object.client_id
90+
Slug = $Object.app_slug
91+
}
9092
$this.Target = [GitHubOwner]@{
9193
Name = $Target
9294
Type = $Type

‎src/classes/public/Context/GitHubContext/GitHubAppContext.ps1‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@
5050
$this.KeyVaultKeyReference = $Object.KeyVaultKeyReference
5151
$this.OwnerName = $Object.OwnerName
5252
$this.OwnerType = $Object.OwnerType
53-
$this.Permissions = [GitHubPermission]::NewPermissionList($Object.Permissions)
53+
if ($Object.Permissions) {
54+
$this.Permissions = [GitHubPermission]::NewPermissionList($Object.Permissions)
55+
}
5456
$this.Events = , ($Object.Events)
55-
$this.App = [GitHubApp]::New($Object.App)
57+
if ($Object.App) {
58+
$this.App = [GitHubApp]::New($Object.App)
59+
}
5660
}
5761
}

‎src/functions/private/Auth/Context/Set-GitHubContext.ps1‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@
4444
}
4545

4646
process {
47-
Write-Debug 'Context:'
48-
$contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ }
47+
if ($DebugPreference -eq 'Continue') {
48+
Write-Debug 'Context:'
49+
$contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ }
50+
Write-Debug "Getting info on the context [$($contextObj['AuthType'])]."
51+
}
4952

5053
# Run functions to get info on the temporary context.
5154
try {
52-
Write-Debug "Getting info on the context [$($contextObj['AuthType'])]."
5355
switch -Regex (($contextObj['AuthType'])) {
5456
'PAT|UAT|IAT' {
5557
$viewer = Get-GitHubViewer -Context $contextObj
@@ -79,9 +81,9 @@
7981
try {
8082
$app = Get-GitHubApp -Slug $contextObj['Username'] -Context $contextObj
8183
$contextObj['DisplayName'] = [string]$app.Name
82-
# TODO: $contextObj['App'] = $app
84+
$contextObj['App'] = $app
8385
} catch {
84-
Write-Warning "Failed to get the GitHub App with the slug: [$($contextObj['Username'])]."
86+
Write-Warning "Unable to get the GitHub App: [$($contextObj['Username'])]."
8587
}
8688
}
8789
if ($script:IsGitHubActions) {
@@ -114,12 +116,9 @@
114116
if ([string]::IsNullOrEmpty($contextObj['InstallationName'])) {
115117
$contextObj['InstallationName'] = [string]$installationName
116118
}
117-
$contextObj['Name'] = "$($contextObj['HostName'])/$($contextObj['Username'])/" +
118-
"$($contextObj['InstallationType'])/$($contextObj['InstallationName'])"
119-
} else {
120-
$contextObj['Name'] = "$($contextObj['HostName'])/$($contextObj['Username'])/" +
121-
"$($contextObj['InstallationType'])/$($contextObj['InstallationName'])"
122119
}
120+
$contextObj['Name'] = "$($contextObj['HostName'])/$($contextObj['Username'])/" +
121+
"$($contextObj['InstallationType'])/$($contextObj['InstallationName'])"
123122
}
124123
'App' {
125124
$app = Get-GitHubApp -Context $contextObj
@@ -132,18 +131,20 @@
132131
$contextObj['Events'] = [string[]]$app.Events
133132
$contextObj['OwnerName'] = [string]$app.Owner.Name
134133
$contextObj['OwnerType'] = [string]$app.Owner.Type
135-
$contextObj['App'] = $app
134+
$contextObj['App'] = [GitHubApp]$app
136135
$contextObj['Type'] = 'App'
137136
}
138137
default {
139138
throw 'Failed to get info on the context. Unknown logon type.'
140139
}
141140
}
142-
Write-Debug "Found [$($contextObj['Type'])] with login: [$($contextObj['Name'])]"
143-
$contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ }
144-
Write-Debug '----------------------------------------------------'
145-
if ($PSCmdlet.ShouldProcess('Context', 'Set')) {
141+
if ($DebugPreference -eq 'Continue') {
142+
Write-Debug "Found [$($contextObj['Type'])] with login: [$($contextObj['Name'])]"
143+
$contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ }
144+
Write-Debug '----------------------------------------------------'
146145
Write-Debug "Saving context: [$($contextObj['Name'])]"
146+
}
147+
if ($PSCmdlet.ShouldProcess('Context', 'Set')) {
147148
Set-Context -ID $($contextObj['Name']) -Context $contextObj -Vault $script:GitHub.ContextVault
148149
if ($Default) {
149150
Switch-GitHubContext -Context $contextObj['Name']

‎src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
[int] $ID,
4646

4747
# The number of results per page (max 100).
48-
[Parameter()]
48+
[Parameter(ParameterSetName = 'List installations for the authenticated app')]
49+
[Parameter(ParameterSetName = 'List installations on an Enterprise Organization')]
50+
[Parameter(ParameterSetName = 'List installations on an Organization')]
4951
[System.Nullable[int]] $PerPage,
5052

5153
# The context to run the command in. Used to get the details for the API call.
@@ -80,12 +82,12 @@
8082
}
8183
Get-GitHubAppInstallationForOrganization @params
8284
}
83-
'Get installation for the authenticated app by ID' {
84-
Get-GitHubAppInstallationForAuthenticatedAppByID -ID $ID -Context $Context
85-
}
8685
'List installations for the authenticated app' {
8786
Get-GitHubAppInstallationForAuthenticatedAppAsList @params
8887
}
88+
'Get installation for the authenticated app by ID' {
89+
Get-GitHubAppInstallationForAuthenticatedAppByID -ID $ID -Context $Context
90+
}
8991
}
9092
}
9193

0 commit comments

Comments
 (0)