Skip to content

Commit cf85ead

Browse files
azure-sdkCopilotdanieljurek
authored
Sync eng/common directory with azure-sdk-tools for PR 14253 (#48271)
* Copy System.LinkTypes.Related links when cloning package work items for new Major.Minor versions Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> * Replace REST API URI with az boards work-item relation show in GetWorkItemRelatedLinkIds Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> * Fix --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> Co-authored-by: Daniel Jurek <djurek@microsoft.com>
1 parent be0ce2f commit cf85ead

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo,
430430
# Add a work item as related if given.
431431
if ($relatedId)
432432
{
433-
CreateWorkItemRelation $workItemId $relatedId "Related" $outputCommand
433+
foreach ($id in $relatedId) {
434+
CreateWorkItemRelation $workItemId $relatedId "Related" $outputCommand
435+
}
434436
}
435437
return $workItem
436438
}
@@ -445,6 +447,27 @@ function CreateWorkItemRelation($id, $relatedId, $relationType, $outputCommand =
445447
Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
446448
}
447449

450+
function GetWorkItemRelatedLinkIds($workItemId, $outputCommand = $false)
451+
{
452+
$parameters = $ReleaseDevOpsCommonParameters
453+
$parameters += "--id", $workItemId
454+
$response = Invoke-AzBoardsCmd "work-item relation show" $parameters $outputCommand
455+
456+
$relatedIds = @()
457+
if ($response.relations) {
458+
foreach ($relation in $response.relations) {
459+
if ($relation.rel -eq "Related") {
460+
$urlParts = $relation.url -split "/"
461+
$relatedId = $urlParts[-1]
462+
if ($relatedId -match "^\d+$") {
463+
$relatedIds += [int]$relatedId
464+
}
465+
}
466+
}
467+
}
468+
return $relatedIds
469+
}
470+
448471
function UpdateWorkItem($id, $fields, $title, $state, $assignedTo, $outputCommand = $true)
449472
{
450473
$parameters = $ReleaseDevOpsCommonParameters
@@ -481,6 +504,7 @@ function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPro
481504
$latestVersionItem = FindLatestPackageWorkItem -lang $lang -packageName $pkg.Package -outputCommand $outputCommand -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests -groupId $groupId
482505
$assignedTo = "me"
483506
$extraFields = @()
507+
$existingRelatedIds = @()
484508
if ($latestVersionItem) {
485509
Write-Verbose "Copying data from latest matching [$($latestVersionItem.id)] with version $($latestVersionItem.fields["Custom.PackageVersionMajorMinor"])"
486510
if ($latestVersionItem.fields["System.AssignedTo"]) {
@@ -499,6 +523,8 @@ function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPro
499523
if ($latestVersionItem.fields["Custom.RoadmapState"]) {
500524
$extraFields += "`"RoadmapState=" + $latestVersionItem.fields["Custom.RoadmapState"] + "`""
501525
}
526+
527+
$existingRelatedIds = GetWorkItemRelatedLinkIds $latestVersionItem.id $outputCommand
502528
}
503529

504530
if ($allowPrompt) {
@@ -515,6 +541,10 @@ function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPro
515541
}
516542
}
517543
$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -extraFields $extraFields -outputCommand $outputCommand -relatedId $relatedId -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
544+
545+
foreach ($existingRelatedId in $existingRelatedIds) {
546+
CreateWorkItemRelation $workItem.id $existingRelatedId "Related" $outputCommand
547+
}
518548
}
519549

520550
return $workItem

0 commit comments

Comments
 (0)