From 82ce397b8b1e2468102942c8705258cedaba967a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 07:50:44 +0200 Subject: [PATCH 01/37] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20cons?= =?UTF-8?q?tructors=20to=20use=20GitHubContext=20for=20URL=20generation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/public/App/GitHubAppInstallation.ps1 | 6 +++--- src/classes/public/Artifacts/GitHubArtifact.ps1 | 4 ++-- .../public/Environment/GitHubEnvironment.ps1 | 3 ++- .../public/Owner/GitHubOwner/GitHubOrganization.ps1 | 4 ++-- .../Get-GitHubAppInstallableOrganization.ps1 | 2 +- ...-GitHubEnterpriseOrganizationAppInstallation.ps1 | 2 +- .../New-GitHubAppInstallationAccessToken.ps1 | 13 +++++-------- .../private/Artifacts/Get-GitHubArtifactById.ps1 | 2 +- .../Artifacts/Get-GitHubArtifactFromRepository.ps1 | 2 +- .../Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 | 2 +- .../private/Auth/Context/Remove-GitHubContext.ps1 | 1 - .../Environments/Get-GitHubEnvironmentByName.ps1 | 5 +---- .../Environments/Get-GitHubEnvironmentList.ps1 | 4 +--- .../Organization/Get-GitHubAllOrganization.ps1 | 2 +- .../Organization/Get-GitHubMyOrganization.ps1 | 2 +- .../Organization/Get-GitHubUserOrganization.ps1 | 2 +- src/functions/private/Users/Get-GitHubMyUser.ps1 | 2 +- .../private/Users/Get-GitHubUserByName.ps1 | 2 +- src/functions/public/Auth/Connect-GitHubApp.ps1 | 2 +- .../public/Environments/Set-GitHubEnvironment.ps1 | 4 +--- 20 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/classes/public/App/GitHubAppInstallation.ps1 b/src/classes/public/App/GitHubAppInstallation.ps1 index 5335e4830..96fd2831c 100644 --- a/src/classes/public/App/GitHubAppInstallation.ps1 +++ b/src/classes/public/App/GitHubAppInstallation.ps1 @@ -65,7 +65,7 @@ $this.Url = $Object.html_url } - GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) { + GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [GitHubContext] $Context) { $this.ID = $Object.id $this.App = [GitHubApp]::new( [PSCustomObject]@{ @@ -77,7 +77,7 @@ $this.Target = [GitHubOwner]@{ Name = $Target Type = $Type - Url = "https://$HostName/$Target" + Url = "https://$($Context.HostName)/$Target" } $this.Type = $Type $this.RepositorySelection = $Object.repository_selection @@ -88,6 +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)" + $this.Url = "https://$($Context.HostName)/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" } } diff --git a/src/classes/public/Artifacts/GitHubArtifact.ps1 b/src/classes/public/Artifacts/GitHubArtifact.ps1 index 3e654860e..988c09931 100644 --- a/src/classes/public/Artifacts/GitHubArtifact.ps1 +++ b/src/classes/public/Artifacts/GitHubArtifact.ps1 @@ -37,14 +37,14 @@ GitHubArtifact() {} - GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [string]$HostName) { + GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [GitHubContext]$Context) { $this.ID = $Object.id $this.NodeID = $Object.node_id $this.Name = $Object.name $this.Owner = $Owner $this.Repository = $Repository $this.Size = $Object.size_in_bytes - $this.Url = "https://$($HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)" + $this.Url = "https://$($Context.HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)" $this.ArchiveDownloadUrl = $Object.archive_download_url $this.Expired = $Object.expired $this.Digest = $Object.digest diff --git a/src/classes/public/Environment/GitHubEnvironment.ps1 b/src/classes/public/Environment/GitHubEnvironment.ps1 index 4da7639c7..799addd97 100644 --- a/src/classes/public/Environment/GitHubEnvironment.ps1 +++ b/src/classes/public/Environment/GitHubEnvironment.ps1 @@ -28,12 +28,13 @@ GitHubEnvironment() {} - GitHubEnvironment([PSCustomObject]$Object, [string]$Owner, [string]$Repository) { + GitHubEnvironment([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [GitHubContext]$Context) { $this.ID = $Object.id $this.NodeID = $Object.node_id $this.Name = $Object.name $this.Owner = $Owner $this.Repository = $Repository + $this.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($Object.id)/edit" $this.CreatedAt = $Object.created_at $this.UpdatedAt = $Object.updated_at $this.AdminsCanBypass = $Object.can_admins_bypass diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 5869a6367..ef33c930c 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -136,7 +136,7 @@ GitHubOrganization() {} - GitHubOrganization([PSCustomObject] $Object, [string] $HostName) { + GitHubOrganization([PSCustomObject] $Object, [GitHubContext] $Context) { # From GitHubNode $this.ID = $Object.id $this.NodeID = $Object.node_id @@ -145,7 +145,7 @@ $this.Name = $Object.login $this.DisplayName = $Object.name $this.AvatarUrl = $Object.avatar_url - $this.Url = $Object.html_url ?? "https://$($HostName)/$($Object.login)" + $this.Url = $Object.html_url ?? "https://$($Context.HostName)/$($Object.login)" $this.Type = $Object.type $this.Company = $Object.company $this.Blog = $Object.blog diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 index 4d5017e44..5c03bfcfb 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 @@ -52,7 +52,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { foreach ($organization in $_.Response) { - [GitHubOrganization]::new($organization, $Context.HostName) + [GitHubOrganization]::new($organization, $Context) } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 index 4609f1fe1..ea19a3c4d 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -62,7 +62,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { foreach ($installation in $_.Response) { - [GitHubAppInstallation]::new($installation, $Organization, 'Organization', $context.HostName) + [GitHubAppInstallation]::new($installation, $Organization, 'Organization', $Context) } } } diff --git a/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 b/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 index 2291149ad..34369ff47 100644 --- a/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 +++ b/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 @@ -48,18 +48,15 @@ 'PSUseShouldProcessForStateChangingFunctions', '', Justification = 'No state is changed.' )] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', - Justification = 'The tokens are received as clear text. Mitigating exposure by removing variables and performing garbage collection.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'The tokens are received as clear text. Mitigating exposure by removing variables and performing garbage collection.' + )] [CmdletBinding()] param( # The unique identifier of the installation. # Example: '12345678' - [Parameter( - Mandatory, - ValueFromPipeline, - ValueFromPipelineByPropertyName - )] - [Alias('installation_id', 'InstallationID')] + [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [int] $ID, # The context to run the command in. Used to get the details for the API call. diff --git a/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 b/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 index 1d634fbbb..782667043 100644 --- a/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 +++ b/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 @@ -68,7 +68,7 @@ function Get-GitHubArtifactById { } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubArtifact]::new($_.Response, $Owner, $Repository, $Context.HostName) + [GitHubArtifact]::new($_.Response, $Owner, $Repository, $Context) } } diff --git a/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 b/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 index d7f86c044..08087d229 100644 --- a/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 +++ b/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 @@ -88,7 +88,7 @@ function Get-GitHubArtifactFromRepository { } $artifacts | ForEach-Object { - [GitHubArtifact]::new($_, $Owner, $Repository, $Context.HostName) + [GitHubArtifact]::new($_, $Owner, $Repository, $Context) } } diff --git a/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 b/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 index a7b9b863b..7a54c1709 100644 --- a/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 +++ b/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 @@ -99,7 +99,7 @@ function Get-GitHubArtifactFromWorkflowRun { } $artifacts | ForEach-Object { - [GitHubArtifact]::new($_, $Owner, $Repository, $Context.HostName) + [GitHubArtifact]::new($_, $Owner, $Repository, $Context) } } diff --git a/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 index 4c93f5ddc..9b6f810d8 100644 --- a/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 @@ -23,7 +23,6 @@ param( # The name of the context. [Parameter(Mandatory)] - [Alias('Name')] [string] $Context ) diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 index d4286cb88..0b9df7f01 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 @@ -50,7 +50,6 @@ filter Get-GitHubEnvironmentByName { Mandatory, ValueFromPipelineByPropertyName )] - [Alias('Organization', 'User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. @@ -88,9 +87,7 @@ filter Get-GitHubEnvironmentByName { } try { Invoke-GitHubAPI @inputObject | ForEach-Object { - $environment = [GitHubEnvironment]::new($_.Response, $Owner, $Repository) - $environment.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($environment.ID)/edit" - $environment + [GitHubEnvironment]::new($_.Response, $Owner, $Repository, $Context) } } catch { return diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 index 85d191c16..01d109a97 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 @@ -83,9 +83,7 @@ filter Get-GitHubEnvironmentList { Invoke-GitHubAPI @inputObject | ForEach-Object { $_.Response.environments | ForEach-Object { - $environment = [GitHubEnvironment]::new($_, $Owner, $Repository) - $environment.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($environment.ID)/edit" - $environment + [GitHubEnvironment]::new($_, $Owner, $Repository, $Context) } } } diff --git a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 index 98ffe0674..53f774ee2 100644 --- a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 @@ -58,7 +58,7 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context.HostName) } + $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context) } } } end { diff --git a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 index d11b5aebe..fd25ed1df 100644 --- a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 @@ -53,7 +53,7 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context.HostName) } + $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context) } } } diff --git a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 index 6a8df5659..17829cc9d 100644 --- a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 @@ -56,7 +56,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { foreach ($org in $_.Response) { - [GitHubOrganization]::new($org, $Context.HostName) + [GitHubOrganization]::new($org, $Context) } } } diff --git a/src/functions/private/Users/Get-GitHubMyUser.ps1 b/src/functions/private/Users/Get-GitHubMyUser.ps1 index 7526a7837..6141d5043 100644 --- a/src/functions/private/Users/Get-GitHubMyUser.ps1 +++ b/src/functions/private/Users/Get-GitHubMyUser.ps1 @@ -44,7 +44,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { if ($_.Response.type -eq 'Organization') { - [GitHubOrganization]::New($_.Response, $Context.HostName) + [GitHubOrganization]::New($_.Response, $Context) } elseif ($_.Response.type -eq 'User') { [GitHubUser]::New($_.Response) } else { diff --git a/src/functions/private/Users/Get-GitHubUserByName.ps1 b/src/functions/private/Users/Get-GitHubUserByName.ps1 index 701bca251..880b63e55 100644 --- a/src/functions/private/Users/Get-GitHubUserByName.ps1 +++ b/src/functions/private/Users/Get-GitHubUserByName.ps1 @@ -62,7 +62,7 @@ try { Invoke-GitHubAPI @inputObject | ForEach-Object { if ($_.Response.type -eq 'Organization') { - [GitHubOrganization]::New($_.Response, $Context.HostName) + [GitHubOrganization]::New($_.Response, $Context) } elseif ($_.Response.type -eq 'User') { [GitHubUser]::New($_.Response) } else { diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index c74caafba..1994c5082 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -122,7 +122,7 @@ $selectedInstallations | ForEach-Object { $installation = $_ Write-Verbose "Processing installation [$($installation.Target.Name)] [$($installation.id)]" - $token = New-GitHubAppInstallationAccessToken -Context $Context -InstallationID $installation.id + $token = New-GitHubAppInstallationAccessToken -Context $Context -ID $installation.id $contextParams = @{ AuthType = [string]'IAT' diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 index 65c0b326c..b048f185e 100644 --- a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -182,9 +182,7 @@ if ($PSCmdlet.ShouldProcess("Environment [$Owner/$Repository/$Name]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { - $environment = [GitHubEnvironment]::new($_.Response, $Owner, $Repository) - $environment.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($environment.ID)/edit" - $environment + [GitHubEnvironment]::new($_.Response, $Owner, $Repository, $Context) } } } From 4dbc3995fb66ba7722daa589b52e65267f411cda Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 07:50:53 +0200 Subject: [PATCH 02/37] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20alias?= =?UTF-8?q?=20'Get-GitHubRepoSecurityFixes'=20from=20Get-GitHubRepositoryS?= =?UTF-8?q?ecurityFix=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/Get-GitHubRepositorySecurityFix.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index e5356b44d..c26043b60 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -19,7 +19,6 @@ .LINK https://psmodule.io/GitHub/Functions/Repositories/Repositories/Get-GitHubRepositorySecurityFix #> - [Alias('Get-GitHubRepoSecurityFixes')] [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param( From 93e652119fe6191a581b32b7bac1279d3143f4ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 07:50:58 +0200 Subject: [PATCH 03/37] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20alias?= =?UTF-8?q?=20'Get-GitHubAppJWT'=20from=20Get-GitHubAppJSONWebToken=20func?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 index 133816e4f..9ac33c835 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 @@ -37,7 +37,6 @@ )] [CmdletBinding(DefaultParameterSetName = 'PrivateKey')] - [Alias('Get-GitHubAppJWT')] [OutputType([GitHubJsonWebToken])] param( # The client ID of the GitHub App. From c18a1ee10b483371d2b9e8c931d8173ef546a182 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 07:54:31 +0200 Subject: [PATCH 04/37] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20aliase?= =?UTF-8?q?s=20from=20parameters=20and=20add=20new=20functions=20for=20rep?= =?UTF-8?q?ository=20rule=20suites?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 | 5 ----- .../RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 | 4 ---- .../Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 | 1 - 3 files changed, 10 deletions(-) rename src/functions/{public => private}/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 (94%) rename src/functions/{public => private}/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 (96%) diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 similarity index 94% rename from src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 rename to src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 index 0bce42cff..e614f7f10 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 +++ b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 @@ -24,8 +24,6 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Organization')] - [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. @@ -34,7 +32,6 @@ # The unique identifier of the rule suite result. To get this ID, you can use GET /repos/ { owner }/ { repo }/rulesets/rule-suites for repositories and GET /orgs/ { org }/rulesets/rule-suites for organizations. [Parameter(Mandatory)] - [Alias('RuleSuiteId')] [int] $ID, # The context to run the command in. Used to get the details for the API call. @@ -66,5 +63,3 @@ Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 similarity index 96% rename from src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 rename to src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 index d124a6b77..7843a405b 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 +++ b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 @@ -32,8 +32,6 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Organization')] - [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. @@ -104,5 +102,3 @@ Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 index d24ceb1e3..741f9e9b3 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 @@ -39,7 +39,6 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [Alias('org')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. From 9e3b199b97fe26817302337fa774e4808a95f037 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 08:59:17 +0200 Subject: [PATCH 05/37] Refactor response handling in multiple functions to use foreach loops for improved readability --- .../Get-GitHubAppInstallationForAuthenticatedApp.ps1 | 4 ++-- .../Environments/Get-GitHubEnvironmentList.ps1 | 4 ++-- .../Organization/Get-GitHubAllOrganization.ps1 | 4 +++- .../Organization/Get-GitHubMyOrganization.ps1 | 4 +++- .../Organization/Get-GitHubOrganizationByName.ps1 | 2 +- .../Organization/Get-GitHubUserOrganization.ps1 | 4 ++-- src/functions/private/Users/Get-GitHubAllUser.ps1 | 12 ++++++------ 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 index f4dfcb18e..a4a218574 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 @@ -47,8 +47,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { - [GitHubAppInstallation]::new($_) + foreach ($installation in $_.Response) { + [GitHubAppInstallation]::new($installation) } } } diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 index 01d109a97..c4cd691bb 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 @@ -82,8 +82,8 @@ filter Get-GitHubEnvironmentList { } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.environments | ForEach-Object { - [GitHubEnvironment]::new($_, $Owner, $Repository, $Context) + foreach ($environment in $_.Response.environments) { + [GitHubEnvironment]::new($environment, $Owner, $Repository, $Context) } } } diff --git a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 index 53f774ee2..60f8aee2f 100644 --- a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 @@ -58,7 +58,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context) } + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization, $Context) + } } } end { diff --git a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 index fd25ed1df..9d56307f4 100644 --- a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 @@ -53,7 +53,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context) } + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization, $Context) + } } } diff --git a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 index 03595108f..aee398ab2 100644 --- a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -56,7 +56,7 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubOrganization]::new($_.Response, '') + [GitHubOrganization]::new($_.Response, $Context) } } end { diff --git a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 index 17829cc9d..6cd3d6e9b 100644 --- a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 @@ -55,8 +55,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - foreach ($org in $_.Response) { - [GitHubOrganization]::new($org, $Context) + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization, $Context) } } } diff --git a/src/functions/private/Users/Get-GitHubAllUser.ps1 b/src/functions/private/Users/Get-GitHubAllUser.ps1 index 43d57fc63..ea8233a2e 100644 --- a/src/functions/private/Users/Get-GitHubAllUser.ps1 +++ b/src/functions/private/Users/Get-GitHubAllUser.ps1 @@ -58,13 +58,13 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { - if ($_.type -eq 'Organization') { - [GitHubOrganization]::New($_, '') - } elseif ($_.type -eq 'User') { - [GitHubUser]::New($_) + foreach ($account in $_.Response) { + if ($account.type -eq 'Organization') { + [GitHubOrganization]::New($account, $Context) + } elseif ($account.type -eq 'User') { + [GitHubUser]::New($account) } else { - [GitHubOwner]::New($_) + [GitHubOwner]::New($account) } } } From 3da8a4e281256d2599f47622857de580a7a2a0ff Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 09:00:04 +0200 Subject: [PATCH 06/37] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Rename=20'Blog'?= =?UTF-8?q?=20parameter=20to=20'Website'=20in=20multiple=20files=20for=20c?= =?UTF-8?q?onsistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/public/Owner/GitHubOwner.ps1 | 6 +++--- .../public/Owner/GitHubOwner/GitHubOrganization.ps1 | 2 +- src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 | 2 +- src/formats/GitHubOwner.Format.ps1xml | 2 +- .../public/Organization/Update-GitHubOrganization.ps1 | 10 +++++----- src/functions/public/Users/Update-GitHubUser.ps1 | 6 +++--- tests/Organizations.Tests.ps1 | 2 +- tests/Users.Tests.ps1 | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner.ps1 b/src/classes/public/Owner/GitHubOwner.ps1 index cc932ce1a..a209ee9d0 100644 --- a/src/classes/public/Owner/GitHubOwner.ps1 +++ b/src/classes/public/Owner/GitHubOwner.ps1 @@ -23,9 +23,9 @@ # Example: GitHub [string] $Company - # The blog URL of the account. + # The website URL of the account. # Example: https://github.com/blog - [string] $Blog + [string] $Website # The location of the account. # Example: San Francisco @@ -81,7 +81,7 @@ $this.Url = $Object.html_url $this.Type = $Object.type $this.Company = $Object.company - $this.Blog = $Object.website_url ?? $Object.blog + $this.Website = $Object.website_url ?? $Object.blog $this.Location = $Object.location $this.Email = $Object.email $this.TwitterUsername = $Object.twitter_username diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index ef33c930c..33850f5ed 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -148,7 +148,7 @@ $this.Url = $Object.html_url ?? "https://$($Context.HostName)/$($Object.login)" $this.Type = $Object.type $this.Company = $Object.company - $this.Blog = $Object.blog + $this.Website = $Object.blog $this.Location = $Object.location $this.Email = $Object.email $this.TwitterUsername = $Object.twitter_username diff --git a/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 index b6b1d4664..3991c83c5 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 @@ -24,7 +24,7 @@ $this.Url = $Object.html_url $this.Type = $Object.type $this.Company = $Object.company - $this.Blog = $Object.blog + $this.Website = $Object.blog $this.Location = $Object.location $this.Email = $Object.email $this.TwitterUsername = $Object.twitter_username diff --git a/src/formats/GitHubOwner.Format.ps1xml b/src/formats/GitHubOwner.Format.ps1xml index 34d050cd5..ccd9f1020 100644 --- a/src/formats/GitHubOwner.Format.ps1xml +++ b/src/formats/GitHubOwner.Format.ps1xml @@ -99,7 +99,7 @@ TwitterUsername - Blog + Website CreatedAt diff --git a/src/functions/public/Organization/Update-GitHubOrganization.ps1 b/src/functions/public/Organization/Update-GitHubOrganization.ps1 index bfea406da..21fb05bff 100644 --- a/src/functions/public/Organization/Update-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Update-GitHubOrganization.ps1 @@ -8,9 +8,9 @@ profile and member privileges. .EXAMPLE - Update-GitHubOrganization -Organization 'GitHub' -Blog 'https://github.blog' + Update-GitHubOrganization -Organization 'GitHub' -Website 'https://github.blog' - Sets the blog URL for the organization 'GitHub' to ''. + Sets the website URL for the organization 'GitHub' to ''. .EXAMPLE $param = @{ @@ -134,9 +134,9 @@ [Parameter(ValueFromPipelineByPropertyName)] [bool] $WebCommitSignoffRequired, - # Path to the organization's blog. + # Path to the organization's website. [Parameter(ValueFromPipelineByPropertyName)] - [string] $Blog, + [string] $Website, # Whether secret scanning push protection is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for @@ -171,7 +171,7 @@ $body = @{ name = $NewName billing_email = $BillingEmail - blog = $Blog + blog = $Website company = $Company description = $Description email = $Email diff --git a/src/functions/public/Users/Update-GitHubUser.ps1 b/src/functions/public/Users/Update-GitHubUser.ps1 index 69af9e3d2..d1fb915f9 100644 --- a/src/functions/public/Users/Update-GitHubUser.ps1 +++ b/src/functions/public/Users/Update-GitHubUser.ps1 @@ -40,9 +40,9 @@ [Parameter()] [string] $Email, - # The new blog URL of the user. + # The new website URL of the user. [Parameter()] - [string] $Blog, + [string] $Website, # The new Twitter username of the user. [Parameter()] @@ -81,7 +81,7 @@ $body = @{ name = $DisplayName email = $Email - blog = $Blog + blog = $Website twitter_username = $TwitterUsername company = $Company location = $Location diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 32ddb2b28..4136b6b53 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -94,7 +94,7 @@ Describe 'Organizations' { { Update-GitHubOrganization -Name $owner -Description 'Test Organization' } | Should -Not -Throw { Update-GitHubOrganization -Name $owner -DefaultRepositoryPermission read } | Should -Not -Throw { Update-GitHubOrganization -Name $owner -MembersCanCreateRepositories $true } | Should -Not -Throw - { Update-GitHubOrganization -Name $owner -Blog 'https://psmodule.io' } | Should -Not -Throw + { Update-GitHubOrganization -Name $owner -Website 'https://psmodule.io' } | Should -Not -Throw } } diff --git a/tests/Users.Tests.ps1 b/tests/Users.Tests.ps1 index 5dcd0ec18..c77c1ee3f 100644 --- a/tests/Users.Tests.ps1 +++ b/tests/Users.Tests.ps1 @@ -53,14 +53,14 @@ Describe 'Users' { $guid = (New-Guid).Guid $user = Get-GitHubUser { Update-GitHubUser -DisplayName 'Octocat' } | Should -Not -Throw - { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw + { Update-GitHubUser -Website 'https://psmodule.io' } | Should -Not -Throw { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Location 'USA' } | Should -Not -Throw { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw $tmpUser = Get-GitHubUser $tmpUser.DisplayName | Should -Be 'Octocat' - $tmpUser.Blog | Should -Be 'https://psmodule.io' + $tmpUser.Website | Should -Be 'https://psmodule.io' $tmpUser.TwitterUsername | Should -Be 'PSModule' $tmpUser.Company | Should -Be 'PSModule' $tmpUser.Location | Should -Be 'USA' From 290e3fa9f470c010763d36e51edba9220d95ec96 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 10:12:40 +0200 Subject: [PATCH 07/37] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20functions?= =?UTF-8?q?=20to=20retrieve=20GitHub=20Enterprise=20details=20by=20name=20?= =?UTF-8?q?and=20list=20all=20instances,=20including=20comprehensive=20doc?= =?UTF-8?q?umentation=20and=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Enterprise/Get-GitHubEnterpriseByName.ps1 | 74 +++++++++++++++ .../Enterprise/Get-GitHubEnterpriseList.ps1 | 89 +++++++++++++++++++ .../Enterprise/Get-GitHubEnterprise.ps1 | 79 +++++++--------- .../{Enterprise.ps1 => Enterprise.Tests.ps1} | 14 +-- 4 files changed, 195 insertions(+), 61 deletions(-) create mode 100644 src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 create mode 100644 src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 rename tests/{Enterprise.ps1 => Enterprise.Tests.ps1} (77%) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 new file mode 100644 index 000000000..b6971860f --- /dev/null +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 @@ -0,0 +1,74 @@ +function Get-GitHubEnterpriseByName { + <# + .SYNOPSIS + Retrieves details about a GitHub Enterprise instance by name (slug). + + .DESCRIPTION + This function retrieves detailed information about a GitHub Enterprise instance, including its avatar, billing details, storage usage, + creation date, and other metadata based on the provided name (slug). It returns an object of type GitHubEnterprise populated with this + information. + + .EXAMPLE + Get-GitHubEnterpriseByName -Name 'my-enterprise' + + Output: + ```powershell + Name : My Enterprise + Slug : my-enterprise + URL : https://github.com/enterprises/my-enterprise + CreatedAt : 2022-01-01T00:00:00Z + ViewerIsAdmin : True + ``` + + Retrieves details about the GitHub Enterprise instance named 'my-enterprise'. + + .OUTPUTS + GitHubEnterprise + + .NOTES + An object containing detailed information about the GitHub Enterprise instance, including billing info, URLs, and metadata. + #> + [OutputType([GitHubEnterprise])] + [CmdletBinding()] + param( + # The name (slug) of the GitHub Enterprise instance to retrieve. + [Parameter(Mandatory)] + [Alias('Slug')] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $graphQLFields = [GitHubEnterprise]::PropertyToGraphQLMap + + $enterpriseQuery = @{ + query = @" +query(`$Slug: String!) { + enterprise(slug: `$Slug) { + $graphQLFields + } +} +"@ + Variables = @{ + Slug = $Name + } + Context = $Context + } + $enterpriseResult = Invoke-GitHubGraphQLQuery @enterpriseQuery + [GitHubEnterprise]::new($enterpriseResult.enterprise) + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 new file mode 100644 index 000000000..76267a5aa --- /dev/null +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -0,0 +1,89 @@ +function Get-GitHubEnterpriseList { + <# + .SYNOPSIS + Retrieves a list of all GitHub Enterprise instances. + + .DESCRIPTION + This function retrieves detailed information about all GitHub Enterprise instances, including their avatars, billing details, storage usage, + creation dates, and other metadata. It returns an array of objects of type GitHubEnterprise populated with this information. + + .EXAMPLE + Get-GitHubEnterpriseList + + Output: + ```powershell + Name : My Enterprise + Slug : my-enterprise + URL : https://github.com/enterprises/my-enterprise + CreatedAt : 2022-01-01T00:00:00Z + + Name : Another Enterprise + Slug : another-enterprise + URL : https://github.com/enterprises/another-enterprise + CreatedAt : 2021-12-01T00:00:00Z + ``` + + Retrieves details about the GitHub Enterprise instance. + + .OUTPUTS + GitHubEnterprise[] + + .NOTES + An array of objects containing detailed information about the GitHub Enterprise instances, including billing info, URLs, and metadata. + #> + [OutputType([GitHubEnterprise[]])] + [CmdletBinding()] + param( + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $hasNextPage = $true + $after = $null + $perPageSetting = Resolve-GitHubContextSetting -Name 'PerPage' -Value $PerPage -Context $Context + + $graphQLFields = [GitHubEnterprise]::PropertyToGraphQLMap + + do { + $enterpriseQuery = @{ + query = @" +query { + viewer { + enterprises(first: `$perPage, after: `$after) { + nodes { + $graphQLFields + } + } + } +} +"@ + Variables = @{ + perPage = $perPageSetting + after = $after + } + Context = $Context + } + Invoke-GitHubGraphQLQuery @enterpriseQuery | ForEach-Object { + foreach ($enterprise in $_.viewer.enterprises.nodes) { + [GitHubEnterprise]::new($enterprise) + + $hasNextPage = $_.viewer.enterprises.pageInfo.hasNextPage + $after = $_.viewer.enterprises.pageInfo.endCursor + } + } + } while ($hasNextPage) + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 index 079a3a89b..006b1a53f 100644 --- a/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 +++ b/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 @@ -1,12 +1,30 @@ function Get-GitHubEnterprise { <# .SYNOPSIS - Retrieves details about a GitHub Enterprise instance by name (slug). + Retrieves GitHub Enterprise instance details for the authenticated user. .DESCRIPTION - This function retrieves detailed information about a GitHub Enterprise instance, including its avatar, billing details, storage usage, - creation date, and other metadata based on the provided name (slug). It returns an object of type GitHubEnterprise populated with this - information. + Retrieves detailed information about GitHub Enterprise instances available to the authenticated user. + By default, the command lists all accessible instances, including metadata such as the enterprise name, slug, URL, and creation date. If a + specific enterprise name is provided, details about that single instance are returned. + + .EXAMPLE + Get-GitHubEnterprise + + Output: + ```powershell + Name : My Enterprise + Slug : my-enterprise + URL : https://github.com/enterprises/my-enterprise + CreatedAt : 2022-01-01T00:00:00Z + + Name : Another Enterprise + Slug : another-enterprise + URL : https://github.com/enterprises/another-enterprise + CreatedAt : 2022-01-01T00:00:00Z + ``` + + Retrieves details about all GitHub Enterprise instances for the user. .EXAMPLE Get-GitHubEnterprise -Name 'my-enterprise' @@ -17,7 +35,6 @@ Slug : my-enterprise URL : https://github.com/enterprises/my-enterprise CreatedAt : 2022-01-01T00:00:00Z - ViewerIsAdmin : True ``` Retrieves details about the GitHub Enterprise instance named 'my-enterprise'. @@ -32,10 +49,10 @@ https://psmodule.io/GitHub/Functions/Enterprise/Get-GitHubEnterprise/ #> [OutputType([GitHubEnterprise])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'List enterprises for the authenticated user')] param( # The name (slug) of the GitHub Enterprise instance to retrieve. - [Parameter(Mandatory)] + [Parameter(Mandatory, ParameterSetName = 'Get enterprise by name')] [Alias('Slug')] [string] $Name, @@ -53,49 +70,15 @@ } process { - $enterpriseQuery = @{ - query = @' -query($Slug: String!) { - enterprise(slug: $Slug) { - avatarUrl - billingEmail - billingInfo { - allLicensableUsersCount - assetPacks - bandwidthQuota - bandwidthUsage - bandwidthUsagePercentage - storageQuota - storageUsage - storageUsagePercentage - totalAvailableLicenses - totalLicenses - } - createdAt - databaseId - description - descriptionHTML - id - location - name - readme - readmeHTML - resourcePath - slug - updatedAt - url - viewerIsAdmin - websiteUrl - } -} -'@ - Variables = @{ - Slug = $Name + switch ($PSCmdlet.ParameterSetName) { + 'Get enterprise by name' { + Get-GitHubEnterpriseByName -Name $Name -Context $Context + break + } + default { + Get-GitHubEnterpriseList -Context $Context } - Context = $Context } - $enterpriseResult = Invoke-GitHubGraphQLQuery @enterpriseQuery - [GitHubEnterprise]::new($enterpriseResult.enterprise) } end { diff --git a/tests/Enterprise.ps1 b/tests/Enterprise.Tests.ps1 similarity index 77% rename from tests/Enterprise.ps1 rename to tests/Enterprise.Tests.ps1 index 9a4760271..28ef51a45 100644 --- a/tests/Enterprise.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -61,26 +61,14 @@ Describe 'Template' { $enterprise.BillingEmail | Should -Be 'marstor@hotmail.com' $enterprise.Url | Should -Be 'https://github.com/enterprises/msx' $enterprise.Type | Should -Be 'Enterprise' - $enterprise.BillingInfo | Should -BeOfType 'GitHubBillingInfo' - $enterprise.BillingInfo.AllLicensableUsersCount | Should -Be 1 - $enterprise.BillingInfo.AssetPacks | Should -Be 0 - $enterprise.BillingInfo.BandwidthQuota | Should -Be 5 - $enterprise.BillingInfo.BandwidthUsage | Should -Be 0 - $enterprise.BillingInfo.BandwidthUsagePercentage | Should -Be 0 - $enterprise.BillingInfo.StorageQuota | Should -Be 5 - $enterprise.BillingInfo.StorageUsage | Should -Be 0 - $enterprise.BillingInfo.StorageUsagePercentage | Should -Be 0 - $enterprise.BillingInfo.TotalAvailableLicenses | Should -Be 0 - $enterprise.BillingInfo.TotalLicenses | Should -Be 1 $enterprise.Readme | Should -Be 'This is a test' $enterprise.ReadmeHTML | Should -Be '

This is a test

' $enterprise.CreatedAt | Should -BeOfType 'DateTime' $enterprise.CreatedAt | Should -Be (Get-Date '18.09.2022 19:53:09') $enterprise.UpdatedAt | Should -BeOfType 'DateTime' $enterprise.Description | Should -Be 'This is the description' - $enterprise.DescriptionHTML | Should -Be '
This is the description
' $enterprise.Location | Should -Be 'Oslo, Norway' - $enterprise.Blog | Should -Be 'https://msx.no' + $enterprise.Website | Should -Be 'https://msx.no' } } } From e3fb7109d53d6dabc4eedf78c605a6b50a3268c6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 10:12:44 +0200 Subject: [PATCH 08/37] Refactor GitHubOwner classes to streamline properties and enhance user experience; update related tests for new parameter names and descriptions --- src/classes/public/Owner/GitHubOwner.ps1 | 53 ++++--------------- .../Owner/GitHubOwner/GitHubEnterprise.ps1 | 36 +++++++------ .../Owner/GitHubOwner/GitHubOrganization.ps1 | 50 +++++++++++++---- .../public/Owner/GitHubOwner/GitHubUser.ps1 | 52 +++++++++++++----- src/formats/GitHubOwner.Format.ps1xml | 31 +++++------ .../public/Users/Update-GitHubUser.ps1 | 10 ++-- src/types/GitHubUser.Types.ps1xml | 8 +++ tests/Users.Tests.ps1 | 4 ++ 8 files changed, 139 insertions(+), 105 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner.ps1 b/src/classes/public/Owner/GitHubOwner.ps1 index a209ee9d0..81efa24b0 100644 --- a/src/classes/public/Owner/GitHubOwner.ps1 +++ b/src/classes/public/Owner/GitHubOwner.ps1 @@ -19,41 +19,17 @@ # Example: User [string] $Type - # The company the account is affiliated with. - # Example: GitHub - [string] $Company - - # The website URL of the account. - # Example: https://github.com/blog - [string] $Website - # The location of the account. # Example: San Francisco [string] $Location - # The email of the account. - # Example: octocat@github.com - [string] $Email - - # The Twitter username. - # Example: monalisa - [string] $TwitterUsername - - # The number of public repositories. - # Example: 2 - [System.Nullable[uint]] $PublicRepos + # The description of the organization. + # Example: A great organization + [string] $Description - # The number of public gists. - # Example: 1 - [System.Nullable[uint]] $PublicGists - - # The number of followers. - # Example: 20 - [System.Nullable[uint]] $Followers - - # The number of accounts this account is following. - # Example: 0 - [System.Nullable[uint]] $Following + # The website URL of the account. + # Example: https://github.com/blog + [string] $Website # The creation date of the account. # Example: 2008-01-14T04:33:35Z @@ -63,10 +39,6 @@ # Example: 2008-01-14T04:33:35Z [System.Nullable[datetime]] $UpdatedAt - # The user's plan. - # Includes: Name, Collaborators, PrivateRepos, Space - [GitHubPlan] $Plan - GitHubOwner() {} GitHubOwner([PSCustomObject]$Object) { @@ -78,20 +50,13 @@ $this.Name = $Object.slug ?? $Object.login $this.DisplayName = $Object.name $this.AvatarUrl = $Object.avatar_url - $this.Url = $Object.html_url + $this.Url = $Object.html_url ?? $Object.url $this.Type = $Object.type - $this.Company = $Object.company - $this.Website = $Object.website_url ?? $Object.blog $this.Location = $Object.location - $this.Email = $Object.email - $this.TwitterUsername = $Object.twitter_username - $this.PublicRepos = $Object.public_repos - $this.PublicGists = $Object.public_gists - $this.Followers = $Object.followers - $this.Following = $Object.following + $this.Description = $Object.description ?? $Object.bio + $this.Website = $Object.websiteUrl ?? $Object.blog $this.CreatedAt = $Object.created_at $this.UpdatedAt = $Object.updated_at - $this.Plan = [GitHubPlan]::New($Object.plan) } [string] ToString() { diff --git a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 index 790c19625..c14c8ecd6 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 @@ -1,15 +1,4 @@ class GitHubEnterprise : GitHubOwner { - # The description of the enterprise. - # Example: A great enterprise - [string] $Description - - # The description of the enterprise, as HTML. - # Example:
A great enterprise
- [string] $DescriptionHTML - - # The billing information for the organization. - [GitHubBillingInfo] $BillingInfo - # The billing email address for the organization. # Example: org@example.com [string] $BillingEmail @@ -22,6 +11,24 @@ # Example:

This is the readme for the enterprise

[string] $ReadmeHTML + static [hashtable] $PropertyToGraphQLMap = @{ + ID = 'databaseId' + NodeID = 'id' + Name = 'slug' + DisplayName = 'name' + AvatarUrl = 'avatarUrl' + Url = 'url' + Type = $Object.type ?? 'Enterprise' + Website = 'websiteUrl' + Location = 'location' + CreatedAt = 'createdAt' + UpdatedAt = 'updatedAt' + Description = 'description' + BillingEmail = 'billingEmail' + Readme = 'readme' + ReadmeHTML = 'readmeHTML' + } + GitHubEnterprise() {} GitHubEnterprise([PSCustomObject] $Object) { @@ -35,17 +42,14 @@ $this.AvatarUrl = $Object.avatarUrl $this.Url = $Object.url $this.Type = $Object.type ?? 'Enterprise' - $this.Company = $Object.company - $this.Blog = $Object.websiteUrl $this.Location = $Object.location + $this.Description = $Object.description + $this.Website = $Object.websiteUrl $this.CreatedAt = $Object.createdAt $this.UpdatedAt = $Object.updatedAt # From GitHubEnterprise - $this.Description = $Object.description - $this.DescriptionHTML = $Object.descriptionHTML $this.BillingEmail = $Object.billingEmail - $this.BillingInfo = [GitHubBillingInfo]::new($Object.billingInfo) $this.Readme = $Object.readme $this.ReadmeHTML = $Object.readmeHTML } diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 33850f5ed..6a359f92e 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -1,7 +1,35 @@ class GitHubOrganization : GitHubOwner { - # The description of the organization. - # Example: A great organization - [string] $Description + # The email of the account. + # Example: octocat@github.com + [string] $Email + + # The company the account is affiliated with. + # Example: GitHub + [string] $Company + + # The Twitter username. + # Example: monalisa + [string] $TwitterUsername + + # The user's plan. + # Includes: Name, Collaborators, PrivateRepos, Space + [GitHubPlan] $Plan + + # The number of public repositories. + # Example: 2 + [System.Nullable[uint]] $PublicRepos + + # The number of public gists. + # Example: 1 + [System.Nullable[uint]] $PublicGists + + # The number of followers. + # Example: 20 + [System.Nullable[uint]] $Followers + + # The number of accounts this account is following. + # Example: 0 + [System.Nullable[uint]] $Following # The number of private gists. # Example: 81 @@ -147,21 +175,21 @@ $this.AvatarUrl = $Object.avatar_url $this.Url = $Object.html_url ?? "https://$($Context.HostName)/$($Object.login)" $this.Type = $Object.type - $this.Company = $Object.company - $this.Website = $Object.blog $this.Location = $Object.location + $this.Description = $Object.description + $this.Website = $Object.blog + $this.CreatedAt = $Object.created_at + $this.UpdatedAt = $Object.updated_at + + # From GitHubOrganization $this.Email = $Object.email + $this.Company = $Object.company $this.TwitterUsername = $Object.twitter_username + $this.Plan = [GitHubPlan]::New($Object.plan) $this.PublicRepos = $Object.public_repos $this.PublicGists = $Object.public_gists $this.Followers = $Object.followers $this.Following = $Object.following - $this.CreatedAt = $Object.created_at - $this.UpdatedAt = $Object.updated_at - $this.Plan = [GitHubPlan]::New($Object.plan) - - # From GitHubOrganization - $this.Description = $Object.description $this.PrivateGists = $Object.total_private_gists $this.TotalPrivateRepos = $Object.total_private_repos $this.OwnedPrivateRepos = $Object.owned_private_repos diff --git a/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 index 3991c83c5..a9e4e4abe 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 @@ -1,15 +1,43 @@ class GitHubUser : GitHubOwner { + # The email of the account. + # Example: octocat@github.com + [string] $Email + # Whether the user is hireable. [System.Nullable[bool]] $Hireable - # The user's biography. - # Example: There once was... - [string] $Bio + # The company the account is affiliated with. + # Example: GitHub + [string] $Company + + # The Twitter username. + # Example: monalisa + [string] $TwitterUsername + + # The number of public repositories. + # Example: 2 + [System.Nullable[uint]] $PublicRepos + + # The number of public gists. + # Example: 1 + [System.Nullable[uint]] $PublicGists + + # The number of followers. + # Example: 20 + [System.Nullable[uint]] $Followers + + # The number of accounts this account is following. + # Example: 0 + [System.Nullable[uint]] $Following # The notification email address of the user. # Example: octocat@github.com [string] $NotificationEmail + # The user's plan. + # Includes: Name, Collaborators, PrivateRepos, Space + [GitHubPlan] $Plan + GitHubUser() {} GitHubUser([PSCustomObject]$Object) { @@ -23,23 +51,23 @@ $this.AvatarUrl = $Object.avatar_url $this.Url = $Object.html_url $this.Type = $Object.type - $this.Company = $Object.company - $this.Website = $Object.blog $this.Location = $Object.location + $this.Description = $Object.bio + $this.Website = $Object.blog + $this.CreatedAt = $Object.created_at + $this.UpdatedAt = $Object.updated_at + + # From GitHubUser $this.Email = $Object.email + $this.Hireable = $Object.hireable + $this.Company = $Object.company $this.TwitterUsername = $Object.twitter_username $this.PublicRepos = $Object.public_repos $this.PublicGists = $Object.public_gists $this.Followers = $Object.followers $this.Following = $Object.following - $this.CreatedAt = $Object.created_at - $this.UpdatedAt = $Object.updated_at - $this.Plan = [GitHubPlan]::New($Object.plan) - - # From GitHubUser - $this.Hireable = $Object.hireable - $this.Bio = $Object.bio $this.NotificationEmail = $Object.notification_email + $this.Plan = [GitHubPlan]::New($Object.plan) } [string] ToString() { diff --git a/src/formats/GitHubOwner.Format.ps1xml b/src/formats/GitHubOwner.Format.ps1xml index ccd9f1020..c1d8dcb3f 100644 --- a/src/formats/GitHubOwner.Format.ps1xml +++ b/src/formats/GitHubOwner.Format.ps1xml @@ -7,9 +7,13 @@ GitHubOwner GitHubUser GitHubOrganization + GitHubEnterprise + + + @@ -20,15 +24,15 @@ - - - - + + + DisplayName + if ($Host.UI.SupportsVirtualTerminal -and @@ -46,10 +50,7 @@ Type - Company - - - Plan + CreatedAt @@ -65,6 +66,9 @@ + + DisplayName + Name @@ -74,9 +78,6 @@ NodeID - - DisplayName - AvatarUrl @@ -86,9 +87,6 @@ Type - - Company - Location @@ -96,7 +94,7 @@ Email
- TwitterUsername + Description Website @@ -107,9 +105,6 @@ UpdatedAt - - Plan - diff --git a/src/functions/public/Users/Update-GitHubUser.ps1 b/src/functions/public/Users/Update-GitHubUser.ps1 index d1fb915f9..de119ff36 100644 --- a/src/functions/public/Users/Update-GitHubUser.ps1 +++ b/src/functions/public/Users/Update-GitHubUser.ps1 @@ -19,9 +19,9 @@ Update the authenticated user's location to 'San Francisco' .EXAMPLE - Update-GitHubUser -Hireable $true -Bio 'I love programming' + Update-GitHubUser -Hireable $true -Description 'I love programming' - Update the authenticated user's hiring availability to 'true' and their biography to 'I love programming' + Update the authenticated user's hiring availability to 'true' and their description to 'I love programming' .NOTES [Update the authenticated user](https://docs.github.com/rest/users/users#update-the-authenticated-user) @@ -42,6 +42,7 @@ # The new website URL of the user. [Parameter()] + [Alias('Blog')] [string] $Website, # The new Twitter username of the user. @@ -62,7 +63,8 @@ # The new short biography of the user. [Parameter()] - [string] $Bio, + [Alias('Bio')] + [string] $Description, # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. @@ -86,7 +88,7 @@ company = $Company location = $Location hireable = $Hireable - bio = $Bio + bio = $Description } $body | Remove-HashtableEntry -NullOrEmptyValues diff --git a/src/types/GitHubUser.Types.ps1xml b/src/types/GitHubUser.Types.ps1xml index f81e6433f..275d10688 100644 --- a/src/types/GitHubUser.Types.ps1xml +++ b/src/types/GitHubUser.Types.ps1xml @@ -7,6 +7,14 @@ User $this.Name + + Bio + $this.Description + + + Blog + $this.Website + diff --git a/tests/Users.Tests.ps1 b/tests/Users.Tests.ps1 index c77c1ee3f..f4cb7cc32 100644 --- a/tests/Users.Tests.ps1 +++ b/tests/Users.Tests.ps1 @@ -53,18 +53,22 @@ Describe 'Users' { $guid = (New-Guid).Guid $user = Get-GitHubUser { Update-GitHubUser -DisplayName 'Octocat' } | Should -Not -Throw + { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw { Update-GitHubUser -Website 'https://psmodule.io' } | Should -Not -Throw { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Location 'USA' } | Should -Not -Throw { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw + { Update-GitHubUser -Description 'I love programming' } | Should -Not -Throw $tmpUser = Get-GitHubUser $tmpUser.DisplayName | Should -Be 'Octocat' + $tmpUser.Blog | Should -Be 'https://psmodule.io' $tmpUser.Website | Should -Be 'https://psmodule.io' $tmpUser.TwitterUsername | Should -Be 'PSModule' $tmpUser.Company | Should -Be 'PSModule' $tmpUser.Location | Should -Be 'USA' $tmpUser.Bio | Should -Be 'I love programming' + $tmpUser.Description | Should -Be 'I love programming' # Flaky tests # { Update-GitHubUser -Hireable $true } | Should -Not -Throw From 11b0d2fac4f2f9549d41c713b939fdf5eec17da4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 10:14:18 +0200 Subject: [PATCH 09/37] Add test for Get-GitHubEnterprise to retrieve all available enterprises with detailed assertions --- tests/Enterprise.Tests.ps1 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 28ef51a45..04c99b607 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -70,5 +70,31 @@ Describe 'Template' { $enterprise.Location | Should -Be 'Oslo, Norway' $enterprise.Website | Should -Be 'https://msx.no' } + + It 'Get-GitHubEnterprise - Can get info about all available enterprises' -Skip:($OwnerType -notlike 'enterprise') { + $enterprises = Get-GitHubEnterprise + LogGroup 'Enterprises' { + Write-Host ($enterprises | Select-Object * | Out-String) + } + $enterprises.count | Should -Be 1 + $enterprises | Should -Not -BeNullOrEmpty + $enterprises | Should -BeOfType 'GitHubEnterprise' + $enterprises.Name | Should -Be 'msx' + $enterprises.DisplayName | Should -Be 'MSX' + $enterprises.ID | Should -Be 15567 + $enterprises.NodeID | Should -Be 'E_kgDNPM8' + $enterprises.AvatarUrl | Should -Be 'https://avatars.githubusercontent.com/b/15567?v=4' + $enterprises.BillingEmail | Should -Be 'marstor@hotmail.com' + $enterprises.Url | Should -Be 'https://github.com/enterprises/msx' + $enterprises.Type | Should -Be 'Enterprise' + $enterprises.Readme | Should -Be 'This is a test' + $enterprises.ReadmeHTML | Should -Be '

This is a test

' + $enterprises.CreatedAt | Should -BeOfType 'DateTime' + $enterprises.CreatedAt | Should -Be (Get-Date '18.09.2022 19:53:09') + $enterprises.UpdatedAt | Should -BeOfType 'DateTime' + $enterprises.Description | Should -Be 'This is the description' + $enterprises.Location | Should -Be 'Oslo, Norway' + $enterprises.Website | Should -Be 'https://msx.no' + } } } From 14819895f5448557cd2362c6529347063762bddb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 21:54:26 +0200 Subject: [PATCH 10/37] Refactor response handling in Get-GitHubOrganizationMember to use foreach loops for improved readability; update Update-GitHubOrganization to pass context parameter correctly; clean up test logging in Enterprise.Tests --- .../Organization/Members/Get-GitHubOrganizationMember.ps1 | 4 +++- .../public/Organization/Update-GitHubOrganization.ps1 | 2 +- tests/Enterprise.Tests.ps1 | 6 ++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 b/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 index 75e9bc920..2354b1fb0 100644 --- a/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 +++ b/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 @@ -67,7 +67,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubUser]::new($_) } + foreach ($user in $_.Response) { + [GitHubUser]::new($user) + } } } diff --git a/src/functions/public/Organization/Update-GitHubOrganization.ps1 b/src/functions/public/Organization/Update-GitHubOrganization.ps1 index 21fb05bff..fa270a4ba 100644 --- a/src/functions/public/Organization/Update-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Update-GitHubOrganization.ps1 @@ -204,7 +204,7 @@ if ($PSCmdlet.ShouldProcess("organization [$Name]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubOrganization]::new($_.Response, '') + [GitHubOrganization]::new($_.Response, $Context) } } } diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 04c99b607..8b003ef2c 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -33,11 +33,9 @@ Describe 'Template' { Write-Host ($context | Format-List | Out-String) } if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { + LogGroup 'Context - Installation' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context - Installation' { - Write-Host ($context | Format-List | Out-String) - } + Write-Host ($context | Format-List | Out-String) } } } From f5e8f670b3105213a4dfa2e21732c3f23a5cd948 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 22:21:00 +0200 Subject: [PATCH 11/37] Refactor GraphQL fields assignment in Get-GitHubEnterpriseByName and Get-GitHubEnterpriseList to use .Values for improved clarity; add suppress message attributes for variable scoping issues. --- .../private/Enterprise/Get-GitHubEnterpriseByName.ps1 | 2 +- .../private/Enterprise/Get-GitHubEnterpriseList.ps1 | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 index b6971860f..6fc6f9309 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 @@ -49,7 +49,7 @@ } process { - $graphQLFields = [GitHubEnterprise]::PropertyToGraphQLMap + $graphQLFields = ([GitHubEnterprise]::PropertyToGraphQLMap).Values $enterpriseQuery = @{ query = @" diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 index 76267a5aa..1c292d22d 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -31,6 +31,14 @@ .NOTES An array of objects containing detailed information about the GitHub Enterprise instances, including billing info, URLs, and metadata. #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'hasNextPage', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'after', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] [OutputType([GitHubEnterprise[]])] [CmdletBinding()] param( @@ -51,7 +59,7 @@ $after = $null $perPageSetting = Resolve-GitHubContextSetting -Name 'PerPage' -Value $PerPage -Context $Context - $graphQLFields = [GitHubEnterprise]::PropertyToGraphQLMap + $graphQLFields = ([GitHubEnterprise]::PropertyToGraphQLMap).Values do { $enterpriseQuery = @{ From 14a858bea972ed40dbb2cb268c14cf607d5d1928 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 22:29:27 +0200 Subject: [PATCH 12/37] Refactor formatting of the GraphQL property mapping in GitHubEnterprise class for improved readability --- .../Owner/GitHubOwner/GitHubEnterprise.ps1 | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 index c14c8ecd6..7dc37a898 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 @@ -12,21 +12,21 @@ [string] $ReadmeHTML static [hashtable] $PropertyToGraphQLMap = @{ - ID = 'databaseId' - NodeID = 'id' - Name = 'slug' - DisplayName = 'name' - AvatarUrl = 'avatarUrl' - Url = 'url' - Type = $Object.type ?? 'Enterprise' - Website = 'websiteUrl' - Location = 'location' - CreatedAt = 'createdAt' - UpdatedAt = 'updatedAt' - Description = 'description' - BillingEmail = 'billingEmail' - Readme = 'readme' - ReadmeHTML = 'readmeHTML' + ID = 'databaseId' + NodeID = 'id' + Name = 'slug' + DisplayName = 'name' + AvatarUrl = 'avatarUrl' + Url = 'url' + Type = $Object.type ?? 'Enterprise' + Website = 'websiteUrl' + Location = 'location' + CreatedAt = 'createdAt' + UpdatedAt = 'updatedAt' + Description = 'description' + BillingEmail = 'billingEmail' + Readme = 'readme' + ReadmeHTML = 'readmeHTML' } GitHubEnterprise() {} From cdc409f7114e58a32b4ff12a57a61fb4b9a3047c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 22:57:20 +0200 Subject: [PATCH 13/37] Update examples and comments in Update-GitHubOrganization and Update-GitHubUser for clarity --- .../public/Organization/Update-GitHubOrganization.ps1 | 6 +++--- src/functions/public/Users/Update-GitHubUser.ps1 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Organization/Update-GitHubOrganization.ps1 b/src/functions/public/Organization/Update-GitHubOrganization.ps1 index fa270a4ba..9095cf593 100644 --- a/src/functions/public/Organization/Update-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Update-GitHubOrganization.ps1 @@ -8,9 +8,9 @@ profile and member privileges. .EXAMPLE - Update-GitHubOrganization -Organization 'GitHub' -Website 'https://github.blog' + Update-GitHubOrganization -Organization 'GitHub' -Description 'The official GitHub organization.' - Sets the website URL for the organization 'GitHub' to ''. + Sets the description for the organization 'GitHub' to 'The official GitHub organization.'. .EXAMPLE $param = @{ @@ -134,7 +134,7 @@ [Parameter(ValueFromPipelineByPropertyName)] [bool] $WebCommitSignoffRequired, - # Path to the organization's website. + # Path to the organization's site. [Parameter(ValueFromPipelineByPropertyName)] [string] $Website, diff --git a/src/functions/public/Users/Update-GitHubUser.ps1 b/src/functions/public/Users/Update-GitHubUser.ps1 index de119ff36..7338bb66c 100644 --- a/src/functions/public/Users/Update-GitHubUser.ps1 +++ b/src/functions/public/Users/Update-GitHubUser.ps1 @@ -40,7 +40,7 @@ [Parameter()] [string] $Email, - # The new website URL of the user. + # The new site for the user. [Parameter()] [Alias('Blog')] [string] $Website, From d174cc10509caad0804a29246656ae3d619c8dd5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 23:05:21 +0200 Subject: [PATCH 14/37] Remove redundant type assignment in GitHubEnterprise property mapping --- src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 index 7dc37a898..f763a03f4 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 @@ -18,7 +18,6 @@ DisplayName = 'name' AvatarUrl = 'avatarUrl' Url = 'url' - Type = $Object.type ?? 'Enterprise' Website = 'websiteUrl' Location = 'location' CreatedAt = 'createdAt' From 92640f34b74a82d4385f6ab527d630a361d5cd26 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 23:30:01 +0200 Subject: [PATCH 15/37] Remove BillingEmail property from GitHubEnterprise class and related tests --- src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 | 6 ------ tests/Enterprise.Tests.ps1 | 1 - 2 files changed, 7 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 index f763a03f4..fb2640fc2 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 @@ -1,8 +1,4 @@ class GitHubEnterprise : GitHubOwner { - # The billing email address for the organization. - # Example: org@example.com - [string] $BillingEmail - # The readme of the enterprise. # Example: This is the readme for the enterprise [string] $Readme @@ -23,7 +19,6 @@ CreatedAt = 'createdAt' UpdatedAt = 'updatedAt' Description = 'description' - BillingEmail = 'billingEmail' Readme = 'readme' ReadmeHTML = 'readmeHTML' } @@ -48,7 +43,6 @@ $this.UpdatedAt = $Object.updatedAt # From GitHubEnterprise - $this.BillingEmail = $Object.billingEmail $this.Readme = $Object.readme $this.ReadmeHTML = $Object.readmeHTML } diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 8b003ef2c..21d41427c 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -56,7 +56,6 @@ Describe 'Template' { $enterprise.ID | Should -Be 15567 $enterprise.NodeID | Should -Be 'E_kgDNPM8' $enterprise.AvatarUrl | Should -Be 'https://avatars.githubusercontent.com/b/15567?v=4' - $enterprise.BillingEmail | Should -Be 'marstor@hotmail.com' $enterprise.Url | Should -Be 'https://github.com/enterprises/msx' $enterprise.Type | Should -Be 'Enterprise' $enterprise.Readme | Should -Be 'This is a test' From 44d0a8bfece7cf7356ec9bf8a346ceb54c01218f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 23:47:54 +0200 Subject: [PATCH 16/37] Refactor whitespace in GitHubEnterprise property mapping for improved consistency --- .../Owner/GitHubOwner/GitHubEnterprise.ps1 | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 index fb2640fc2..66fea40c4 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 @@ -8,19 +8,19 @@ [string] $ReadmeHTML static [hashtable] $PropertyToGraphQLMap = @{ - ID = 'databaseId' - NodeID = 'id' - Name = 'slug' - DisplayName = 'name' - AvatarUrl = 'avatarUrl' - Url = 'url' - Website = 'websiteUrl' - Location = 'location' - CreatedAt = 'createdAt' - UpdatedAt = 'updatedAt' - Description = 'description' - Readme = 'readme' - ReadmeHTML = 'readmeHTML' + ID = 'databaseId' + NodeID = 'id' + Name = 'slug' + DisplayName = 'name' + AvatarUrl = 'avatarUrl' + Url = 'url' + Website = 'websiteUrl' + Location = 'location' + CreatedAt = 'createdAt' + UpdatedAt = 'updatedAt' + Description = 'description' + Readme = 'readme' + ReadmeHTML = 'readmeHTML' } GitHubEnterprise() {} From abd8328af1b936ab22b8bd883e80d9e8f3cfa1dc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 23:55:44 +0200 Subject: [PATCH 17/37] Update GraphQL query structure in Get-GitHubEnterpriseList and fix date comparison in tests for consistency --- src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 | 2 +- tests/Enterprise.Tests.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 index 1c292d22d..a71c9482e 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -64,7 +64,7 @@ do { $enterpriseQuery = @{ query = @" -query { +query(`$perPage: Int!, `$after: String) { viewer { enterprises(first: `$perPage, after: `$after) { nodes { diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 21d41427c..9c7ccf59e 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -61,7 +61,7 @@ Describe 'Template' { $enterprise.Readme | Should -Be 'This is a test' $enterprise.ReadmeHTML | Should -Be '

This is a test

' $enterprise.CreatedAt | Should -BeOfType 'DateTime' - $enterprise.CreatedAt | Should -Be (Get-Date '18.09.2022 19:53:09') + $enterprise.CreatedAt | Should -Be '18.09.2022 19:53:09' $enterprise.UpdatedAt | Should -BeOfType 'DateTime' $enterprise.Description | Should -Be 'This is the description' $enterprise.Location | Should -Be 'Oslo, Norway' @@ -87,7 +87,7 @@ Describe 'Template' { $enterprises.Readme | Should -Be 'This is a test' $enterprises.ReadmeHTML | Should -Be '

This is a test

' $enterprises.CreatedAt | Should -BeOfType 'DateTime' - $enterprises.CreatedAt | Should -Be (Get-Date '18.09.2022 19:53:09') + $enterprises.CreatedAt | Should -Be '18.09.2022 19:53:09' $enterprises.UpdatedAt | Should -BeOfType 'DateTime' $enterprises.Description | Should -Be 'This is the description' $enterprises.Location | Should -Be 'Oslo, Norway' From 9e531327eb2867c271c27af85ecc263d913a8864 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 5 Jul 2025 23:55:58 +0200 Subject: [PATCH 18/37] Remove hardcoded CreatedAt date checks in GitHubEnterprise tests for improved flexibility --- tests/Enterprise.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 9c7ccf59e..90ab7084f 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -61,7 +61,6 @@ Describe 'Template' { $enterprise.Readme | Should -Be 'This is a test' $enterprise.ReadmeHTML | Should -Be '

This is a test

' $enterprise.CreatedAt | Should -BeOfType 'DateTime' - $enterprise.CreatedAt | Should -Be '18.09.2022 19:53:09' $enterprise.UpdatedAt | Should -BeOfType 'DateTime' $enterprise.Description | Should -Be 'This is the description' $enterprise.Location | Should -Be 'Oslo, Norway' @@ -87,7 +86,6 @@ Describe 'Template' { $enterprises.Readme | Should -Be 'This is a test' $enterprises.ReadmeHTML | Should -Be '

This is a test

' $enterprises.CreatedAt | Should -BeOfType 'DateTime' - $enterprises.CreatedAt | Should -Be '18.09.2022 19:53:09' $enterprises.UpdatedAt | Should -BeOfType 'DateTime' $enterprises.Description | Should -Be 'This is the description' $enterprises.Location | Should -Be 'Oslo, Norway' From 437959afce249b0f9bf63e8e160e30d978655525 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 08:23:03 +0200 Subject: [PATCH 19/37] Add pagination support to GraphQL query in Get-GitHubEnterpriseList function --- src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 index a71c9482e..bca8d3572 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -70,6 +70,10 @@ query(`$perPage: Int!, `$after: String) { nodes { $graphQLFields } + pageInfo { + endCursor + hasNextPage + } } } } From 3f4723f0a571e5ee0b38463ffd267ff62be5bb3d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 08:34:16 +0200 Subject: [PATCH 20/37] Add Pester tests for GitHub API interactions - Created TEMPLATE.ps1 for structuring Pester tests with authentication cases. - Implemented Teams.Tests.ps1 to test GitHub Teams API functionalities, including team creation, retrieval, updating, and deletion. - Developed Users.Tests.ps1 to validate user-related API calls, such as fetching user details and managing user emails. - Established Variables.Tests.ps1 for testing GitHub repository and organization variable management, including setting, updating, and removing variables. - Added necessary suppressions for Pester-related warnings and ensured proper logging for debugging. --- src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 | 1 + {tests => test2}/Apps.Tests.ps1 | 0 {tests => test2}/Artifacts.Tests.ps1 | 0 {tests => test2}/Environments.Tests.ps1 | 0 {tests => test2}/GitHub.Tests.ps1 | 0 {tests => test2}/Organizations.Tests.ps1 | 0 {tests => test2}/README.md | 0 {tests => test2}/Releases.Tests.ps1 | 0 {tests => test2}/Repositories.Tests.ps1 | 0 {tests => test2}/Secrets.Tests.ps1 | 0 {tests => test2}/TEMPLATE.ps1 | 0 {tests => test2}/Teams.Tests.ps1 | 0 {tests => test2}/Users.Tests.ps1 | 0 {tests => test2}/Variables.Tests.ps1 | 0 tests/Enterprise.Tests.ps1 | 2 +- 15 files changed, 2 insertions(+), 1 deletion(-) rename {tests => test2}/Apps.Tests.ps1 (100%) rename {tests => test2}/Artifacts.Tests.ps1 (100%) rename {tests => test2}/Environments.Tests.ps1 (100%) rename {tests => test2}/GitHub.Tests.ps1 (100%) rename {tests => test2}/Organizations.Tests.ps1 (100%) rename {tests => test2}/README.md (100%) rename {tests => test2}/Releases.Tests.ps1 (100%) rename {tests => test2}/Repositories.Tests.ps1 (100%) rename {tests => test2}/Secrets.Tests.ps1 (100%) rename {tests => test2}/TEMPLATE.ps1 (100%) rename {tests => test2}/Teams.Tests.ps1 (100%) rename {tests => test2}/Users.Tests.ps1 (100%) rename {tests => test2}/Variables.Tests.ps1 (100%) diff --git a/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 index 006b1a53f..20493743e 100644 --- a/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 +++ b/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 @@ -70,6 +70,7 @@ } process { + Write-Debug "ParameterSet: $($PSCmdlet.ParameterSetName)" switch ($PSCmdlet.ParameterSetName) { 'Get enterprise by name' { Get-GitHubEnterpriseByName -Name $Name -Context $Context diff --git a/tests/Apps.Tests.ps1 b/test2/Apps.Tests.ps1 similarity index 100% rename from tests/Apps.Tests.ps1 rename to test2/Apps.Tests.ps1 diff --git a/tests/Artifacts.Tests.ps1 b/test2/Artifacts.Tests.ps1 similarity index 100% rename from tests/Artifacts.Tests.ps1 rename to test2/Artifacts.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/test2/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to test2/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/test2/GitHub.Tests.ps1 similarity index 100% rename from tests/GitHub.Tests.ps1 rename to test2/GitHub.Tests.ps1 diff --git a/tests/Organizations.Tests.ps1 b/test2/Organizations.Tests.ps1 similarity index 100% rename from tests/Organizations.Tests.ps1 rename to test2/Organizations.Tests.ps1 diff --git a/tests/README.md b/test2/README.md similarity index 100% rename from tests/README.md rename to test2/README.md diff --git a/tests/Releases.Tests.ps1 b/test2/Releases.Tests.ps1 similarity index 100% rename from tests/Releases.Tests.ps1 rename to test2/Releases.Tests.ps1 diff --git a/tests/Repositories.Tests.ps1 b/test2/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to test2/Repositories.Tests.ps1 diff --git a/tests/Secrets.Tests.ps1 b/test2/Secrets.Tests.ps1 similarity index 100% rename from tests/Secrets.Tests.ps1 rename to test2/Secrets.Tests.ps1 diff --git a/tests/TEMPLATE.ps1 b/test2/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to test2/TEMPLATE.ps1 diff --git a/tests/Teams.Tests.ps1 b/test2/Teams.Tests.ps1 similarity index 100% rename from tests/Teams.Tests.ps1 rename to test2/Teams.Tests.ps1 diff --git a/tests/Users.Tests.ps1 b/test2/Users.Tests.ps1 similarity index 100% rename from tests/Users.Tests.ps1 rename to test2/Users.Tests.ps1 diff --git a/tests/Variables.Tests.ps1 b/test2/Variables.Tests.ps1 similarity index 100% rename from tests/Variables.Tests.ps1 rename to test2/Variables.Tests.ps1 diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 90ab7084f..771243fbe 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -68,7 +68,7 @@ Describe 'Template' { } It 'Get-GitHubEnterprise - Can get info about all available enterprises' -Skip:($OwnerType -notlike 'enterprise') { - $enterprises = Get-GitHubEnterprise + $enterprises = Get-GitHubEnterprise -Debug -Verbose LogGroup 'Enterprises' { Write-Host ($enterprises | Select-Object * | Out-String) } From 2cb9f366bc6498826a54e2124d19550605d5cb54 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 08:42:23 +0200 Subject: [PATCH 21/37] Fix initial hasNextPage value in Get-GitHubEnterpriseList function for correct pagination handling --- .../private/Enterprise/Get-GitHubEnterpriseList.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 index bca8d3572..17b51597c 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -55,7 +55,7 @@ } process { - $hasNextPage = $true + $hasNextPage = $false $after = $null $perPageSetting = Resolve-GitHubContextSetting -Name 'PerPage' -Value $PerPage -Context $Context @@ -87,10 +87,9 @@ query(`$perPage: Int!, `$after: String) { Invoke-GitHubGraphQLQuery @enterpriseQuery | ForEach-Object { foreach ($enterprise in $_.viewer.enterprises.nodes) { [GitHubEnterprise]::new($enterprise) - - $hasNextPage = $_.viewer.enterprises.pageInfo.hasNextPage - $after = $_.viewer.enterprises.pageInfo.endCursor } + $hasNextPage = $_.viewer.enterprises.pageInfo.hasNextPage + $after = $_.viewer.enterprises.pageInfo.endCursor } } while ($hasNextPage) } From b7a356e908ea51883f91eb33cfe8c659b2f4cd4f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 09:34:39 +0200 Subject: [PATCH 22/37] Add Get-GitHubOrganizationList function to retrieve organization details with pagination support --- .../Owner/GitHubOwner/GitHubOrganization.ps1 | 58 ++++++---- .../Get-GitHubOrganizationList.ps1 | 100 ++++++++++++++++++ 2 files changed, 138 insertions(+), 20 deletions(-) create mode 100644 src/functions/public/Organization/Get-GitHubOrganizationList.ps1 diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 6a359f92e..2394babcf 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -3,10 +3,6 @@ # Example: octocat@github.com [string] $Email - # The company the account is affiliated with. - # Example: GitHub - [string] $Company - # The Twitter username. # Example: monalisa [string] $TwitterUsername @@ -77,7 +73,7 @@ # Whether two-factor authentication is required for members. # Example: $true - [System.Nullable[bool]] $TwoFactorRequirementEnabled + [System.Nullable[bool]] $RequiresTwoFactorAuthentication # The type of repositories members can create. # Example: all @@ -162,29 +158,51 @@ # The date and time when the organization was archived, if applicable. [System.Nullable[datetime]] $ArchivedAt + static [hashtable] $PropertyToGraphQLMap = @{ + ArchivedAt = 'archivedAt' + AvatarUrl = 'avatarUrl' + CreatedAt = 'createdAt' + Description = 'description' + DisplayName = 'name' + Email = 'email' + ID = 'databaseId' + Location = 'location' + Name = 'login' + NodeID = 'id' + IsVerified = 'isVerified' + MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' + RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' + TwitterUsername = 'twitterUsername' + UpdatedAt = 'updatedAt' + Url = 'url' + IsAdmin = 'viewerIsAdmin' + IsMember = 'viewerIsAMember' + RequireWebCommitSignoff = 'webCommitSignoffRequired' + Website = 'websiteUrl' + } + GitHubOrganization() {} GitHubOrganization([PSCustomObject] $Object, [GitHubContext] $Context) { # From GitHubNode - $this.ID = $Object.id - $this.NodeID = $Object.node_id + $this.ID = $Object.databaseId ?? $Object.id + $this.NodeID = $Object.node_id ?? $Object.id # From GitHubOwner $this.Name = $Object.login $this.DisplayName = $Object.name - $this.AvatarUrl = $Object.avatar_url - $this.Url = $Object.html_url ?? "https://$($Context.HostName)/$($Object.login)" - $this.Type = $Object.type + $this.AvatarUrl = $Object.avatar_url ?? $Object.avatarUrl + $this.Url = $Object.html_url ?? $Object.url ?? "https://$($Context.HostName)/$($Object.login)" + $this.Type = $Object.type ?? 'Organization' $this.Location = $Object.location $this.Description = $Object.description - $this.Website = $Object.blog - $this.CreatedAt = $Object.created_at - $this.UpdatedAt = $Object.updated_at + $this.Website = $Object.website ?? $Object.blog + $this.CreatedAt = $Object.created_at ?? $Object.createdAt + $this.UpdatedAt = $Object.updated_at ?? $Object.updatedAt # From GitHubOrganization $this.Email = $Object.email - $this.Company = $Object.company - $this.TwitterUsername = $Object.twitter_username + $this.TwitterUsername = $Object.twitter_username ?? $Object.twitterUsername $this.Plan = [GitHubPlan]::New($Object.plan) $this.PublicRepos = $Object.public_repos $this.PublicGists = $Object.public_gists @@ -195,21 +213,21 @@ $this.OwnedPrivateRepos = $Object.owned_private_repos $this.DiskUsage = $Object.disk_usage $this.Collaborators = $Object.collaborators - $this.IsVerified = $Object.is_verified + $this.IsVerified = $Object.is_verified ?? $Object.isVerified $this.HasOrganizationProjects = $Object.has_organization_projects $this.HasRepositoryProjects = $Object.has_repository_projects $this.BillingEmail = $Object.billing_email $this.DefaultRepositoryPermission = $Object.default_repository_permission $this.MembersCanCreateRepositories = $Object.members_can_create_repositories - $this.TwoFactorRequirementEnabled = $Object.two_factor_requirement_enabled + $this.RequiresTwoFactorAuthentication = $Object.two_factor_requirement_enabled ?? $Object.requiresTwoFactorAuthentication $this.MembersAllowedRepositoryCreationType = $Object.members_allowed_repository_creation_type $this.MembersCanCreatePublicRepositories = $Object.members_can_create_public_repositories $this.MembersCanCreatePrivateRepositories = $Object.members_can_create_private_repositories $this.MembersCanCreateInternalRepositories = $Object.members_can_create_internal_repositories $this.MembersCanInviteCollaborators = $Object.members_can_invite_collaborators $this.MembersCanCreatePages = $Object.members_can_create_pages - $this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories - $this.RequireWebCommitSignoff = $Object.web_commit_signoff_required + $this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories ?? $Object.membersCanForkPrivateRepositories + $this.RequireWebCommitSignoff = $Object.web_commit_signoff_required ?? $Object.requiresTwoFactorAuthentication $this.DeployKeysEnabledForRepositories = $Object.deploy_keys_enabled_for_repositories $this.MembersCanCreatePublicPages = $Object.members_can_create_public_pages $this.MembersCanCreatePrivatePages = $Object.members_can_create_private_pages @@ -222,7 +240,7 @@ $this.SecretScanningPushProtectionCustomLinkEnabled = $Object.secret_scanning_push_protection_custom_link_enabled $this.SecretScanningPushProtectionCustomLink = $Object.secret_scanning_push_protection_custom_link $this.SecretScanningValidityChecksEnabled = $Object.secret_scanning_validity_checks_enabled - $this.ArchivedAt = $Object.archived_at + $this.ArchivedAt = $Object.archived_at ?? $Object.archivedAt } [string] ToString() { diff --git a/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 b/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 new file mode 100644 index 000000000..28ff45925 --- /dev/null +++ b/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 @@ -0,0 +1,100 @@ +function Get-GitHubOrganizationList { + <# + .SYNOPSIS + Retrieves a list of all GitHub organizations. + + .DESCRIPTION + This function retrieves detailed information about all GitHub organizations that the authenticated user belongs to, including their avatars, + creation dates, member counts, and other metadata. It returns an array of objects of type GitHubOrganization populated with this information. + + .EXAMPLE + Get-GitHubOrganizationList + + Output: + ```powershell + Name : MyOrganization + Login : my-org + URL : https://github.com/my-org + CreatedAt : 2022-01-01T00:00:00Z + + Name : Another Organization + Login : another-org + URL : https://github.com/another-org + CreatedAt : 2021-12-01T00:00:00Z + ``` + + Retrieves details about the GitHub organizations the authenticated user belongs to. + + .OUTPUTS + GitHubOrganization[] + + .NOTES + An array of objects containing detailed information about the GitHub organizations, including member info, URLs, and metadata. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'hasNextPage', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'after', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [OutputType([GitHubOrganization[]])] + [CmdletBinding()] + param( + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $hasNextPage = $false + $after = $null + $perPageSetting = Resolve-GitHubContextSetting -Name 'PerPage' -Value $PerPage -Context $Context + + $graphQLFields = ([GitHubOrganization]::PropertyToGraphQLMap).Values + + do { + $organizationQuery = @{ + query = @" +query(`$perPage: Int!, `$after: String) { + viewer { + organizations(first: `$perPage, after: `$after) { + nodes { + $graphQLFields + } + pageInfo { + endCursor + hasNextPage + } + } + } +} +"@ + Variables = @{ + perPage = $perPageSetting + after = $after + } + Context = $Context + } + Invoke-GitHubGraphQLQuery @organizationQuery | ForEach-Object { + foreach ($organization in $_.viewer.organizations.nodes) { + [GitHubOrganization]::new($organization) + } + $hasNextPage = $_.viewer.organizations.pageInfo.hasNextPage + $after = $_.viewer.organizations.pageInfo.endCursor + } + } while ($hasNextPage) + } + + end { + Write-Debug "[$stackPath] - End" + } +} From e4f218e507b02f111a465d84eb726b0ee64abd0d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 18:07:24 +0200 Subject: [PATCH 23/37] Unskip test for Get-GitHubEnterprise to ensure it runs for enterprise type --- tests/Enterprise.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 771243fbe..8e8aa58c5 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -44,7 +44,8 @@ Describe 'Template' { Write-Host ('-' * 60) } - It 'Get-GitHubEnterprise - Can get info about an enterprise' -Skip:($OwnerType -notlike 'enterprise') { + # -Skip:(($OwnerType -ne 'enterprise') -or ()) + It 'Get-GitHubEnterprise - Can get info about an enterprise' { $enterprise = Get-GitHubEnterprise -Name $Owner LogGroup 'Enterprise' { Write-Host ($enterprise | Select-Object * | Out-String) From a41e6bfeeced9511737644fd67021f95761d20d2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 18:08:33 +0200 Subject: [PATCH 24/37] Remove debug and verbose flags from Get-GitHubEnterprise call in test for available enterprises --- tests/Enterprise.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 8e8aa58c5..c8efbee48 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -69,7 +69,7 @@ Describe 'Template' { } It 'Get-GitHubEnterprise - Can get info about all available enterprises' -Skip:($OwnerType -notlike 'enterprise') { - $enterprises = Get-GitHubEnterprise -Debug -Verbose + $enterprises = Get-GitHubEnterprise LogGroup 'Enterprises' { Write-Host ($enterprises | Select-Object * | Out-String) } From a5770a981115bef8f732f5533ae896b6fb3ad48b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 18:13:34 +0200 Subject: [PATCH 25/37] Unskip test for Get-GitHubEnterprise to ensure it runs for available enterprises --- tests/Enterprise.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index c8efbee48..09acd89ef 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -68,7 +68,8 @@ Describe 'Template' { $enterprise.Website | Should -Be 'https://msx.no' } - It 'Get-GitHubEnterprise - Can get info about all available enterprises' -Skip:($OwnerType -notlike 'enterprise') { + #-Skip:($OwnerType -notlike 'enterprise') + It 'Get-GitHubEnterprise - Can get info about all available enterprises' { $enterprises = Get-GitHubEnterprise LogGroup 'Enterprises' { Write-Host ($enterprises | Select-Object * | Out-String) From 23086700e01cfc68a10a707d569b0c59a4d1b0a0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 18:22:36 +0200 Subject: [PATCH 26/37] Unskip test for Get-GitHubEnterprise to ensure it runs for enterprise type --- tests/Enterprise.Tests.ps1 | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/tests/Enterprise.Tests.ps1 b/tests/Enterprise.Tests.ps1 index 09acd89ef..b6b7a73dd 100644 --- a/tests/Enterprise.Tests.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -44,8 +44,7 @@ Describe 'Template' { Write-Host ('-' * 60) } - # -Skip:(($OwnerType -ne 'enterprise') -or ()) - It 'Get-GitHubEnterprise - Can get info about an enterprise' { + It 'Get-GitHubEnterprise - Can get info about an enterprise' -Skip:($OwnerType -ne 'enterprise') { $enterprise = Get-GitHubEnterprise -Name $Owner LogGroup 'Enterprise' { Write-Host ($enterprise | Select-Object * | Out-String) @@ -67,31 +66,5 @@ Describe 'Template' { $enterprise.Location | Should -Be 'Oslo, Norway' $enterprise.Website | Should -Be 'https://msx.no' } - - #-Skip:($OwnerType -notlike 'enterprise') - It 'Get-GitHubEnterprise - Can get info about all available enterprises' { - $enterprises = Get-GitHubEnterprise - LogGroup 'Enterprises' { - Write-Host ($enterprises | Select-Object * | Out-String) - } - $enterprises.count | Should -Be 1 - $enterprises | Should -Not -BeNullOrEmpty - $enterprises | Should -BeOfType 'GitHubEnterprise' - $enterprises.Name | Should -Be 'msx' - $enterprises.DisplayName | Should -Be 'MSX' - $enterprises.ID | Should -Be 15567 - $enterprises.NodeID | Should -Be 'E_kgDNPM8' - $enterprises.AvatarUrl | Should -Be 'https://avatars.githubusercontent.com/b/15567?v=4' - $enterprises.BillingEmail | Should -Be 'marstor@hotmail.com' - $enterprises.Url | Should -Be 'https://github.com/enterprises/msx' - $enterprises.Type | Should -Be 'Enterprise' - $enterprises.Readme | Should -Be 'This is a test' - $enterprises.ReadmeHTML | Should -Be '

This is a test

' - $enterprises.CreatedAt | Should -BeOfType 'DateTime' - $enterprises.UpdatedAt | Should -BeOfType 'DateTime' - $enterprises.Description | Should -Be 'This is the description' - $enterprises.Location | Should -Be 'Oslo, Norway' - $enterprises.Website | Should -Be 'https://msx.no' - } } } From 6a4b82753c75e434aa3bc3a3018ec80e3503f915 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 18:37:25 +0200 Subject: [PATCH 27/37] Remove IsAdmin and IsMember fields from GitHubOrganization mapping --- src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 2394babcf..e2eba0fd5 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -175,8 +175,6 @@ TwitterUsername = 'twitterUsername' UpdatedAt = 'updatedAt' Url = 'url' - IsAdmin = 'viewerIsAdmin' - IsMember = 'viewerIsAMember' RequireWebCommitSignoff = 'webCommitSignoffRequired' Website = 'websiteUrl' } From a99a017631add4cd6a3fd2ff469e044ef3d99fa2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:12:50 +0200 Subject: [PATCH 28/37] Pass Context parameter to GitHubOrganization constructor in Get-GitHubOrganizationList function --- .../public/Organization/Get-GitHubOrganizationList.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 b/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 index 28ff45925..b584fa36e 100644 --- a/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 +++ b/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 @@ -86,7 +86,7 @@ query(`$perPage: Int!, `$after: String) { } Invoke-GitHubGraphQLQuery @organizationQuery | ForEach-Object { foreach ($organization in $_.viewer.organizations.nodes) { - [GitHubOrganization]::new($organization) + [GitHubOrganization]::new($organization, $Context) } $hasNextPage = $_.viewer.organizations.pageInfo.hasNextPage $after = $_.viewer.organizations.pageInfo.endCursor From 7653e6ba59c59114e8225d38606ae65ac891652a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:22:55 +0200 Subject: [PATCH 29/37] Make Context parameter mandatory in Get-GitHubEnterprise functions and comment out RequiresTwoFactorAuthentication in GitHubOrganization mapping --- src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 | 2 +- src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 | 2 +- src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index e2eba0fd5..76b61103f 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -171,7 +171,7 @@ NodeID = 'id' IsVerified = 'isVerified' MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' - RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' + # RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' TwitterUsername = 'twitterUsername' UpdatedAt = 'updatedAt' Url = 'url' diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 index 6fc6f9309..81d33aa5d 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 @@ -38,7 +38,7 @@ # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. - [Parameter()] + [Parameter(Mandatory)] [object] $Context ) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 index 17b51597c..cd2f890e4 100644 --- a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -44,7 +44,7 @@ param( # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. - [Parameter()] + [Parameter(Mandatory)] [object] $Context ) From 4557c194aeb2a3f069ba57d5362eaa72e6cdd53c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:30:50 +0200 Subject: [PATCH 30/37] Comment out MembersCanForkPrivateRepositories mapping in GitHubOrganization --- src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 76b61103f..29edc37d7 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -170,7 +170,7 @@ Name = 'login' NodeID = 'id' IsVerified = 'isVerified' - MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' + # MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' # RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' TwitterUsername = 'twitterUsername' UpdatedAt = 'updatedAt' From e070866bf3d04985d47aa265bbc35b6cbc19be0a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:31:04 +0200 Subject: [PATCH 31/37] Comment out MembersCanForkPrivateRepositories and RequiresTwoFactorAuthentication mappings in GitHubOrganization --- .../Owner/GitHubOwner/GitHubOrganization.ps1 | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 29edc37d7..85b2c77f1 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -159,24 +159,24 @@ [System.Nullable[datetime]] $ArchivedAt static [hashtable] $PropertyToGraphQLMap = @{ - ArchivedAt = 'archivedAt' - AvatarUrl = 'avatarUrl' - CreatedAt = 'createdAt' - Description = 'description' - DisplayName = 'name' - Email = 'email' - ID = 'databaseId' - Location = 'location' - Name = 'login' - NodeID = 'id' - IsVerified = 'isVerified' + ArchivedAt = 'archivedAt' + AvatarUrl = 'avatarUrl' + CreatedAt = 'createdAt' + Description = 'description' + DisplayName = 'name' + Email = 'email' + ID = 'databaseId' + Location = 'location' + Name = 'login' + NodeID = 'id' + IsVerified = 'isVerified' # MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' # RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' - TwitterUsername = 'twitterUsername' - UpdatedAt = 'updatedAt' - Url = 'url' - RequireWebCommitSignoff = 'webCommitSignoffRequired' - Website = 'websiteUrl' + TwitterUsername = 'twitterUsername' + UpdatedAt = 'updatedAt' + Url = 'url' + RequireWebCommitSignoff = 'webCommitSignoffRequired' + Website = 'websiteUrl' } GitHubOrganization() {} From 1ff536acfc4ff0ad1ccd19da12b9f40f2b46a18e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:39:22 +0200 Subject: [PATCH 32/37] Add Get-GitHubOrganizationListForAuthUser function and update references --- .../Organization/Get-GitHubMyOrganization.ps1 | 65 ------------------- ...Get-GitHubOrganizationListForAuthUser.ps1} | 8 +-- .../Organization/Get-GitHubOrganization.ps1 | 2 +- {test2 => tests}/Organizations.Tests.ps1 | 0 4 files changed, 5 insertions(+), 70 deletions(-) delete mode 100644 src/functions/private/Organization/Get-GitHubMyOrganization.ps1 rename src/functions/{public/Organization/Get-GitHubOrganizationList.ps1 => private/Organization/Get-GitHubOrganizationListForAuthUser.ps1} (93%) rename {test2 => tests}/Organizations.Tests.ps1 (100%) diff --git a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 deleted file mode 100644 index 9d56307f4..000000000 --- a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 +++ /dev/null @@ -1,65 +0,0 @@ -filter Get-GitHubMyOrganization { - <# - .SYNOPSIS - List organizations for the authenticated user - - .DESCRIPTION - List organizations for the authenticated user. - - **OAuth scope requirements** - - This only lists organizations that your authorization allows you to operate on - in some way (e.g., you can list teams with `read:org` scope, you can publicize your - organization membership with `user` scope, etc.). Therefore, this API requires at - least `user` or `read:org` scope. OAuth requests with insufficient scope receive a - `403 Forbidden` response. - - .EXAMPLE - Get-GitHubMyOrganization - - List organizations for the authenticated user. - - .OUTPUTS - GitHubOrganization - - .NOTES - [List organizations for the authenticated user](https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user) - #> - [OutputType([GitHubOrganization])] - [CmdletBinding()] - param( - # The number of results per page (max 100). - [Parameter()] - [System.Nullable[int]] $PerPage, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = '/user/orgs' - PerPage = $PerPage - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - foreach ($organization in $_.Response) { - [GitHubOrganization]::new($organization, $Context) - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 similarity index 93% rename from src/functions/public/Organization/Get-GitHubOrganizationList.ps1 rename to src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 index b584fa36e..352317398 100644 --- a/src/functions/public/Organization/Get-GitHubOrganizationList.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 @@ -1,14 +1,14 @@ -function Get-GitHubOrganizationList { +function Get-GitHubOrganizationListForAuthUser { <# .SYNOPSIS - Retrieves a list of all GitHub organizations. + Retrieves a list of all GitHub organizations for the authenticated user. .DESCRIPTION This function retrieves detailed information about all GitHub organizations that the authenticated user belongs to, including their avatars, creation dates, member counts, and other metadata. It returns an array of objects of type GitHubOrganization populated with this information. .EXAMPLE - Get-GitHubOrganizationList + Get-GitHubOrganizationListForAuthUser Output: ```powershell @@ -44,7 +44,7 @@ param( # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. - [Parameter()] + [Parameter(Mandatory)] [object] $Context ) diff --git a/src/functions/public/Organization/Get-GitHubOrganization.ps1 b/src/functions/public/Organization/Get-GitHubOrganization.ps1 index cd490cd5d..526e66e74 100644 --- a/src/functions/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Get-GitHubOrganization.ps1 @@ -114,7 +114,7 @@ Get-GitHubAllOrganization -Since $Since -PerPage $PerPage -Context $Context } 'List all organizations for the authenticated user' { - Get-GitHubMyOrganization -PerPage $PerPage -Context $Context + Get-GitHubOrganizationListForAuthUser -PerPage $PerPage -Context $Context } default { Write-Error "Invalid parameter set name: $($PSCmdlet.ParameterSetName)" diff --git a/test2/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 similarity index 100% rename from test2/Organizations.Tests.ps1 rename to tests/Organizations.Tests.ps1 From 7ab92ef7e7f6ad418ea1ba8ecd115b0ed0dc9a29 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:48:47 +0200 Subject: [PATCH 33/37] Add PerPage parameter to Get-GitHubOrganizationListForAuthUser function --- .../Organization/Get-GitHubOrganizationListForAuthUser.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 index 352317398..9ff03c5f6 100644 --- a/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 @@ -42,6 +42,9 @@ [OutputType([GitHubOrganization[]])] [CmdletBinding()] param( + # The number of results per page (max 100). + [System.Nullable[int]] $PerPage, + # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. [Parameter(Mandatory)] From 589f2961f22a1e719913610a81ebff95dc41a0f6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:49:15 +0200 Subject: [PATCH 34/37] Add Parameter attribute to PerPage in Get-GitHubOrganizationListForAuthUser function --- .../Organization/Get-GitHubOrganizationListForAuthUser.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 index 9ff03c5f6..a8024ee6b 100644 --- a/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 @@ -43,6 +43,7 @@ [CmdletBinding()] param( # The number of results per page (max 100). + [Parameter()] [System.Nullable[int]] $PerPage, # The context to run the command in. Used to get the details for the API call. From ad37bef098f93330c866cd53d520d1f4fb77608b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 19:56:22 +0200 Subject: [PATCH 35/37] Refactor property mapping in GitHubOrganization class and comment out unused mappings --- .../Owner/GitHubOwner/GitHubOrganization.ps1 | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 85b2c77f1..48528dba2 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -159,24 +159,24 @@ [System.Nullable[datetime]] $ArchivedAt static [hashtable] $PropertyToGraphQLMap = @{ - ArchivedAt = 'archivedAt' - AvatarUrl = 'avatarUrl' - CreatedAt = 'createdAt' - Description = 'description' - DisplayName = 'name' - Email = 'email' - ID = 'databaseId' - Location = 'location' - Name = 'login' - NodeID = 'id' - IsVerified = 'isVerified' + ArchivedAt = 'archivedAt' + AvatarUrl = 'avatarUrl' + CreatedAt = 'createdAt' + Description = 'description' + DisplayName = 'name' + Email = 'email' + ID = 'databaseId' + Location = 'location' + Name = 'login' + NodeID = 'id' + IsVerified = 'isVerified' # MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' # RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' - TwitterUsername = 'twitterUsername' - UpdatedAt = 'updatedAt' - Url = 'url' - RequireWebCommitSignoff = 'webCommitSignoffRequired' - Website = 'websiteUrl' + TwitterUsername = 'twitterUsername' + UpdatedAt = 'updatedAt' + Url = 'url' + # RequireWebCommitSignoff = 'webCommitSignoffRequired' + Website = 'websiteUrl' } GitHubOrganization() {} From 62c7f1067994a548918101ac699c198ff1c61085 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 20:32:46 +0200 Subject: [PATCH 36/37] Add initial test scripts for GitHub API interactions - Created TEMPLATE.ps1 for Pester testing framework setup. - Added Teams.Tests.ps1 to test GitHub Teams API functionalities. - Introduced Users.Tests.ps1 for testing user-related API endpoints. - Implemented Variables.Tests.ps1 to validate GitHub variable management. - Each test file includes necessary setup, teardown, and context-specific tests. --- {test2 => tests}/Apps.Tests.ps1 | 0 {test2 => tests}/Artifacts.Tests.ps1 | 0 {test2 => tests}/Environments.Tests.ps1 | 0 {test2 => tests}/GitHub.Tests.ps1 | 0 {test2 => tests}/README.md | 0 {test2 => tests}/Releases.Tests.ps1 | 0 {test2 => tests}/Repositories.Tests.ps1 | 0 {test2 => tests}/Secrets.Tests.ps1 | 0 {test2 => tests}/TEMPLATE.ps1 | 0 {test2 => tests}/Teams.Tests.ps1 | 0 {test2 => tests}/Users.Tests.ps1 | 0 {test2 => tests}/Variables.Tests.ps1 | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename {test2 => tests}/Apps.Tests.ps1 (100%) rename {test2 => tests}/Artifacts.Tests.ps1 (100%) rename {test2 => tests}/Environments.Tests.ps1 (100%) rename {test2 => tests}/GitHub.Tests.ps1 (100%) rename {test2 => tests}/README.md (100%) rename {test2 => tests}/Releases.Tests.ps1 (100%) rename {test2 => tests}/Repositories.Tests.ps1 (100%) rename {test2 => tests}/Secrets.Tests.ps1 (100%) rename {test2 => tests}/TEMPLATE.ps1 (100%) rename {test2 => tests}/Teams.Tests.ps1 (100%) rename {test2 => tests}/Users.Tests.ps1 (100%) rename {test2 => tests}/Variables.Tests.ps1 (100%) diff --git a/test2/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 similarity index 100% rename from test2/Apps.Tests.ps1 rename to tests/Apps.Tests.ps1 diff --git a/test2/Artifacts.Tests.ps1 b/tests/Artifacts.Tests.ps1 similarity index 100% rename from test2/Artifacts.Tests.ps1 rename to tests/Artifacts.Tests.ps1 diff --git a/test2/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from test2/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/test2/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 100% rename from test2/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 diff --git a/test2/README.md b/tests/README.md similarity index 100% rename from test2/README.md rename to tests/README.md diff --git a/test2/Releases.Tests.ps1 b/tests/Releases.Tests.ps1 similarity index 100% rename from test2/Releases.Tests.ps1 rename to tests/Releases.Tests.ps1 diff --git a/test2/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from test2/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/test2/Secrets.Tests.ps1 b/tests/Secrets.Tests.ps1 similarity index 100% rename from test2/Secrets.Tests.ps1 rename to tests/Secrets.Tests.ps1 diff --git a/test2/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from test2/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/test2/Teams.Tests.ps1 b/tests/Teams.Tests.ps1 similarity index 100% rename from test2/Teams.Tests.ps1 rename to tests/Teams.Tests.ps1 diff --git a/test2/Users.Tests.ps1 b/tests/Users.Tests.ps1 similarity index 100% rename from test2/Users.Tests.ps1 rename to tests/Users.Tests.ps1 diff --git a/test2/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 similarity index 100% rename from test2/Variables.Tests.ps1 rename to tests/Variables.Tests.ps1 From ed8553104b18c268856fa1f3880bce9e268845f7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 6 Jul 2025 20:33:12 +0200 Subject: [PATCH 37/37] Update CodeCoverage PercentTarget to 50 in PSModule.yml --- .github/PSModule.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index c1eb7bd1a..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,3 @@ Test: CodeCoverage: - PercentTarget: 0 + PercentTarget: 50