Skip to content

Commit 78ff374

Browse files
🩹 [Patch]: Widen availability of URL for GitHubOrganization (#453)
## Description This pull request introduces a new `HostName` parameter to the `GitHubOrganization` class constructor and updates its usage across various functions. The changes ensure that the `Url` property of `GitHubOrganization` objects can dynamically include the hostname when constructing URLs. Additionally, minor error handling improvements were made in one function. ### Updates to `GitHubOrganization` class constructor: * [`src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1`](diffhunk://#diff-ee1cc4e59ef0d0762f150872a9fc2f78c80e9f3d5ce713b9e617fdbaeda48093L139-R139): Added a `HostName` parameter to the `GitHubOrganization` constructor and updated the `Url` property to include the hostname dynamically if provided. [[1]](diffhunk://#diff-ee1cc4e59ef0d0762f150872a9fc2f78c80e9f3d5ce713b9e617fdbaeda48093L139-R139) [[2]](diffhunk://#diff-ee1cc4e59ef0d0762f150872a9fc2f78c80e9f3d5ce713b9e617fdbaeda48093L148-R148) ### Updates to functions using `GitHubOrganization`: * [`src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1`](diffhunk://#diff-0a1f53a3d172fea0035dcdd32a8ca1bfa0441e91f0727c44591b3448b8c9542aL55-R55): Updated calls to the `GitHubOrganization` constructor to pass the `HostName` parameter from the `$Context` object. * `src/functions/private/Organization/Get-GitHubAllOrganization.ps1`, `src/functions/private/Organization/Get-GitHubMyOrganization.ps1`, `src/functions/private/Organization/Get-GitHubUserOrganization.ps1`: Updated calls to the `GitHubOrganization` constructor to pass the `HostName` parameter from the `$Context` object. [[1]](diffhunk://#diff-88b7f49464570f7937d5c2148aed56483c01eb5afaff12cc2ba8c0be9b723e6eL61-R61) [[2]](diffhunk://#diff-e068816595f1abcde1a1fcfa9a80805a5302dadab28d14bd17a224e1f0264352L56-R56) [[3]](diffhunk://#diff-c730abb0f5d97cb7dfd8dfb1aedd31839de272c3f4e714f70f6db26882504e52L58-R60) * `src/functions/private/Organization/Get-GitHubOrganizationByName.ps1`, `src/functions/private/Users/Get-GitHubAllUser.ps1`, `src/functions/public/Organization/Update-GitHubOrganization.ps1`: Updated calls to the `GitHubOrganization` constructor to pass an empty string as the `HostName` parameter when context is unavailable. [[1]](diffhunk://#diff-83fe1cc74ed99f4410b85163cff6dd65affd068817289729bba8aaebb88ec3b7L59-R59) [[2]](diffhunk://#diff-a06e292f87831c3c28fe840f4e7e832f3c5f79043bee587a9e36edbcf13a4ddaL63-R63) [[3]](diffhunk://#diff-eeb2f01e72cb4d2e7bc3bc35152d71f146c8d558aee15fa170031b8f443e17c8L207-R207) ### Error handling improvement: * [`src/functions/private/Users/Get-GitHubUserByName.ps1`](diffhunk://#diff-a2d6056b06ab6b0d2cb714b430a71c01e3ead9c5f890a342379b6969d422c43bR62-R72): Added a `try-catch` block around the `Invoke-GitHubAPI` call to handle potential errors gracefully. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 8e7b3d6 commit 78ff374

File tree

10 files changed

+23
-17
lines changed

10 files changed

+23
-17
lines changed

src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136

137137
GitHubOrganization() {}
138138

139-
GitHubOrganization([PSCustomObject]$Object) {
139+
GitHubOrganization([PSCustomObject] $Object, [string] $HostName) {
140140
# From GitHubNode
141141
$this.ID = $Object.id
142142
$this.NodeID = $Object.node_id
@@ -145,7 +145,7 @@
145145
$this.Name = $Object.login
146146
$this.DisplayName = $Object.name
147147
$this.AvatarUrl = $Object.avatar_url
148-
$this.Url = $Object.html_url
148+
$this.Url = $Object.html_url ?? "https://$($HostName)/$($Object.login)"
149149
$this.Type = $Object.type
150150
$this.Company = $Object.company
151151
$this.Blog = $Object.blog

src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
Invoke-GitHubAPI @inputObject | ForEach-Object {
5454
foreach ($organization in $_.Response) {
55-
[GitHubOrganization]::new($organization)
55+
[GitHubOrganization]::new($organization, $Context.HostName)
5656
}
5757
}
5858
}

src/functions/private/Organization/Get-GitHubAllOrganization.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
}
5959

6060
Invoke-GitHubAPI @inputObject | ForEach-Object {
61-
$_.Response | ForEach-Object { [GitHubOrganization]::new($_) }
61+
$_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context.HostName) }
6262
}
6363
}
6464
end {

src/functions/private/Organization/Get-GitHubMyOrganization.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
}
5454

