forked from artgarciams/copyWorkItemType
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectAndGroup.psm1
559 lines (488 loc) · 39.4 KB
/
ProjectAndGroup.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#
# FileName : ProjectAndGroup.psm1
# Data : 05/02/2022
# Purpose : this module will copy a work item type
# This script is for demonstration only not to be used as production code
#
# last update 05/02/2022
function GetVSTSCredential () {
Param(
$userEmail,
$Token
)
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userEmail, $token)))
return @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
}
function Copy-ProcessAndWorkItemType()
{
Param(
[Parameter(Mandatory = $false)]
$userParams,
[Parameter(Mandatory = $true)]
$InheritedProcessName,
[Parameter(Mandatory = $true)]
$DestinationProcess,
[Parameter(Mandatory = $true)]
$WorkItemCopyFrom,
[Parameter(Mandatory = $true)]
$WorkItemToCopy
)
$authorization = GetVSTSCredential -Token $userParams.PAT -userEmail $userParams.userEmail
# get all processes
# GET https://dev.azure.com/{organization}/_apis/work/processes?api-version=7.1-preview.2
$AllProcessesUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes?api-version=7.1-preview.2"
$AllProcesses = Invoke-RestMethod -Uri $AllProcessesUrl -Method Get -Headers $authorization
# find inherited process - process to copy
$inheritProc = $AllProcesses.value | Where-Object {$_.name -eq $InheritedProcessName}
# see if new process exists
$proc = $AllProcesses.value | Where-Object {$_.name -eq $DestinationProcess}
# if new process does not exist add it
if([string]::IsNullOrEmpty($proc) )
{
# create new process
# POST https://dev.azure.com/{organization}/_apis/work/processes?api-version=7.1-preview.2
$processJson = @{
description = "New process added with PowerShell"
name = $DestinationProcess
parentProcessTypeId = $inheritProc.parentProcessTypeId
}
$newProcess = ConvertTo-Json -InputObject $processJson
$newProcessesUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes?api-version=7.1-preview.2"
$proc = Invoke-RestMethod -Uri $newProcessesUrl -Method Post -ContentType "application/json" -Headers $authorization -Body $newProcess
}
#
# now confirm new process work item exists if not add ite
#
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/work-item-types/list?view=azure-devops-rest-7.1
# GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workitemtypes?api-version=7.1-preview.2
$findWkProcessUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes" + '?$expand=layout&api-version=7.1-preview.2'
$findWkProcess = Invoke-RestMethod -Uri $findWkProcessUrl -Method Get -Headers $authorization
$newWKItem = $findWkProcess.value | Where-Object {$_.name -eq $WorkItemToCopy}
# get work item types to inherit from
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/work-item-types/list?view=azure-devops-rest-7.1
# GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workitemtypes?api-version=7.1-preview.2
$AllWorkItemTypeUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $inheritProc.typeId + '/workitemtypes?$expand=layout&api-version=7.1-preview.2'
$AllWorkItemTypes = Invoke-RestMethod -Uri $AllWorkItemTypeUrl -Method Get -Headers $authorization
$WorkItemType = $AllWorkItemTypes.value | Where-Object {$_.name -eq $WorkItemCopyFrom}
# new process work item type does not exist add it
if([string]::IsNullOrEmpty($newWKItem) )
{
# create work item type within new precess
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/work-item-types/create?view=azure-devops-rest-7.1
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workitemtypes?api-version=7.1-preview.2
$workitemTypeJson = @{
color = "f6546a"
icon = "icon_airplane"
description = "my first powershell induced workitem type"
name = $WorkItemToCopy
isDisabled = $false
}
# add work item
$newWkJson = ConvertTo-Json -InputObject $workitemTypeJson
$newWkItemsUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + '/workitemtypes?$expand=layout&api-version=7.1-preview.2'
$newWKItem = Invoke-RestMethod -Uri $newWkItemsUrl -Method Post -ContentType "application/json" -Headers $authorization -Body $newWkJson
# not get list of all work items including the one we added
$AllWorkItemTypeUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + '/workitemtypes?$expand=layout&api-version=7.1-preview.2'
$newWKItemList = Invoke-RestMethod -Uri $AllWorkItemTypeUrl -Method Get -Headers $authorization
$newWKItem = $newWKItemList.value | Where-Object {$_.name -eq $WorkItemToCopy}
# get states of work item to copy. this will be used to add states to new work item
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/states/list?view=azure-devops-rest-7.1
# GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/states?api-version=7.1-preview.1
$getAllStatesUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $WorkItemType.referenceName + "/states?api-version=7.1-preview.1"
$getAllStates = Invoke-RestMethod -Uri $getAllStatesUrl -Method Get -Headers $authorization
Write-Host $getAllStates
# loop thru states of work item to copy and add to new work item
foreach ($state in $getAllStates.value)
{
switch ($state.name )
{
"New" { Write-Host "State " $state.name " Exists" }
"Active" { Write-Host "State " $state.name " Exists" }
"Closed" { Write-Host "State " $state.name " Exists" }
Default
{
$ddState = @{
name = $state.name
color = $state.color
stateCategory = $state.stateCategory
# order = $state.order
}
$newState = ConvertTo-Json -InputObject $ddState
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/states/create?view=azure-devops-rest-7.1
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/states?api-version=7.1-preview.1
$addStateUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/states?api-version=7.1-preview.1"
$addState = Invoke-RestMethod -Uri $addStateUrl -Method Post -ContentType "application/json" -Headers $authorization -Body $newState
Write-Host "Added State " $state.name " --- " $addState
}
}
}
# now make sure all the states from the work item type to copy from are the same as the copy to
# will remove any states not in the copy from
# get states of work item to copy. this will be used to add states to new work item
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/states/list?view=azure-devops-rest-7.1
# GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/states?api-version=7.1-preview.1
$getNewStatesUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/states?api-version=7.1-preview.1"
$NewStates = Invoke-RestMethod -Uri $getNewStatesUrl -Method Get -Headers $authorization
Write-Host $NewStates
foreach ($st in $NewStates.value)
{
$fndState = $getAllStates.value | Where-Object {$_.name -eq $st.name}
# if not found in copy from work item delete it. WHen a work item get created it is given a few default states.
if([string]::IsNullOrEmpty($fndState) )
{
# stat does not exist in copy from work item so it should be removed from copy to work item.
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/states/delete?view=azure-devops-rest-7.1
# DELETE https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/states/{stateId}?api-version=7.1-preview.1
$DelstateURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/states/" + $st.id + "?api-version=7.1-preview.1"
$DelStates = Invoke-RestMethod -Uri $DelstateURL -Method Delete -Headers $authorization
Write-Host "Deleted state " $st.name " from Work item to copy to" $DelStates
}
}
}
# get pages from new work item type. needed to add groups to page.
# each page has 4 sections that arte created on page creation.they are situated left to right on page. section 4 i believe is hidden( not sure yet)
$newPages = $newWKItem.layout.pages
# find all fields in work item type need to handle boolean and other fields
# this is a list of all the fileds in the org
# https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/fields/get?view=azure-devops-rest-7.1
# GET https://dev.azure.com/{organization}/{project}/_apis/wit/fields?api-version=7.1-preview.2
$AllFieldsUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + '/_apis/wit/fields?$expand=extensionFields&api-version=7.1-preview.2'
$AllFields = Invoke-RestMethod -Uri $AllFieldsUrl -Method Get -Headers $authorization
Write-Host $AllFields
$fldCOntrib = $AllFields.value | Where-Object {$_.isContribution -eq "True" }
# loop thru layout to copy and add pages to new layout if they dont exist
foreach ($Curritem in $WorkItemType.layout.pages)
{
$pgExists = $newPages | Where-Object {$_.label -eq $Curritem.label}
# if page does not exists. add
if([string]::IsNullOrEmpty($pgExists))
{
# add page to work item and add all groups , fields and controls
[pscustomobject]$addPage = @{
id = ""
label = $Curritem.label.Trim()
order = $null
visible = $true
pageType = $null
}
$secJson = ConvertTo-Json -InputObject $addPage
$pageURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + '/layout/pages?api-version=7.1-preview.1'
$page = Invoke-RestMethod -Uri $pageURL -Method Post -ContentType "application/json" -Headers $authorization -Body $secJson
Write-Host $page
}
}
# refresh pages in new work item. when new process is created it has default pages. after we add pages need to get work item type again to get all new pages
$AllWorkItemTypeUrl = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + '/workitemtypes?$expand=layout&api-version=7.1-preview.2'
$newWKItemList = Invoke-RestMethod -Uri $AllWorkItemTypeUrl -Method Get -Headers $authorization
$newWKItem = $newWKItemList.value | Where-Object {$_.name -eq $WorkItemToCopy}
# get pages from new work item type. needed to add groups to page.
# each page has 4 sections that arte created on page creation.they are situated left to right on page. section 4 i believe is hidden( not sure yet)
$newPages = $newWKItem.layout.pages
# loop thru inherited work item to copy to new work item
foreach ($Curritem in $WorkItemType.layout.pages)
{
$pgExists = $newPages | Where-Object {$_.label.Trim() -eq $Curritem.label.Trim()}
# if page exists. add groupd that are missing and add fileds to groups
if($pgExists -ne $null)
{
# if inherited page is visible, add group info if missing
if($Curritem.visible -eq $true)
{
# loop thru each section in inherited work item and then loop thru
# each section in new work item and add groups to new work item if they are not there
foreach ($currSection in $Curritem.sections)
{
# loop thru each new section and add groups as needed
foreach ($newSection in $pgExists.sections)
{
# find inhertited section and go thru groups
if( $currSection.id -eq $newSection.id)
{
# loop thru each group in inherited page and add any group that does not exist
foreach ($grp in $currSection.groups)
{
$added = "$false"
# special case if we rename system.description need to handle it this way
$newGrp = $null
$isMultiLine = $false
if($grp.controls[0].id -eq "System.Description")
{
# does new group exist if its one of the default fields we need to look for them first
$newGrp = $newSection.groups | Where-Object {$_.id -eq $grp.id}
}
else
{
# does new group exist if its one of the default fields we need to look for them first
$newGrp = $newSection.groups | Where-Object {$_.label.Trim() -eq $grp.label.Trim()}
# multi line text fields cannot be inside a group. they are their own group on the UI
if($grp.controls[0].controlType -eq "HtmlFieldControl")
{
$isMultiLine = $true
# first add the field to the work item
$addCtl = @{
referenceName = $grp.controls[0].id
order = "$null"
readOnly = "$false"
label = $grp.label.Trim()
visible = "$true"
# must encapsulate true false in quotes to register
defaultValue = if($fld.type -eq "boolean"){"$false"}else {""}
required = if($fld.type -eq "boolean"){"$true"}else {"$false"}
}
$ctlJSON = ConvertTo-Json -InputObject $addCtl
# add field to work item type
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/fields/add?view=azure-devops-rest-7.1
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/fields?api-version=7.1-preview.2
$field = $null
$fieldURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemTypes/" + $newWKItem.referenceName + "/fields?api-version=7.1-preview.2"
$field = Invoke-RestMethod -Uri $fieldURL -Method Post -ContentType "application/json" -Headers $authorization -Body $ctlJSON
Write-Host $field
# now add the Multi line field to the page in a group with no name
$addGroup = @{
Contribution = "$null"
height = "$null"
id = "$null"
inherited = "$null"
isContribution = "$false"
label = $grp.label.Trim()
visible = "$true"
order = "$null"
overridden = "$null"
controls = @( @{
contribution = "$null"
controlType = "$null"
height = "$null"
id = $grp.controls[0].id
inherited = "$null"
isContribution = "$false"
label = $grp.controls[0].label.Trim()
metadata = "$null"
order = "$null"
overridden = "$null"
visible = "$true"
watermark = "$null"
})
}
$grpJSON = ConvertTo-Json -InputObject $addGroup
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/pages/{pageId}/sections/{sectionId}/groups?api-version=7.1-preview.1
$groupURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/pages/" + $pgExists.id + "/sections/" + $newSection.id + "/groups?api-version=7.1-preview.1"
$group = Invoke-RestMethod -Uri $groupURL -Method Post -ContentType "application/json" -Headers $authorization -Body $grpJSON
Write-Host "Multi line field " $group
$newGrp = $group
}
}
# if group does not exist add it
if([string]::IsNullOrEmpty($newGrp) -and $isMultiLine -eq $false )
{
$addGroup = @{
id = "$null"
label = $grp.label.Trim()
visible = "$true"
isContribution = "$false"
}
$grpJSON = ConvertTo-Json -InputObject $addGroup
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/pages/{pageId}/sections/{sectionId}/groups?api-version=7.1-preview.1
$groupURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/pages/" + $pgExists.id + "/sections/" + $newSection.id + "/groups?api-version=7.1-preview.1"
$group = Invoke-RestMethod -Uri $groupURL -Method Post -ContentType "application/json" -Headers $authorization -Body $grpJSON
Write-Host $group
foreach ($grpCtl in $grp.controls)
{
$added = "$false"
$fld = $AllFields.value | Where-Object {$_.referenceName -eq $grpCtl.id }
if($fld.type -eq "html")
{
Write-Host $fld
}
# url contribution control - need to set added to true so code will not try to add field or control again
# url control has to be added as a control to the group, not like others that need field added first
# adding url contribution field is not documented. found request by using fiddler
if($grpCtl.contribution.contributionId -like "*url-field")
{
$addCtl = @{
contributionId = $grpCtl.contribution.contributionId
isContribution = if($grpCtl.isContribution -eq $true){"$true"}else {"$false"}
height = "$null"
label = $grpCtl.label.Trim()
metadata = "$null"
order = "$null"
overridden = "$null"
controlType = "$null"
readOnly = if($grpCtl.readOnly -eq $true){"$true"}else {"$false"}
visible = if($grpCtl.visible -eq $true){"$true"}else {"$false"}
watermark = "$null"
contribution = @{
contributionId = $grpCtl.contribution.contributionId
inputs = @{
HideUrlIfEmptyField = $grpCtl.contribution.inputs.HideUrlIfEmptyField
Title = $grpCtl.contribution.inputs.Title
Url = $grpCtl.contribution.inputs.Url
}
}
}
$ctlJSON = ConvertTo-Json -InputObject $addCtl
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/controls/create?view=azure-devops-rest-7.1
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/groups/{groupId}/controls?api-version=7.1-preview.1
$controlURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/groups/" + $group.id + "/controls?api-version=7.1-preview.1"
$control = Invoke-RestMethod -Uri $controlURL -Method Post -ContentType "application/json" -Headers $authorization -Body $ctlJSON
Write-Host $control
$added = "$true"
}
# add controls to group
if($grpCtl.isContribution -eq $true )
{
$addCtl = @{
referenceName = $grpCtl.contribution.inputs.FieldName
order = "$null"
readOnly = "$false"
inherited = $grpCtl.inherited
label = $grpCtl.label.Trim()
visible = "$true"
# must encapsulate true false in quotes to register
required = if($grpCtl.controlType -eq "boolean"){"$true"}else {"$false"}
contribution = @{
contributionId = $grpCtl.contribution.contributionId
inputs = @{
FieldName = $grpCtl.contribution.inputs.FieldName
Values = $grpCtl.contribution.inputs.Values
}
}
isContribution = "$true"
}
}
else
{
$addCtl = @{
referenceName = $grpCtl.id
order = "$null"
readOnly = "$false"
label = $grpCtl.label.Trim()
visible = "$true"
# must encapsulate true false in quotes to register
defaultValue = if($fld.type -eq "boolean"){"$false"}else {""}
required = if($fld.type -eq "boolean"){"$true"}else {"$false"}
}
}
$ctlJSON = ConvertTo-Json -InputObject $addCtl
if ($added -eq "$false")
{
# add field to work item type
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/fields/add?view=azure-devops-rest-7.1
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/fields?api-version=7.1-preview.2
$field = $null
$fieldURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemTypes/" + $newWKItem.referenceName + "/fields?api-version=7.1-preview.2"
$field = Invoke-RestMethod -Uri $fieldURL -Method Post -ContentType "application/json" -Headers $authorization -Body $ctlJSON
Write-Host $field
}
# add control to group. add the field to the control
if($grpCtl.isContribution -eq $true)
{
$addCtl = @{
# un documented when adding a contribution control it must have an ID. it has to be unique so i added a guid.
id = New-Guid
# un documented - if adding a contribution field must add reference name - this is the field in the control
referenceName = $grpCtl.contribution.inputs.FieldName
isContribution = if($grpCtl.isContribution -eq $true){"$true"}else {"$false"}
height = "$null"
label = $grpCtl.label.Trim()
metadata = "$null"
order = "$null"
overridden = "$null"
readOnly = if($grpCtl.readOnly -eq $true){"$true"}else {"$false"}
visible = if($grpCtl.visible -eq $true){"$true"}else {"$false"}
watermark = "$null"
contribution = @{
contributionId = $grpCtl.contribution.contributionId
inputs = @{
FieldName = $grpCtl.contribution.inputs.FieldName
Values = $grpCtl.contribution.inputs.Values
}
}
}
}
else
{
$addCtl = @{
id = $grpCtl.id
isContribution = if($grpCtl.isContribution -eq $true){"$true"}else {"$false"}
height = "$null"
label = $grpCtl.label.Trim()
metadata = "$null"
order = "$null"
overridden = "$null"
readOnly = if($grpCtl.readOnly -eq $true){"$true"}else {"$false"}
visible = if($grpCtl.visible -eq $true){"$true"}else {"$false"}
watermark = "$null"
}
}
IF($added -eq "$false")
{
$ctlJSON = ConvertTo-Json -InputObject $addCtl
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/controls/create?view=azure-devops-rest-7.1
# POST https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/groups/{groupId}/controls?api-version=7.1-preview.1
$controlURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/groups/" + $group.id + "/controls?api-version=7.1-preview.1"
$control = Invoke-RestMethod -Uri $controlURL -Method Post -ContentType "application/json" -Headers $authorization -Body $ctlJSON
Write-Host $control
}
}
}
else
{
# if this is the system description field, need to update label and visibility
if($grp.controls[0].id -eq "System.Description")
{
$editGrp = @{
id = $newGrp.Id
label = $grp.label.Trim()
visible = if($grp.controls[0].visible -eq "true"){"$true"}else{"$false"}
}
$editJSON = ConvertTo-Json -InputObject $editGrp
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/groups/update?view=azure-devops-rest-7.1
# PATCH https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/pages/{pageId}/sections/{sectionId}/groups/{groupId}?api-version=7.1-preview.1
$editURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/pages/" + $pgExists.id + "/sections/" + $newSection.id + "/groups/" + $grp.id + "?api-version=7.1-preview.1"
$editGroup = Invoke-RestMethod -Uri $editURL -Method PATCH -ContentType "application/json" -Headers $authorization -Body $editJSON
Write-Host $editGroup
}
else
{
# if not a multi line control then update the group
if($grp.controls[0].controlType -ne "HtmlFieldControl")
{
# group exists update the group deployment and development groups inherited and trying to hide
$editGrp = @{
id = $newGrp.Id
label = $grp.label.Trim()
visible = if($grp.controls[0].visible -eq "true"){"$true"}else{"$false"}
}
$editJSON = ConvertTo-Json -InputObject $editGrp
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/groups/update?view=azure-devops-rest-7.1
# PATCH https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/pages/{pageId}/sections/{sectionId}/groups/{groupId}?api-version=7.1-preview.1
$editGrp = $null
$editURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/pages/" + $pgExists.id + "/sections/" + $newSection.id + "/groups/" + $grp.id + "?api-version=7.1-preview.1"
$editGroup = Invoke-RestMethod -Uri $editURL -Method PATCH -ContentType "application/json" -Headers $authorization -Body $editJSON
Write-Host $editGroup
}
}
}
}
}
}
}
} # group visible
else
{
# page visible is false hide page in new layout
$editPg = @{
id = $pgExists.id
label = $pgExists.label.Trim()
visible = "$false"
}
$editJSON = ConvertTo-Json -InputObject $editPg
# https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/pages/update?view=azure-devops-rest-7.1
# PATCH https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/layout/pages?api-version=7.1-preview.1
$editURL = $userParams.HTTP_preFix + "://dev.azure.com/" + $userParams.VSTSMasterAcct + "/_apis/work/processes/" + $proc.typeId + "/workitemtypes/" + $newWKItem.referenceName + "/layout/pages?api-version=7.1-preview.1"
$editPage = Invoke-RestMethod -Uri $editURL -Method PATCH -ContentType "application/json" -Headers $authorization -Body $editJSON
Write-Host $editPage
}
} # page exists
}
}