Skip to content

Commit 06059ca

Browse files
committed
fix ado removal
1 parent 47b7ecb commit 06059ca

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed

src/ALZ/Public/Remove-AzureDevOpsAccelerator.ps1

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Remove-AzureDevOpsAccelerator {
1717
CRITICAL WARNING: This is a highly destructive operation that will permanently delete Azure DevOps resources.
1818
Use with extreme caution and ensure you have appropriate backups and authorization before executing.
1919
20-
.PARAMETER AzureDevOpsOrganization
20+
.PARAMETER Organization
2121
The Azure DevOps organization URL or name. Can be provided as either the full URL
2222
(e.g., https://dev.azure.com/my-org) or just the organization name (e.g., my-org).
2323
This parameter is required.
@@ -29,16 +29,9 @@ function Remove-AzureDevOpsAccelerator {
2929
3030
.PARAMETER AgentPoolNamePatterns
3131
An array of regex patterns to match against agent pool names. Agent pools matching any of
32-
these patterns will be deleted. If empty, no agent pools will be deleted. Requires the
33-
-IncludeAgentPools switch to be specified.
32+
these patterns will be deleted. If empty, no agent pools will be deleted.
3433
Default: Empty array (no agent pools deleted)
3534
36-
.PARAMETER IncludeAgentPools
37-
A switch parameter that enables deletion of agent pools matching the patterns specified in
38-
-AgentPoolNamePatterns. By default, agent pools are not deleted. This is useful for cleaning
39-
up self-hosted agent pools created during the bootstrap process.
40-
Default: $false (do not delete agent pools)
41-
4235
.PARAMETER BypassConfirmation
4336
A switch parameter that bypasses the interactive confirmation prompts. When specified, the function
4437
waits for the duration specified in -BypassConfirmationTimeoutSeconds before proceeding, allowing
@@ -65,24 +58,24 @@ function Remove-AzureDevOpsAccelerator {
6558
Default: $false (execute actual deletions)
6659
6760
.EXAMPLE
68-
Remove-AzureDevOpsAccelerator -AzureDevOpsOrganization "my-org" -ProjectNamePatterns @("^alz-.*") -PlanMode
61+
Remove-AzureDevOpsAccelerator -Organization "my-org" -ProjectNamePatterns @("^alz-.*") -PlanMode
6962
7063
Shows what projects matching the pattern "^alz-.*" would be deleted from the "my-org"
7164
organization without making any changes.
7265
7366
.EXAMPLE
74-
Remove-AzureDevOpsAccelerator -AzureDevOpsOrganization "https://dev.azure.com/my-org" -ProjectNamePatterns @("^alz-.*")
67+
Remove-AzureDevOpsAccelerator -Organization "https://dev.azure.com/my-org" -ProjectNamePatterns @("^alz-.*")
7568
7669
Deletes all projects matching the pattern "^alz-.*" from the "my-org" organization.
7770
7871
.EXAMPLE
79-
Remove-AzureDevOpsAccelerator -AzureDevOpsOrganization "my-org" -ProjectNamePatterns @("^alz-.*") -IncludeAgentPools -AgentPoolNamePatterns @("^alz-.*")
72+
Remove-AzureDevOpsAccelerator -Organization "my-org" -ProjectNamePatterns @("^alz-.*") -AgentPoolNamePatterns @("^alz-.*")
8073
8174
Deletes projects and self-hosted agent pools matching the pattern "^alz-.*" from the
8275
"my-org" organization.
8376
8477
.EXAMPLE
85-
Remove-AzureDevOpsAccelerator -AzureDevOpsOrganization "my-org" -ProjectNamePatterns @("^test-alz$") -BypassConfirmation -BypassConfirmationTimeoutSeconds 10
78+
Remove-AzureDevOpsAccelerator -Organization "my-org" -ProjectNamePatterns @("^test-alz$") -BypassConfirmation -BypassConfirmationTimeoutSeconds 10
8679
8780
Deletes the project named exactly "test-alz" with a 10-second confirmation bypass timeout.
8881
@@ -99,8 +92,8 @@ function Remove-AzureDevOpsAccelerator {
9992
[CmdletBinding(SupportsShouldProcess = $true)]
10093
param (
10194
[Parameter(Mandatory = $true, HelpMessage = "[REQUIRED] The Azure DevOps organization URL or name.")]
102-
[Alias("org")]
103-
[string]$AzureDevOpsOrganization,
95+
[Alias("org", "AzureDevOpsOrganization")]
96+
[string]$Organization,
10497

10598
[Parameter(Mandatory = $false, HelpMessage = "[OPTIONAL] Regex patterns to match project names for deletion.")]
10699
[Alias("projects")]
@@ -110,9 +103,6 @@ function Remove-AzureDevOpsAccelerator {
110103
[Alias("pools")]
111104
[string[]]$AgentPoolNamePatterns = @(),
112105

113-
[Parameter(Mandatory = $false, HelpMessage = "[OPTIONAL] Include agent pools in the deletion process.")]
114-
[switch]$IncludeAgentPools,
115-
116106
[Parameter(Mandatory = $false, HelpMessage = "[OPTIONAL] Bypass interactive confirmation prompts.")]
117107
[switch]$BypassConfirmation,
118108

@@ -154,7 +144,7 @@ function Remove-AzureDevOpsAccelerator {
154144
$funcWriteToConsoleLog = ${function:Write-ToConsoleLog}.ToString()
155145

156146
# Normalize organization URL
157-
$organizationUrl = Get-NormalizedOrganizationUrl -Organization $AzureDevOpsOrganization
147+
$organizationUrl = Get-NormalizedOrganizationUrl -Organization $Organization
158148
Write-ToConsoleLog "Using Azure DevOps organization: $organizationUrl"
159149

160150
# Configure Azure DevOps CLI defaults
@@ -184,7 +174,7 @@ function Remove-AzureDevOpsAccelerator {
184174
Write-ToConsoleLog "Thanks for providing the inputs, getting started..." -IsSuccess
185175

186176
$hasProjectPatterns = $ProjectNamePatterns.Count -gt 0
187-
$hasAgentPoolPatterns = $IncludeAgentPools -and $AgentPoolNamePatterns.Count -gt 0
177+
$hasAgentPoolPatterns = $AgentPoolNamePatterns.Count -gt 0
188178

189179
if(-not $hasProjectPatterns -and -not $hasAgentPoolPatterns) {
190180
Write-ToConsoleLog "No patterns provided for projects or agent pools. Nothing to do. Exiting..." -IsError
@@ -237,9 +227,9 @@ function Remove-AzureDevOpsAccelerator {
237227
Write-ToConsoleLog "Found $($allAgentPools.Count) total agent pools in organization: $organizationUrl"
238228

239229
foreach($pool in $allAgentPools) {
240-
# Skip system pools (Azure Pipelines, Default, etc.)
241-
if($pool.isHosted -or $pool.poolType -eq "automation") {
242-
Write-ToConsoleLog "Skipping hosted/system pool: $($pool.name)"
230+
# Skip hosted pools (Microsoft-hosted Azure Pipelines)
231+
if($pool.isHosted) {
232+
Write-ToConsoleLog "Skipping hosted pool: $($pool.name)"
243233
continue
244234
}
245235

src/ALZ/Public/Remove-GitHubAccelerator.ps1

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Remove-GitHubAccelerator {
1818
CRITICAL WARNING: This is a highly destructive operation that will permanently delete GitHub resources.
1919
Use with extreme caution and ensure you have appropriate backups and authorization before executing.
2020
21-
.PARAMETER GitHubOrganization
21+
.PARAMETER Organization
2222
The GitHub organization name where the resources to be deleted are located.
2323
This parameter is required.
2424
@@ -63,24 +63,24 @@ function Remove-GitHubAccelerator {
6363
Default: $false (execute actual deletions)
6464
6565
.EXAMPLE
66-
Remove-GitHubAccelerator -GitHubOrganization "my-org" -RepositoryNamePatterns @("^alz-.*") -PlanMode
66+
Remove-GitHubAccelerator -Organization "my-org" -RepositoryNamePatterns @("^alz-.*") -PlanMode
6767
6868
Shows what repositories matching the pattern "^alz-.*" would be deleted from the "my-org"
6969
organization without making any changes.
7070
7171
.EXAMPLE
72-
Remove-GitHubAccelerator -GitHubOrganization "my-org" -RepositoryNamePatterns @("^alz-.*") -TeamNamePatterns @("^alz-.*")
72+
Remove-GitHubAccelerator -Organization "my-org" -RepositoryNamePatterns @("^alz-.*") -TeamNamePatterns @("^alz-.*")
7373
7474
Deletes all repositories and teams matching the pattern "^alz-.*" from the "my-org" organization.
7575
7676
.EXAMPLE
77-
Remove-GitHubAccelerator -GitHubOrganization "my-org" -RepositoryNamePatterns @("^alz-.*", "^landing-zone-.*") -RunnerGroupNamePatterns @("^alz-.*")
77+
Remove-GitHubAccelerator -Organization "my-org" -RepositoryNamePatterns @("^alz-.*", "^landing-zone-.*") -RunnerGroupNamePatterns @("^alz-.*")
7878
7979
Deletes repositories matching either pattern and runner groups matching "^alz-.*" from the
8080
"my-org" organization.
8181
8282
.EXAMPLE
83-
Remove-GitHubAccelerator -GitHubOrganization "my-org" -RepositoryNamePatterns @("^test-alz$") -BypassConfirmation -BypassConfirmationTimeoutSeconds 10
83+
Remove-GitHubAccelerator -Organization "my-org" -RepositoryNamePatterns @("^test-alz$") -BypassConfirmation -BypassConfirmationTimeoutSeconds 10
8484
8585
Deletes the repository named exactly "test-alz" with a 10-second confirmation bypass timeout.
8686
@@ -96,8 +96,8 @@ function Remove-GitHubAccelerator {
9696
[CmdletBinding(SupportsShouldProcess = $true)]
9797
param (
9898
[Parameter(Mandatory = $true, HelpMessage = "[REQUIRED] The GitHub organization name.")]
99-
[Alias("org")]
100-
[string]$GitHubOrganization,
99+
[Alias("org", "GitHubOrganization")]
100+
[string]$Organization,
101101

102102
[Parameter(Mandatory = $false, HelpMessage = "[OPTIONAL] Regex patterns to match repository names for deletion.")]
103103
[Alias("repos")]
@@ -176,15 +176,15 @@ function Remove-GitHubAccelerator {
176176

177177
# Discover repositories
178178
if($hasRepositoryPatterns) {
179-
Write-ToConsoleLog "Discovering repositories in organization: $GitHubOrganization"
179+
Write-ToConsoleLog "Discovering repositories in organization: $Organization"
180180

181-
$repositoriesResponse = (gh repo list $GitHubOrganization --json name,url --limit 1000 2>&1)
181+
$repositoriesResponse = (gh repo list $Organization --json name,url --limit 1000 2>&1)
182182
if($LASTEXITCODE -ne 0) {
183-
Write-ToConsoleLog "Failed to list repositories in organization: $GitHubOrganization" -IsError
183+
Write-ToConsoleLog "Failed to list repositories in organization: $Organization" -IsError
184184
return
185185
}
186186
$allRepositories = @($repositoriesResponse | ConvertFrom-Json)
187-
Write-ToConsoleLog "Found $($allRepositories.Count) total repositories in organization: $GitHubOrganization"
187+
Write-ToConsoleLog "Found $($allRepositories.Count) total repositories in organization: $Organization"
188188

189189
foreach($repo in $allRepositories) {
190190
foreach($pattern in $RepositoryNamePatterns) {
@@ -204,15 +204,15 @@ function Remove-GitHubAccelerator {
204204

205205
# Discover teams
206206
if($hasTeamPatterns) {
207-
Write-ToConsoleLog "Discovering teams in organization: $GitHubOrganization"
207+
Write-ToConsoleLog "Discovering teams in organization: $Organization"
208208

209-
$teamsResponse = (gh api "orgs/$GitHubOrganization/teams" --paginate 2>&1)
209+
$teamsResponse = (gh api "orgs/$Organization/teams" --paginate 2>&1)
210210
if($LASTEXITCODE -ne 0) {
211-
Write-ToConsoleLog "Failed to list teams in organization: $GitHubOrganization" -IsError
211+
Write-ToConsoleLog "Failed to list teams in organization: $Organization" -IsError
212212
return
213213
}
214214
$allTeams = @($teamsResponse | ConvertFrom-Json)
215-
Write-ToConsoleLog "Found $($allTeams.Count) total teams in organization: $GitHubOrganization"
215+
Write-ToConsoleLog "Found $($allTeams.Count) total teams in organization: $Organization"
216216

217217
foreach($team in $allTeams) {
218218
foreach($pattern in $TeamNamePatterns) {
@@ -233,18 +233,18 @@ function Remove-GitHubAccelerator {
233233

234234
# Discover runner groups
235235
if($hasRunnerGroupPatterns) {
236-
Write-ToConsoleLog "Discovering runner groups in organization: $GitHubOrganization"
236+
Write-ToConsoleLog "Discovering runner groups in organization: $Organization"
237237

238-
$runnerGroupsResponse = (gh api "orgs/$GitHubOrganization/actions/runner-groups" --paginate 2>&1)
238+
$runnerGroupsResponse = (gh api "orgs/$Organization/actions/runner-groups" --paginate 2>&1)
239239
if($LASTEXITCODE -ne 0) {
240-
Write-ToConsoleLog "Failed to list runner groups in organization: $GitHubOrganization (may require GitHub Enterprise)" -IsWarning
240+
Write-ToConsoleLog "Failed to list runner groups in organization: $Organization (may require GitHub Enterprise)" -IsWarning
241241
$allRunnerGroups = @()
242242
} else {
243243
$allRunnerGroups = ($runnerGroupsResponse | ConvertFrom-Json).runner_groups
244244
}
245245

246246
if($null -ne $allRunnerGroups) {
247-
Write-ToConsoleLog "Found $($allRunnerGroups.Count) total runner groups in organization: $GitHubOrganization"
247+
Write-ToConsoleLog "Found $($allRunnerGroups.Count) total runner groups in organization: $Organization"
248248

249249
foreach($runnerGroup in $allRunnerGroups) {
250250
# Skip the default runner group as it cannot be deleted
@@ -313,7 +313,7 @@ function Remove-GitHubAccelerator {
313313
$funcWriteToConsoleLog = $using:funcWriteToConsoleLog
314314
${function:Write-ToConsoleLog} = $funcWriteToConsoleLog
315315
$TempLogFileForPlan = $using:TempLogFileForPlan
316-
$org = $using:GitHubOrganization
316+
$org = $using:Organization
317317

318318
$repo = $_
319319
$repoFullName = "$org/$($repo.Name)"
@@ -343,7 +343,7 @@ function Remove-GitHubAccelerator {
343343
$funcWriteToConsoleLog = $using:funcWriteToConsoleLog
344344
${function:Write-ToConsoleLog} = $funcWriteToConsoleLog
345345
$TempLogFileForPlan = $using:TempLogFileForPlan
346-
$org = $using:GitHubOrganization
346+
$org = $using:Organization
347347

348348
$team = $_
349349

@@ -372,7 +372,7 @@ function Remove-GitHubAccelerator {
372372
$funcWriteToConsoleLog = $using:funcWriteToConsoleLog
373373
${function:Write-ToConsoleLog} = $funcWriteToConsoleLog
374374
$TempLogFileForPlan = $using:TempLogFileForPlan
375-
$org = $using:GitHubOrganization
375+
$org = $using:Organization
376376

377377
$runnerGroup = $_
378378

0 commit comments

Comments
 (0)