Skip to content

Commit a1a882d

Browse files
Sync eng/common directory with azure-sdk-tools for PR 6782 (Azure#38269)
* Create Epic work item type as Service or product when running prepare release script * Updated epic type field name * Additional change to create release plan work item * Exclude work items created from release planner test * Fix issue in params * Updated as per review comments --------- Co-authored-by: praveenkuttappan <prmarott@microsoft.com>
1 parent 5419b80 commit a1a882d

File tree

1 file changed

+101
-19
lines changed

1 file changed

+101
-19
lines changed

eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function BuildHashKey()
135135
}
136136

137137
$parentWorkItems = @{}
138-
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false)
138+
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true)
139139
{
140140
$key = BuildHashKey $serviceName $packageDisplayName
141141
if ($key -and $parentWorkItems.ContainsKey($key)) {
@@ -154,10 +154,12 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
154154
else {
155155
$serviceCondition = "[ServiceName] <> ''"
156156
}
157-
157+
if($ignoreReleasePlannerTests){
158+
$serviceCondition += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
159+
}
158160
$query = "SELECT [ID], [ServiceName], [PackageDisplayName], [Parent] FROM WorkItems WHERE [Work Item Type] = 'Epic' AND ${serviceCondition}"
159161

160-
$fields = @("System.Id", "Custom.ServiceName", "Custom.PackageDisplayName", "System.Parent")
162+
$fields = @("System.Id", "Custom.ServiceName", "Custom.PackageDisplayName", "System.Parent", "System.Tags")
161163

162164
$workItems = Invoke-Query $fields $query $outputCommand
163165

@@ -180,13 +182,63 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
180182
return $null
181183
}
182184

185+
$releasePlanWorkItems = @{}
186+
function FindReleasePlanWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true)
187+
{
188+
$key = BuildHashKey $serviceName $packageDisplayName
189+
if ($key -and $releasePlanWorkItems.ContainsKey($key)) {
190+
return $releasePlanWorkItems[$key]
191+
}
192+
193+
if ($serviceName) {
194+
$condition = "[ServiceName] = '${serviceName}'"
195+
if ($packageDisplayName) {
196+
$condition += " AND [PackageDisplayName] = '${packageDisplayName}'"
197+
}
198+
else {
199+
$condition += " AND [PackageDisplayName] = ''"
200+
}
201+
}
202+
else {
203+
$condition = "[ServiceName] <> ''"
204+
}
205+
$condition += " AND [System.State] <> 'Finished'"
206+
if($ignoreReleasePlannerTests){
207+
$condition += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
208+
}
209+
210+
$query = "SELECT [ID], [ServiceName], [PackageDisplayName], [Parent] FROM WorkItems WHERE [Work Item Type] = 'Release Plan' AND ${condition}"
211+
212+
$fields = @("System.Id", "Custom.ServiceName", "Custom.PackageDisplayName", "System.Parent", "System.Tags")
213+
214+
$workItems = Invoke-Query $fields $query $outputCommand
215+
216+
foreach ($wi in $workItems)
217+
{
218+
$localKey = BuildHashKey $wi.fields["Custom.ServiceName"] $wi.fields["Custom.PackageDisplayName"]
219+
if (!$localKey) { continue }
220+
if ($releasePlanWorkItems.ContainsKey($localKey) -and $releasePlanWorkItems[$localKey].id -ne $wi.id) {
221+
Write-Warning "Already found parent [$($releasePlanWorkItems[$localKey].id)] with key [$localKey], using that one instead of [$($wi.id)]."
222+
}
223+
else {
224+
Write-Verbose "[$($wi.id)]$localKey - Cached"
225+
$releasePlanWorkItems[$localKey] = $wi
226+
}
227+
}
228+
229+
if ($key -and $releasePlanWorkItems.ContainsKey($key)) {
230+
return $releasePlanWorkItems[$key]
231+
}
232+
return $null
233+
}
234+
183235
$packageWorkItems = @{}
184236
$packageWorkItemWithoutKeyFields = @{}
185237

186-
function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true)
238+
function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
187239
{
188240
# Cache all the versions of this package and language work items
189-
$null = FindPackageWorkItem $lang $packageName -includeClosed $true -outputCommand $outputCommand
241+
$null = FindPackageWorkItem $lang $packageName -includeClosed $true -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
190242

191243
$latestWI = $null
192244
foreach ($wi in $packageWorkItems.Values)
@@ -206,7 +258,7 @@ function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true)
206258
return $latestWI
207259
}
208260

