Skip to content

Commit 6e8c8e4

Browse files
authored
Merge pull request #45 from WeAreInSpark/dylan/fix-repo-output
Dylan/fix repo output
2 parents 5ae55a4 + fa8d678 commit 6e8c8e4

43 files changed

Lines changed: 1981 additions & 603 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/scripts/pester.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$config = New-PesterConfiguration
2+
$config.Run.Path = @('./tests/')
3+
$config.Run.ExcludePath = @('./tests/pester.ps1', './tests/Indented.ScriptAnalyzerRules/')
4+
$config.Run.Exit = $true
5+
$config.Output.CIFormat = 'GithubActions'
6+
$config.Output.Verbosity = 'Detailed'
7+
Invoke-Pester -Configuration $config

.github/workflows/Tests.yaml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
name: ⚗️ Tests
22
on: [pull_request]
33
jobs:
4-
test:
5-
name: Run Tests
6-
runs-on: ${{ matrix.os }}
7-
strategy:
8-
fail-fast: false
9-
matrix:
10-
os: [ubuntu-latest]
4+
scriptanalyzer:
5+
permissions:
6+
contents: read
7+
name: PSScriptAnalyzer Tests
8+
runs-on: ubuntu-latest
119
steps:
1210
- uses: actions/checkout@v3
1311
- name: Update ubuntu runner
1412
uses: ./.github/actions/update-ubuntu-runner
1513
id: update-ubuntu-runner
16-
- name: Test
14+
- name: Run PSScriptAnalyzer
15+
shell: pwsh
16+
run: |
17+
$invokeScriptAnalyzerSplat = @{
18+
Path = 'AzureDevOpsPowerShell'
19+
ReportSummary = $true
20+
Recurse = $true
21+
Settings = 'tests/ScriptAnalyzerSettings.psd1'
22+
EnableExit = $true
23+
}
24+
Invoke-ScriptAnalyzer @invokeScriptAnalyzerSplat
25+
pester:
26+
permissions:
27+
contents: read
28+
name: Pester Tests
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v3
32+
- name: Update ubuntu runner
33+
uses: ./.github/actions/update-ubuntu-runner
34+
id: update-ubuntu-runner
35+
- name: Build
36+
shell: pwsh
37+
run: |
38+
./build.ps1 -Task Build -Bootstrap
39+
- name: Run Pester
1740
shell: pwsh
1841
run: |
19-
./build.ps1 -task GenerateMarkdown -Bootstrap
42+
.github/scripts/pester.ps1
2043
validate-commits:
2144
runs-on: ubuntu-latest
2245
steps:

.github/workflows/powershell.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ name: PSScriptAnalyzer
22

33
on:
44
push:
5-
branches: [ "main"]
6-
pull_request:
7-
branches: [ "main" ]
5+
branches: ["main"]
86
schedule:
9-
- cron: '27 5 * * 3'
7+
- cron: "27 5 * * 3"
108

119
permissions:
1210
contents: read

AzureDevOpsPowerShell/Public/Api/ApprovalsAndChecks/CheckConfigurations/Add-AzDoPipelineBranchControl.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ function Add-AzDoPipelineBranchControl {
55
.DESCRIPTION
66
Creates a Build Validation policy on a branch
77
.EXAMPLE
8-
```powershell
98
$params = @{
109
CollectionUri = "https://dev.azure.com/contoso"
1110
PAT = "***"
@@ -14,7 +13,7 @@ function Add-AzDoPipelineBranchControl {
1413
ProjectName = "Project 1"
1514
Id = 1
1615
}
17-
```
16+
1817
Set-AzDoBranchPolicyBuildValidation @params
1918
2019
This example creates a policy with splatting parameters
@@ -89,7 +88,7 @@ function Add-AzDoPipelineBranchControl {
8988
}
9089

9190
Process {
92-
$projectId = (Get-AzDoproject -CollectionUri $CollectionUri -ProjectName $ProjectName).projectId
91+
$projectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).projectId
9392

9493
foreach ($name in $ResourceName) {
9594

AzureDevOpsPowerShell/Public/Api/Core/Projects/Get-AzDoProject.ps1

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,17 @@ function Get-AzDoProject {
7171
method = 'GET'
7272
}
7373

74-
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Environments from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
75-
$projects = (Invoke-AzDoRestMethod @params).value
74+
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Project(s)")) {
75+
Write-Debug "Calling Invoke-AzDoRestMethod with"
76+
Write-Debug ($params | Out-String)
77+
78+
$result = (Invoke-AzDoRestMethod @params).value | Where-Object { -not $ProjectName -or $_.Name -in $ProjectName }
7679

77-
if ($ProjectName) {
78-
foreach ($name in $ProjectName) {
79-
$project = $projects | Where-Object { $_.name -eq $name }
80-
if (-not($project)) {
81-
Write-Warning "Project $name not found"
82-
} else {
83-
$result += $project
84-
}
85-
}
86-
} else {
87-
$result += $projects
88-
}
8980

9081
} else {
91-
$body | Format-List
82+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
9283
}
9384
}
94-
9585
end {
9686
if ($result) {
9787
$result | ForEach-Object {
@@ -107,3 +97,4 @@ function Get-AzDoProject {
10797
}
10898
}
10999
}
100+

AzureDevOpsPowerShell/Public/Api/Core/Projects/New-AzDoProject.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,18 @@ function New-AzDoProject {
149149
}
150150

151151
if ($PSCmdlet.ShouldProcess($CollectionUri, "Create project named: $($PSStyle.Bold)$name$($PSStyle.Reset)")) {
152-
153-
$body | Invoke-AzDoRestMethod @params | Out-Null
152+
Write-Debug "Calling Invoke-AzDoRestMethod with"
153+
Write-Debug ($params | Out-String)
154+
155+
try {
156+
$body | Invoke-AzDoRestMethod @params | Out-Null
157+
} catch {
158+
if ($_ -match 'TF200019') {
159+
Write-Warning "Project $name already exists, trying to get it"
160+
} else {
161+
Write-AzDoError -message $_
162+
}
163+
}
154164

155165
do {
156166
Start-Sleep 5
@@ -165,6 +175,8 @@ function New-AzDoProject {
165175
$response.State -ne 'wellFormed'
166176
)
167177
$result += ($response)
178+
} else {
179+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
168180
}
169181
}
170182
}