5555
Invoke-GitHubAPI @inputObject | ForEach-Object {
56-
$_.Response | ForEach-Object { [GitHubOrganization]::new($_) }
56+
$_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context.HostName) }
5757
}
5858
}
5959

src/functions/private/Organization/Get-GitHubOrganizationByName.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
}
5757

5858
Invoke-GitHubAPI @inputObject | ForEach-Object {
59-
[GitHubOrganization]::new($_.Response)
59+
[GitHubOrganization]::new($_.Response, '')
6060
}
6161
}
6262
end {

src/functions/private/Organization/Get-GitHubUserOrganization.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
}
5656

5757
Invoke-GitHubAPI @inputObject | ForEach-Object {
58-
$_.Response | ForEach-Object { [GitHubOrganization]::new($_) }
58+
foreach ($org in $_.Response) {
59+
[GitHubOrganization]::new($org, $Context.HostName)
60+
}
5961
}
6062
}
6163
end {

src/functions/private/Users/Get-GitHubAllUser.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Invoke-GitHubAPI @inputObject | ForEach-Object {
6161
$_.Response | ForEach-Object {
6262
if ($_.type -eq 'Organization') {
63-
[GitHubOrganization]::New($_)
63+
[GitHubOrganization]::New($_, '')
6464
} elseif ($_.type -eq 'User') {
6565
[GitHubUser]::New($_)
6666
} else {

src/functions/private/Users/Get-GitHubMyUser.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
Invoke-GitHubAPI @inputObject | ForEach-Object {
4646
if ($_.Response.type -eq 'Organization') {
47-
[GitHubOrganization]::New($_.Response)
47+
[GitHubOrganization]::New($_.Response, $Context.HostName)
4848
} elseif ($_.Response.type -eq 'User') {
4949
[GitHubUser]::New($_.Response)
5050
} else {

src/functions/private/Users/Get-GitHubUserByName.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@
5959
Context = $Context
6060
}
6161

62-
Invoke-GitHubAPI @inputObject | ForEach-Object {
63-
if ($_.Response.type -eq 'Organization') {
64-
[GitHubOrganization]::New($_.Response)
65-
} elseif ($_.Response.type -eq 'User') {
66-
[GitHubUser]::New($_.Response)
67-
} else {
68-
[GitHubOwner]::New($_.Response)
62+
try {
63+
Invoke-GitHubAPI @inputObject | ForEach-Object {
64+
if ($_.Response.type -eq 'Organization') {
65+
[GitHubOrganization]::New($_.Response, $Context.HostName)
66+
} elseif ($_.Response.type -eq 'User') {
67+
[GitHubUser]::New($_.Response)
68+
} else {
69+
[GitHubOwner]::New($_.Response)
70+
}
6971
}
72+
} catch {
73+
return
7074
}
7175
}
7276

src/functions/public/Organization/Update-GitHubOrganization.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204

205205
if ($PSCmdlet.ShouldProcess("organization [$Name]", 'Set')) {
206206
Invoke-GitHubAPI @inputObject | ForEach-Object {
207-
[GitHubOrganization]::new($_.Response)
207+
[GitHubOrganization]::new($_.Response, '')
208208
}
209209
}
210210
}

0 commit comments

Comments
 (0)