209-
function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $true, $includeClosed = $false)
261+
function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $true, $includeClosed = $false, $ignoreReleasePlannerTests = $true)
210262
{
211263
$key = BuildHashKeyNoNull $lang $packageName $version
212264
if ($key -and $packageWorkItems.ContainsKey($key)) {
@@ -218,6 +270,7 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
218270
$fields += "System.State"
219271
$fields += "System.AssignedTo"
220272
$fields += "System.Parent"
273+
$fields += "System.Tags"
221274
$fields += "Custom.Language"
222275
$fields += "Custom.Package"
223276
$fields += "Custom.PackageDisplayName"
@@ -251,7 +304,9 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
251304
if ($version) {
252305
$query += " AND [PackageVersionMajorMinor] = '${version}'"
253306
}
254-
307+
if($ignoreReleasePlannerTests){
308+
$query += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
309+
}
255310
$workItems = Invoke-Query $fields $query $outputCommand
256311

257312
foreach ($wi in $workItems)
@@ -277,13 +332,13 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
277332
return $null
278333
}
279334

280-
function InitializeWorkItemCache($outputCommand = $true, $includeClosed = $false)
335+
function InitializeWorkItemCache($outputCommand = $true, $includeClosed = $false, $ignoreReleasePlannerTests = $true)
281336
{
282337
# Pass null to cache all service parents
283-
$null = FindParentWorkItem -serviceName $null -packageDisplayName $null -outputCommand $outputCommand
338+
$null = FindParentWorkItem -serviceName $null -packageDisplayName $null -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
284339

285340
# Pass null to cache all the package items
286-
$null = FindPackageWorkItem -lang $null -packageName $null -version $null -outputCommand $outputCommand -includeClosed $includeClosed
341+
$null = FindPackageWorkItem -lang $null -packageName $null -version $null -outputCommand $outputCommand -includeClosed $includeClosed -ignoreReleasePlannerTests $ignoreReleasePlannerTests
287342
}
288343

289344
function GetCachedPackageWorkItems()
@@ -490,30 +545,55 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
490545
}
491546
}
492547

493-
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
548+
$newparentItem = FindOrCreateReleasePlanParent $serviceName $pkgDisplayName -outputCommand $false
494549
UpdateWorkItemParent $existingItem $newParentItem -outputCommand $outputCommand
495550
return $existingItem
496551
}
497552

498-
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
553+
$parentItem = FindOrCreateReleasePlanParent $serviceName $pkgDisplayName -outputCommand $false
499554
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand
500555
Write-Host "[$($workItem.id)]$lang - $pkgName($verMajorMinor) - Created"
501556
return $workItem
502557
}
503558

504-
function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true)
559+
function FindOrCreateReleasePlanParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
560+
{
561+
$existingItem = FindReleasePlanWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
562+
if ($existingItem) {
563+
Write-Host "Found existing release plan work item [$($existingItem.id)]"
564+
$newparentItem = FindOrCreatePackageGroupParent $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
565+
UpdateWorkItemParent $existingItem $newParentItem
566+
return $existingItem
567+
}
568+
569+
$fields = @()
570+
$fields += "`"PackageDisplayName=${packageDisplayName}`""
571+
$fields += "`"ServiceName=${serviceName}`""
572+
$productParentItem = FindOrCreatePackageGroupParent $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
573+
$title = "Release Plan - $($packageDisplayName)"
574+
$workItem = CreateWorkItem $title "Release Plan" "Release" "Release" $fields $null $productParentItem.id
575+
576+
$localKey = BuildHashKey $serviceName $packageDisplayName
577+
Write-Host "[$($workItem.id)]$localKey - Created release plan work item"
578+
$releasePlanWorkItems[$localKey] = $workItem
579+
return $workItem
580+
}
581+
582+
function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
505583
{
506-
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand
584+
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
507585
if ($existingItem) {
508-
$newparentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand
586+
Write-Host "Found existing product work item [$($existingItem.id)]"
587+
$newparentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
509588
UpdateWorkItemParent $existingItem $newParentItem
510589
return $existingItem
511590
}
512591

513592
$fields = @()
514593
$fields += "`"PackageDisplayName=${packageDisplayName}`""
515594
$fields += "`"ServiceName=${serviceName}`""
516-
$serviceParentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand
595+
$fields += "`"Custom.EpicType=Product`""
596+
$serviceParentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
517597
$workItem = CreateWorkItem $packageDisplayName "Epic" "Release" "Release" $fields $null $serviceParentItem.id
518598

519599
$localKey = BuildHashKey $serviceName $packageDisplayName
@@ -522,21 +602,23 @@ function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outp
522602
return $workItem
523603
}
524604

525-
function FindOrCreateServiceParent($serviceName, $outputCommand = $true)
605+
function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
526606
{
527-
$serviceParent = FindParentWorkItem $serviceName -outputCommand $outputCommand
607+
$serviceParent = FindParentWorkItem $serviceName -packageDisplayName $null -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
528608
if ($serviceParent) {
609+
Write-Host "Found existing service work item [$($serviceParent.id)]"
529610
return $serviceParent
530611
}
531612

532613
$fields = @()
533614
$fields += "`"PackageDisplayName=`""
534615
$fields += "`"ServiceName=${serviceName}`""
616+
$fields += "`"Custom.EpicType=Service`""
535617
$parentId = $null
536618
$workItem = CreateWorkItem $serviceName "Epic" "Release" "Release" $fields $null $parentId -outputCommand $outputCommand
537619

538620
$localKey = BuildHashKey $serviceName
539-
Write-Host "[$($workItem.id)]$localKey - Created"
621+
Write-Host "[$($workItem.id)]$localKey - Created service work item"
540622
$parentWorkItems[$localKey] = $workItem
541623
return $workItem
542624
}

0 commit comments

Comments
 (0)