AzureDevOpsPowerShell/Public/Api/Core/Projects/Remove-AzDoProject.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Remove-AzDoProject {
4646
)
4747

4848
begin {
49-
$result = New-Object -TypeName "System.Collections.ArrayList"
49+
$result = @()
5050
}
5151

5252
Process {
@@ -61,7 +61,12 @@ function Remove-AzDoProject {
6161
}
6262

6363
if ($PSCmdlet.ShouldProcess($CollectionUri, "Delete project named: $($PSStyle.Bold)$name$($PSStyle.Reset)")) {
64-
$result.add((Invoke-AzDoRestMethod @params)) | Out-Null
64+
Write-Debug "Calling Invoke-AzDoRestMethod with"
65+
Write-Debug ($params | Out-String)
66+
67+
$result += Invoke-AzDoRestMethod @params
68+
} else {
69+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
6570
}
6671
}
6772
}

AzureDevOpsPowerShell/Public/Api/DistributedTask/VariableGroups/Get-AzDoVariableGroup.ps1

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Get-AzDoVariableGroup {
4747
)
4848

4949
Begin {
50-
$result = New-Object -TypeName "System.Collections.ArrayList"
50+
$result = @()
5151
}
5252

5353
Process {
@@ -58,23 +58,20 @@ function Get-AzDoVariableGroup {
5858
}
5959

6060
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Variable groups from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
61-
$variableGroups = (Invoke-AzDoRestMethod @params).value
61+
Write-Debug "Calling Invoke-AzDoRestMethod with"
62+
Write-Debug ($params | Out-String)
6263

64+
$variableGroups = (Invoke-AzDoRestMethod @params).value
6365
if ($VariableGroupName) {
6466
foreach ($name in $VariableGroupName) {
65-
$variableGroup = $variableGroups | Where-Object { $_.name -eq $name }
66-
if (-not($variableGroup)) {
67-
Write-Error "Variable group $name not found"
68-
} else {
69-
$result.add($variableGroup ) | Out-Null
70-
}
67+
$result += $variableGroups | Where-Object { -not $name -or $_.Name -in $name }
7168
}
7269
} else {
73-
$result.add($variableGroups) | Out-Null
70+
$result += $variableGroups
7471
}
7572

7673
} else {
77-
$body | Out-String
74+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
7875
}
7976
}
8077

AzureDevOpsPowerShell/Public/Api/Git/Repositories/Get-AzDoRepo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function Get-AzDoRepo {
9696
URL = $_.url
9797
DefaultBranch = $_.defaultBranch
9898
WebUrl = $_.webUrl
99-
HttpsUrl = $_.remoteUrl
99+
RemoteUrl = $_.remoteUrl
100100
SshUrl = $_.sshUrl
101101
IsDisabled = $_.IsDisabled
102102
}

AzureDevOpsPowerShell/Public/Api/Git/Repositories/New-AzDoRepo.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ function New-AzDoRepo {
6969

7070
if ($PSCmdlet.ShouldProcess($CollectionUri, "Create repo named: $($PSStyle.Bold)$name$($PSStyle.Reset)")) {
7171
Write-Information "Creating Repo on Project $ProjectName"
72-
$result += ($body | Invoke-AzDoRestMethod @params)
72+
try {
73+
$ErrorActionPreference = 'Continue'
74+
$result += ($body | Invoke-AzDoRestMethod @params)
75+
} catch {
76+
if ($_ -match 'TF400948') {
77+
Write-Warning "Repo $name already exists, trying to get it"
78+
$params.Method = 'GET'
79+
$result += (Invoke-AzDoRestMethod @params).value | Where-Object { $_.name -eq $name }
80+
} else {
81+
Write-AzDoError -message $_
82+
}
83+
}
7384
} else {
7485
$Body | Format-List
7586
}
@@ -86,7 +97,7 @@ function New-AzDoRepo {
8697
RepoId = $_.id
8798
RepoURL = $_.url
8899
WebUrl = $_.webUrl
89-
HttpsUrl = $_.remoteUrl
100+
RemoteUrl = $_.remoteUrl
90101
SshUrl = $_.sshUrl
91102
}
92103
}

0 commit comments

Comments
 (0)