Skip to content

Commit 36edb2f

Browse files
authored
Merge branch 'main' into feature-get-run
2 parents 2a2e70d + e707aaf commit 36edb2f

3 files changed

Lines changed: 441 additions & 0 deletions

File tree

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
function Get-AzDoClassificationNode {
2+
<#
3+
.SYNOPSIS
4+
Get a Classification Node in Azure DevOps.
5+
.DESCRIPTION
6+
Get a Classification Node in Azure DevOps. This could be an area or an iteration.
7+
.EXAMPLE
8+
$Params = @{
9+
CollectionUri = "https://dev.azure.com/cantoso"
10+
ProjectName = "Playground"
11+
StructureGroup = "areas"
12+
Name = "Area1"
13+
Depth = '2'
14+
}
15+
16+
Get-AzDoClassificationNode @Params
17+
18+
This example removes a Classification Node of the type 'areas' within the Project.
19+
.EXAMPLE
20+
$Params = @{
21+
CollectionUri = "https://dev.azure.com/cantoso"
22+
ProjectName = "Playground"
23+
StructureGroup = "areas"
24+
Name = "Area1"
25+
Path = "Path1"
26+
Depth = '2'
27+
}
28+
29+
Get-AzDoClassificationNode @Params
30+
31+
This example removes a Classification Node of the type 'areas' within the specified path.
32+
.EXAMPLE
33+
$Params = @{
34+
CollectionUri = "https://dev.azure.com/cantoso"
35+
ProjectName = "Playground"
36+
StructureGroup = "iterations"
37+
Name = "Iteration1"
38+
Depth = '2'
39+
}
40+
41+
Get-AzDoClassificationNode @Params
42+
43+
This example removes a Classification Node of the type 'iterations' within the specified path.
44+
45+
.EXAMPLE
46+
$Params = @{
47+
CollectionUri = "https://dev.azure.com/cantoso"
48+
ProjectName = "Playground"
49+
StructureGroup = "iterations"
50+
Name = "Iteration1"
51+
Path = "Path1"
52+
Depth = '2'
53+
}
54+
55+
Get-AzDoClassificationNode @Params
56+
57+
This example removes a Classification Node of the type 'iterations' within the specified path.
58+
#>
59+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
60+
param (
61+
# Collection Uri of the organization
62+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
63+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
64+
[string]
65+
$CollectionUri,
66+
67+
# Name of the project where the new repository has to be created
68+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
69+
[string]
70+
$ProjectName,
71+
72+
# Name of the project where the new repository has to be created
73+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
74+
[string]
75+
$StructureGroup,
76+
77+
# Path of the classification node (optional)
78+
[Parameter(ValueFromPipelineByPropertyName)]
79+
[string]
80+
$Path,
81+
82+
# Name of the classification node
83+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
84+
[string]
85+
$Name,
86+
87+
# Optional parameter to specify the depth of child nodes to retrieve
88+
[Parameter(ValueFromPipelineByPropertyName)]
89+
[string]
90+
$Depth = '2'
91+
)
92+
93+
begin {
94+
Write-Verbose "Starting function: Get-AzDoClassificationNode"
95+
$result = @()
96+
}
97+
98+
process {
99+
$ProjectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).Projectid
100+
101+
if ($Path) {
102+
$uri = "$CollectionUri/$ProjectName/_apis/wit/classificationnodes/$StructureGroup/$Path/$Name"
103+
} else {
104+
$uri = "$CollectionUri/$ProjectName/_apis/wit/classificationnodes/$StructureGroup/$Name"
105+
}
106+
107+
$params = @{
108+
uri = $uri
109+
version = "7.2-preview.2"
110+
QueryParameters = "`$depth=$depth"
111+
Method = 'GET'
112+
}
113+
114+
if ($PSCmdlet.ShouldProcess($ProjectName, "Get Classification Node named: $($PSStyle.Bold)$Name$($PSStyle.Reset)")) {
115+
$result += Invoke-AzDoRestMethod @params | ForEach-Object {
116+
[PSCustomObject]@{
117+
CollectionUri = $CollectionUri
118+
ProjectName = $ProjectName
119+
Id = $_.id
120+
Identifier = $_.identifier
121+
Name = $_.name
122+
StructureType = $_.structureType
123+
HasChildren = $_.hasChildren
124+
Children = $_.children
125+
Path = $_.path
126+
Links = $_._links
127+
Url = $_.url
128+
}
129+
}
130+
} else {
131+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
132+
}
133+
}
134+
135+
end {
136+
if ($result) {
137+
$result
138+
}
139+
}
140+
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
function New-AzDoClassificationNode {
2+
<#
3+
.SYNOPSIS
4+
Creates a Classification Node in Azure DevOps.
5+
.DESCRIPTION
6+
Creates a Classification Node in Azure DevOps. This could be an area or an iteration.
7+
.EXAMPLE
8+
$Params = @{
9+
CollectionUri = "https://dev.azure.com/cantoso"
10+
ProjectName = "Playground"
11+
StructureGroup = "areas"
12+
Name = "Area1"
13+
}
14+
15+
New-AzDoClassificationNode @Params
16+
17+
This example creates a Classification Node of the type 'areas' within the Project.
18+
.EXAMPLE
19+
$Params = @{
20+
CollectionUri = "https://dev.azure.com/cantoso"
21+
ProjectName = "Playground"
22+
StructureGroup = "areas"
23+
Name = "Area1"
24+
Path = "Path1"
25+
}
26+
27+
New-AzDoClassificationNode @Params
28+
29+
This example creates a Classification Node of the type 'areas' within the specified path.
30+
.EXAMPLE
31+
$Params = @{
32+
CollectionUri = "https://dev.azure.com/cantoso"
33+
ProjectName = "Playground"
34+
StructureGroup = "iterations"
35+
Name = "Iteration1"
36+
}
37+
38+
New-AzDoClassificationNode @Params
39+
40+
This example creates a Classification Node of the type 'iterations' within the Project.
41+
.EXAMPLE
42+
$Params = @{
43+
CollectionUri = "https://dev.azure.com/cantoso"
44+
ProjectName = "Playground"
45+
StructureGroup = "iterations"
46+
Name = "Iteration1"
47+
Path = "Path1"
48+
startDate = "10//701001 00:00:00
49+
finishDate = "10//701008 00:00:00
50+
}
51+
52+
New-AzDoClassificationNode @Params
53+
54+
This example creates a Classification Node of the type 'iterations' within the specified path, it is also possible to use a start and finish date of the iteration by adding the optional parameters 'startDate' and 'finishDate'.
55+
.OUTPUTS
56+
[PSCustomObject]@{
57+
CollectionUri = $CollectionUri
58+
ProjectName = $ProjectName
59+
Id = $_.id
60+
Identifier = $_.identifier
61+
Name = $_.name
62+
StructureType = $_.structureType
63+
HasChildren = $_.hasChildren
64+
Path = $_.path
65+
Links = $_._links
66+
Url = $_.url
67+
}
68+
.NOTES
69+
#>
70+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
71+
param (
72+
# Collection Uri of the organization
73+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
74+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
75+
[string]
76+
$CollectionUri,
77+
78+
# Name of the project where the new repository has to be created
79+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
80+
[string]
81+
$ProjectName,
82+
83+
# Name of the project where the new repository has to be created
84+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
85+
[string]
86+
$StructureGroup,
87+
88+
# Path of the classification node (optional)
89+
[Parameter(ValueFromPipelineByPropertyName)]
90+
[string]
91+
$Path,
92+
93+
# Name of the classification node
94+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
95+
[string]
96+
$Name,
97+
98+
# Start date of the iteration (optional)
99+
[Parameter(ValueFromPipelineByPropertyName)]
100+
[string]
101+
$startDate,
102+
103+
# Finish date of the iteration (optional)
104+
[Parameter(ValueFromPipelineByPropertyName)]
105+
[string]
106+
$finishDate
107+
)
108+
109+
begin {
110+
Write-Verbose "Starting function: New-AzDoClassificationNode"
111+
}
112+
113+
process {
114+
$ProjectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).Projectid
115+
116+
if ($Path) {
117+
$uri = "$CollectionUri/$ProjectName/_apis/wit/classificationnodes/$StructureGroup/$Path"
118+
} else {
119+
$uri = "$CollectionUri/$ProjectName/_apis/wit/classificationnodes/$StructureGroup"
120+
}
121+
122+
$params = @{
123+
uri = $uri
124+
version = "7.2-preview.2"
125+
Method = 'POST'
126+
}
127+
128+
if ($StructureGroup -eq 'areas') {
129+
$body = @{
130+
name = $Name
131+
}
132+
}
133+
if ($StructureGroup -eq 'iterations') {
134+
$body = @{
135+
name = $Name
136+
attributes = @{
137+
startDate = $startDate
138+
finishDate = $finishDate
139+
}
140+
}
141+
}
142+
143+
144+
if ($PSCmdlet.ShouldProcess($ProjectName, "Create Classification Node named: $($PSStyle.Bold)$Name$($PSStyle.Reset)")) {
145+
try {
146+
$body | Invoke-AzDoRestMethod @params | ForEach-Object {
147+
[PSCustomObject]@{
148+
CollectionUri = $CollectionUri
149+
ProjectName = $ProjectName
150+
Id = $_.id
151+
Identifier = $_.identifier
152+
Name = $_.name
153+
StructureType = $_.structureType
154+
HasChildren = $_.hasChildren
155+
Path = $_.path
156+
Links = $_._links
157+
Url = $_.url
158+
}
159+
}
160+
} catch {
161+
if ($_ -match 'is already in use by a different') {
162+
Write-Warning "Classification Node already exists within the path, trying to get it"
163+
$params.Method = 'GET'
164+
$params.uri = "$uri/$Name"
165+
Invoke-AzDoRestMethod @params | ForEach-Object {
166+
[PSCustomObject]@{
167+
CollectionUri = $CollectionUri
168+
ProjectName = $ProjectName
169+
Id = $_.id
170+
Identifier = $_.identifier
171+
Name = $_.name
172+
StructureType = $_.structureType
173+
HasChildren = $_.hasChildren
174+
Path = $_.path
175+
Links = $_._links
176+
Url = $_.url
177+
}
178+
}
179+
} else {
180+
Write-AzDoError -message $_
181+
}
182+
}
183+
}
184+
}
185+
}

0 commit comments

Comments
 (0)