Skip to content

Commit 5eec977

Browse files
🚀 [Feature]: Moving Get-GitHubAppInstallableOrganization into Get-GitHubOrganization (#398)
## Description This pull request includes breaking changes such as moving a public function to private, and exposing its functionality through an existing public function, `Get-GitHubOrganization`. ### Changes to private function `Get-GitHubAppInstallableOrganization`: * Moved the file from `public` to `private` to reflect its intended usage. * Made the `$Context` parameter mandatory, removing the default value of `(Get-GitHubContext)`. * Updated the output handling to return a `GitHubOrganization` object instead of raw API responses, improving type safety. * Removed a placeholder comment about skipping tests for this function. ### Enhancements to `Get-GitHubOrganization`: * Added a new parameter set to support fetching organizations by enterprise slug (`$Enterprise`). This includes marking the `$Enterprise` parameter as mandatory for the new parameter set. * Introduced a new `.EXAMPLE` section in the documentation to demonstrate usage with the enterprise parameter. * Incorporated a new logic branch in the `switch` statement to handle enterprise organizations by calling the `Get-GitHubAppInstallableOrganization` function. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [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 d5fc626 commit 5eec977

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

examples/Apps/AppManagement.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$appIDs = @(
33
'Iv1.f26b61bc99e69405'
44
)
5-
$orgs = Get-GitHubAppInstallableOrganization -Enterprise 'msx'
5+
$orgs = Get-GitHubOrganization -Enterprise 'msx'
66
foreach ($org in $orgs) {
77
foreach ($appID in $appIDs) {
88
Install-GitHubAppOnEnterpriseOrganization -Enterprise msx -Organization $org.login -ClientID $appID -RepositorySelection all

examples/Apps/EnterpriseApps.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ filter Install-GithubApp {
2020
)
2121

2222
process {
23-
$installableOrgs = Get-GitHubAppInstallableOrganization -Enterprise $Enterprise -Debug -Verbose
23+
$installableOrgs = Get-GitHubOrganization -Enterprise $Enterprise -Debug -Verbose
2424
$orgs = $installableOrgs | Where-Object { $_.login -like $organization }
2525
foreach ($org in $orgs) {
2626
foreach ($appIDitem in $AppID) {

src/functions/public/Apps/GitHub App/Get-GitHubAppInstallableOrganization.ps1 renamed to src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
[System.Nullable[int]] $PerPage,
2828

2929
# The context to run the command in. Used to get the details for the API call.
30-
# Can be either a string or a GitHubContext object.
31-
[Parameter()]
32-
[object] $Context = (Get-GitHubContext)
30+
[Parameter(Mandatory)]
31+
[object] $Context
3332
)
3433

3534
begin {
@@ -49,13 +48,11 @@
4948
}
5049

5150
Invoke-GitHubAPI @inputObject | ForEach-Object {
52-
Write-Output $_.Response
51+
[GitHubOrganization]::new($_.Response)
5352
}
5453
}
5554

5655
end {
5756
Write-Debug "[$stackPath] - End"
5857
}
5958
}
60-
61-
#SkipTest:FunctionTest:Will add a test for this function in a future PR

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,27 @@
1212
.EXAMPLE
1313
Get-GitHubOrganization
1414
15-
List organizations for the authenticated user.
15+
List all organizations for the authenticated user.
1616
1717
.EXAMPLE
1818
Get-GitHubOrganization -Username 'octocat'
1919
20-
List public organizations for the user 'octocat'.
20+
List public organizations for a specific user.
2121
2222
.EXAMPLE
2323
Get-GitHubOrganization -All -Since 142951047
2424
25-
List organizations, starting with PSModule.
25+
List all organizations made after an ID.
2626
2727
.EXAMPLE
2828
Get-GitHubOrganization -Name 'PSModule'
2929
30-
Get the organization 'PSModule'.
30+
Get a specific organization.
31+
32+
.EXAMPLE
33+
Get-GitHubOrganization -Enterprise 'msx'
34+
35+
Get the organizations belonging to an Enterprise.
3136
3237
.OUTPUTS
3338
GitHubOrganization
@@ -36,13 +41,13 @@
3641
https://psmodule.io/GitHub/Functions/Organization/Get-GitHubOrganization
3742
#>
3843
[OutputType([GitHubOrganization])]
39-
[CmdletBinding(DefaultParameterSetName = '__AllParameterSets')]
44+
[CmdletBinding(DefaultParameterSetName = 'List all organizations for the authenticated user')]
4045
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'All', Justification = 'Required for parameter set')]
4146
param(
4247
# The organization name. The name is not case sensitive.
4348
[Parameter(
4449
Mandatory,
45-
ParameterSetName = 'NamedOrg',
50+
ParameterSetName = 'Get a specific organization',
4651
ValueFromPipeline,
4752
ValueFromPipelineByPropertyName
4853
)]
@@ -51,27 +56,34 @@
5156
# The handle for the GitHub user account.
5257
[Parameter(
5358
Mandatory,
54-
ParameterSetName = 'NamedUser',
59+
ParameterSetName = 'List public organizations for a specific user',
5560
ValueFromPipelineByPropertyName
5661
)]
5762
[Alias('User')]
5863
[string] $Username,
5964

65+
# The Enterprise slug to get organizations from.
66+
[Parameter(
67+
Mandatory,
68+
ParameterSetName = 'Get the organizations belonging to an Enterprise',
69+
ValueFromPipelineByPropertyName
70+
)]
71+
[string] $Enterprise,
72+
6073
# List all organizations. Use '-Since' to start at a specific organization ID.
6174
[Parameter(
6275
Mandatory,
63-
ParameterSetName = 'AllOrg'
76+
ParameterSetName = 'List all organizations on the tenant'
6477
)]
6578
[switch] $All,
6679

6780
# A organization ID. Only return organizations with an ID greater than this ID.
68-
[Parameter(ParameterSetName = 'AllOrg')]
81+
[Parameter(ParameterSetName = 'List all organizations on the tenant')]
6982
[int] $Since = 0,
7083

7184
# The number of results per page (max 100).
72-
[Parameter(ParameterSetName = 'AllOrg')]
73-
[Parameter(ParameterSetName = 'UserOrg')]
74-
[Parameter(ParameterSetName = '__AllParameterSets')]
85+
[Parameter(ParameterSetName = 'List all organizations on the tenant')]
86+
[Parameter(ParameterSetName = 'List all organizations for the authenticated user')]
7587
[System.Nullable[int]] $PerPage,
7688

7789
# The context to run the command in. Used to get the details for the API call.
@@ -89,13 +101,16 @@
89101

90102
process {
91103
switch ($PSCmdlet.ParameterSetName) {
92-
'NamedOrg' {
104+
'Get a specific organization' {
93105
Get-GitHubOrganizationByName -Name $Name -Context $Context
94106
}
95-
'NamedUser' {
107+
'List public organizations for a specific user' {
96108
Get-GitHubUserOrganization -Username $Username -Context $Context
97109
}
98-
'AllOrg' {
110+
'Get the organizations belonging to an Enterprise' {
111+
Get-GitHubAppInstallableOrganization -Enterprise $Enterprise -Context $Context
112+
}
113+
'List all organizations on the tenant' {
99114
Get-GitHubAllOrganization -Since $Since -PerPage $PerPage -Context $Context
100115
}
101116
default {

0 commit comments

Comments
 (0)