Skip to content

Commit eddd08e

Browse files
committed
fix github removal script
1 parent 7217501 commit eddd08e

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/ALZ/Private/Tools/Checks/Test-GitHubCli.ps1

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,37 @@ function Test-GitHubCli {
1616

1717
# Check if GitHub CLI is authenticated
1818
Write-Verbose "Checking GitHub CLI authentication status"
19-
$null = gh auth status 2>&1
19+
$authStatus = gh auth status 2>&1
2020
if ($LASTEXITCODE -eq 0) {
2121
$results += @{
2222
message = "GitHub CLI is authenticated."
2323
result = "Success"
2424
}
25+
26+
# Check if admin:org scope is available
27+
Write-Verbose "Checking GitHub CLI scopes for admin:org"
28+
if ($authStatus -match "admin:org") {
29+
$results += @{
30+
message = "GitHub CLI has admin:org scope."
31+
result = "Success"
32+
}
33+
} else {
34+
Write-ToConsoleLog "GitHub CLI is missing admin:org scope. Requesting scope refresh..." -IsWarning
35+
# Prompt user to add the admin:org scope
36+
gh auth refresh -h github.com -s admin:org
37+
if ($LASTEXITCODE -eq 0) {
38+
$results += @{
39+
message = "GitHub CLI admin:org scope added successfully."
40+
result = "Success"
41+
}
42+
} else {
43+
$results += @{
44+
message = "Failed to add admin:org scope. Please run 'gh auth refresh -h github.com -s admin:org' manually."
45+
result = "Failure"
46+
}
47+
$hasFailure = $true
48+
}
49+
}
2550
} else {
2651
$results += @{
2752
message = "GitHub CLI is not authenticated. Please authenticate using 'gh auth login'."

src/ALZ/Public/Remove-GitHubAccelerator.ps1

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@ function Remove-GitHubAccelerator {
3434
3535
.PARAMETER RunnerGroupNamePatterns
3636
An array of regex patterns to match against runner group names. Runner groups matching any of
37-
these patterns will be deleted. If empty, no runner groups will be deleted. Requires the
38-
-IncludeRunnerGroups switch to be specified.
37+
these patterns will be deleted. If empty, no runner groups will be deleted.
3938
Default: Empty array (no runner groups deleted)
4039
41-
.PARAMETER IncludeRunnerGroups
42-
A switch parameter that enables deletion of runner groups matching the patterns specified in
43-
-RunnerGroupNamePatterns. By default, runner groups are not deleted.
44-
Default: $false (do not delete runner groups)
45-
4640
.PARAMETER BypassConfirmation
4741
A switch parameter that bypasses the interactive confirmation prompts. When specified, the function
4842
waits for the duration specified in -BypassConfirmationTimeoutSeconds before proceeding, allowing
@@ -80,7 +74,7 @@ function Remove-GitHubAccelerator {
8074
Deletes all repositories and teams matching the pattern "^alz-.*" from the "my-org" organization.
8175
8276
.EXAMPLE
83-
Remove-GitHubAccelerator -GitHubOrganization "my-org" -RepositoryNamePatterns @("^alz-.*", "^landing-zone-.*") -IncludeRunnerGroups -RunnerGroupNamePatterns @("^alz-.*")
77+
Remove-GitHubAccelerator -GitHubOrganization "my-org" -RepositoryNamePatterns @("^alz-.*", "^landing-zone-.*") -RunnerGroupNamePatterns @("^alz-.*")
8478
8579
Deletes repositories matching either pattern and runner groups matching "^alz-.*" from the
8680
"my-org" organization.
@@ -117,9 +111,6 @@ function Remove-GitHubAccelerator {
117111
[Alias("runners")]
118112
[string[]]$RunnerGroupNamePatterns = @(),
119113

120-
[Parameter(Mandatory = $false, HelpMessage = "[OPTIONAL] Include runner groups in the deletion process.")]
121-
[switch]$IncludeRunnerGroups,
122-
123114
[Parameter(Mandatory = $false, HelpMessage = "[OPTIONAL] Bypass interactive confirmation prompts.")]
124115
[switch]$BypassConfirmation,
125116

@@ -171,7 +162,7 @@ function Remove-GitHubAccelerator {
171162

172163
$hasRepositoryPatterns = $RepositoryNamePatterns.Count -gt 0
173164
$hasTeamPatterns = $TeamNamePatterns.Count -gt 0
174-
$hasRunnerGroupPatterns = $IncludeRunnerGroups -and $RunnerGroupNamePatterns.Count -gt 0
165+
$hasRunnerGroupPatterns = $RunnerGroupNamePatterns.Count -gt 0
175166

176167
if(-not $hasRepositoryPatterns -and -not $hasTeamPatterns -and -not $hasRunnerGroupPatterns) {
177168
Write-ToConsoleLog "No patterns provided for repositories, teams, or runner groups. Nothing to do. Exiting..." -IsError

0 commit comments

Comments
 (0)