Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
76d9f88
🩹 [Patch]: Add New-GitHubOrganization function to create organization…
MariusStorhaug Jul 4, 2025
f51059c
🩹 [Patch]: Cleanup of Context usage in classes, and functions for Rep…
MariusStorhaug Jul 6, 2025
af28e9e
Add initial test scripts for GitHub API interactions
MariusStorhaug Jul 7, 2025
3a65044
🩹 [Patch]: Fix property mapping for web commit signoff in GitHubOrgan…
MariusStorhaug Jul 7, 2025
bf3b3ff
Merge branch 'main' of https://github.com/PSModule/GitHub into organi…
MariusStorhaug Jul 7, 2025
c516558
🩹 [Patch]: Update output type and repository selection validation in …
MariusStorhaug Jul 7, 2025
a96765c
🩹 [Patch]: Add cleanup for enterprise organizations in AfterAll block…
MariusStorhaug Jul 7, 2025
c7cc346
🩹 [Patch]: Update organization removal logic in AfterAll block to use…
MariusStorhaug Jul 7, 2025
82a012c
🩹 [Patch]: Pass context to GitHubOrganization constructor in New-GitH…
MariusStorhaug Jul 7, 2025
25f37ba
🩹 [Patch]: Enhance New-GitHubOrganization function by adding mandator…
MariusStorhaug Jul 7, 2025
62cb520
🩹 [Patch]: Ensure context is resolved in New-GitHubOrganization funct…
MariusStorhaug Jul 7, 2025
ce1c0c2
🩹 [Patch]: Enhance organization cleanup logic in AfterAll block to lo…
MariusStorhaug Jul 7, 2025
50db04b
🩹 [Patch]: Update Get-GitHubOrganization calls to include -Enterprise…
MariusStorhaug Jul 7, 2025
905c7da
🩹 [Patch]: Refactor organization retrieval logic in test cases; remov…
MariusStorhaug Jul 7, 2025
c5f3a20
🩹 [Patch]: Update Get-GitHubOrganization calls to include -Enterprise…
MariusStorhaug Jul 7, 2025
cd3b7e1
🩹 [Patch]: Add logging for organization retrieval in enterprise conte…
MariusStorhaug Jul 7, 2025
571bb8e
🩹 [Patch]: Add logging for organization retrieval in AfterAll block f…
MariusStorhaug Jul 7, 2025
a544b0a
🩹 [Patch]: Simplify organization cleanup in AfterAll block by removin…
MariusStorhaug Jul 7, 2025
149de4c
🩹 [Patch]: Set default parameter set name for CmdletBinding in Remove…
MariusStorhaug Jul 7, 2025
fc62a39
🩹 [Patch]: Bypass confirmation prompt in Remove-GitHubOrganization fo…
MariusStorhaug Jul 7, 2025
d539d43
🩹 [Patch]: Remove organization deletion for enterprise in AfterAll block
MariusStorhaug Jul 7, 2025
500dc24
🩹 [Patch]: Add test for updating organization location in Update-GitH…
MariusStorhaug Jul 7, 2025
9511cd1
🩹 [Patch]: Refactor organization tests to improve context handling an…
MariusStorhaug Jul 7, 2025
3adf4af
🩹 [Patch]: Remove commented placeholder for app tests in Organization…
MariusStorhaug Jul 7, 2025
676869b
🩹 [Patch]: Update Connect-GitHubApp test to skip for non-enterprise o…
MariusStorhaug Jul 7, 2025
75baf11
🩹 [Patch]: Enhance error logging in Invoke-GitHubAPI by adding contex…
MariusStorhaug Jul 7, 2025
b2375ab
🩹 [Patch]: Update organization location and removal tests to expect e…
MariusStorhaug Jul 7, 2025
00bade5
Add comprehensive Pester tests for GitHub API interactions
MariusStorhaug Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/Organizations/Organization.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$orgParam = @{
Enterprise = 'msx'
Name = 'Marius-Test7'
Owner = 'GitHub-Automation'
BillingEmail = 'post@msx.no'
}
$org = New-GitHubOrganization @orgParam

$installAppParam = @{
Enterprise = 'msx'
Organization = $org.login
ClientID = (Get-GitHubContext).ClientID
RepositorySelection = 'all'
}
Install-GitHubApp @installAppParam

$updateOrgParam = @{
Name = $org.login
Description = 'Test organization created by PowerShell script'
Location = 'Oslo, Norway'
BillingEmail = 'post@msx.no'
Company = 'MSX AS'
Email = 'info@msx.no'
Blog = 'https://msx.no/blog'
TwitterUsername = 'msx_no'
HasOrganizationProjects = $true
DefaultRepositoryPermission = 'read'
MembersCanCreateRepositories = $true
MembersCanCreatePublicRepositories = $true
MembersCanCreatePrivateRepositories = $true
MembersCanCreateInternalRepositories = $true
MembersCanCreatePages = $true
MembersCanCreatePublicPages = $true
MembersCanCreatePrivatePages = $true
MembersCanForkPrivateRepositories = $true
WebCommitSignoffRequired = $false
SecretScanningPushProtectionEnabledForNewRepositories = $true
SecretScanningPushProtectionCustomLinkEnabled = $false
SecretScanningPushProtectionCustomLink = '<link>'
}
Update-GitHubOrganization @updateOrgParam
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
$this.MembersCanInviteCollaborators = $Object.members_can_invite_collaborators
$this.MembersCanCreatePages = $Object.members_can_create_pages
$this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories ?? $Object.membersCanForkPrivateRepositories
$this.RequireWebCommitSignoff = $Object.web_commit_signoff_required ?? $Object.requiresTwoFactorAuthentication
$this.RequireWebCommitSignoff = $Object.web_commit_signoff_required ?? $Object.webCommitSignoffRequired
$this.DeployKeysEnabledForRepositories = $Object.deploy_keys_enabled_for_repositories
$this.MembersCanCreatePublicPages = $Object.members_can_create_public_pages
$this.MembersCanCreatePrivatePages = $Object.members_can_create_private_pages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.EXAMPLE
Install-GitHubAppOnEnterpriseOrganization -Enterprise 'msx' -Organization 'org' -ClientID '123456'
#>
[OutputType([GitHubAppInstallation])]
[CmdletBinding()]
param(
# The enterprise slug or ID.
Expand All @@ -29,7 +30,7 @@
# - all - all repositories that the authenticated GitHub App installation can access.
# - selected - select specific repositories.
[Parameter(Mandatory)]
[ValidateSet('all', 'selected')]
[ValidateSet('All', 'Selected')]
[string] $RepositorySelection,

# The names of the repositories to which the installation will be granted access.
Expand All @@ -49,6 +50,9 @@
}

process {
if ($RepositorySelection) {
$RepositorySelection = $RepositorySelection.ToLower()
}
$body = @{
client_id = $ClientID
repository_selection = $RepositorySelection
Expand All @@ -64,7 +68,7 @@
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
[GitHubAppInstallation]::new($_.Response)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/functions/public/API/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ function Invoke-GitHubAPI {
}

$exception = @"

----------------------------------
Context:
$($Context | Format-List | Out-String)
----------------------------------
Request:
$([pscustomobject]$APICall | Select-Object -ExcludeProperty Body, Headers | Format-List | Out-String)
Expand Down
88 changes: 88 additions & 0 deletions src/functions/public/Organization/New-GitHubOrganization.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
function New-GitHubOrganization {
<#
.SYNOPSIS
Creates a new GitHub organization within a specified enterprise.

.DESCRIPTION
This function creates a new GitHub organization within the specified enterprise.

.EXAMPLE
New-GitHubOrganization -Enterprise 'my-enterprise' -Name 'my-org' -Owner 'user1' -BillingEmail 'billing@example.com'

.OUTPUTS
GitHubOrganization

.LINK
https://psmodule.io/GitHub/Functions/Organization/New-GitHubOrganization/
#>
[OutputType([GitHubOrganization])]
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
param(
# The name of the enterprise to create the organization in.
[Parameter()]
[string]$Enterprise,

# The name of the organization to create.
[Parameter(Mandatory)]
[string]$Name,

# The owners of the organization. This should be a list of GitHub usernames.
[Parameter(Mandatory)]
[string[]]$Owner,

# The billing email for the organization.
[Parameter()]
[string]$BillingEmail,

# 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"
$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT
}

process {
$enterpriseObject = Get-GitHubEnterprise -Name $Enterprise -Context $Context
Write-Verbose "Creating organization in enterprise: $($enterpriseObject.Name)"
$graphQLFields = ([GitHubOrganization]::PropertyToGraphQLMap).Values

$inputParams = @{
adminLogins = $Owner
billingEmail = $BillingEmail
enterpriseId = $enterpriseObject.NodeID
login = $Name
profileName = $Name
}

$updateGraphQLInputs = @{
Query = @"
mutation(`$input:CreateEnterpriseOrganizationInput!) {
createEnterpriseOrganization(input:`$input) {
organization {
$graphQLFields
}
}
}
"@
Variables = @{
input = $inputParams
}
Context = $Context
}
if ($PSCmdlet.ShouldProcess("Creating organization '$Name' in enterprise '$Enterprise'")) {
$orgresult = Invoke-GitHubGraphQLQuery @updateGraphQLInputs
[GitHubOrganization]::new($orgresult.createEnterpriseOrganization.organization, $Context)
}
}

end {
Write-Debug "[$stackPath] - End"
}
}

42 changes: 27 additions & 15 deletions src/functions/public/Organization/Remove-GitHubOrganization.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
https://psmodule.io/GitHub/Functions/Organization/Remove-GitHubOrganization
#>
[OutputType([void])]
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
[CmdletBinding(DefaultParameterSetName = 'Remove an organization', SupportsShouldProcess, ConfirmImpact = 'High')]
param(
# The organization name. The name is not case sensitive.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string] $Name,

# The input object to process. Can be a single or an array of GitHubOrganization objects.
[Parameter(Mandatory, ParameterSetName = 'ArrayInput', ValueFromPipeline)]
[GitHubOrganization[]] $InputObject,

# 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()]
Expand All @@ -48,20 +48,32 @@
}

process {
$inputObject = @{
Method = 'DELETE'
APIEndpoint = "/orgs/$Name"
Context = $Context
}
switch ($PSCmdlet.ParameterSetName) {
'ArrayInput' {
foreach ($item in $InputObject) {
$params = @{
Name = $item.Name
Context = $Context
}
Remove-GitHubOrganization @params
}
break
}
default {
$apiParams = @{
Method = 'DELETE'
APIEndpoint = "/orgs/$Name"
Context = $Context
}

if ($PSCmdlet.ShouldProcess("organization [$Name]", 'DELETE')) {
$null = Invoke-GitHubAPI @inputObject
if ($PSCmdlet.ShouldProcess("organization [$Name]", 'Delete')) {
$null = Invoke-GitHubAPI @apiParams
}
}
}
}

end {
Write-Debug "[$stackPath] - End"
}
}

#SkipTest:FunctionTest:Will add a test for this function in a future PR
Loading