Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 7075 (#27351)
Browse files Browse the repository at this point in the history
Sync eng/common directory with azure-sdk-tools for PR
Azure/azure-sdk-tools#7075 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

Co-authored-by: praveenkuttappan <prmarott@microsoft.com>
  • Loading branch information
azure-sdk and praveenkuttappan committed Oct 16, 2023
1 parent 27fb2d9 commit 9ef244c
Showing 1 changed file with 2 additions and 75 deletions.
77 changes: 2 additions & 75 deletions eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -182,56 +182,6 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
return $null
}

$releasePlanWorkItems = @{}
function FindReleasePlanWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true)
{
$key = BuildHashKey $serviceName $packageDisplayName
if ($key -and $releasePlanWorkItems.ContainsKey($key)) {
return $releasePlanWorkItems[$key]
}

if ($serviceName) {
$condition = "[ServiceName] = '${serviceName}'"
if ($packageDisplayName) {
$condition += " AND [PackageDisplayName] = '${packageDisplayName}'"
}
else {
$condition += " AND [PackageDisplayName] = ''"
}
}
else {
$condition = "[ServiceName] <> ''"
}
$condition += " AND [System.State] <> 'Finished'"
if($ignoreReleasePlannerTests){
$condition += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
}

$query = "SELECT [ID], [ServiceName], [PackageDisplayName], [Parent] FROM WorkItems WHERE [Work Item Type] = 'Release Plan' AND ${condition}"

$fields = @("System.Id", "Custom.ServiceName", "Custom.PackageDisplayName", "System.Parent", "System.Tags")

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

foreach ($wi in $workItems)
{
$localKey = BuildHashKey $wi.fields["Custom.ServiceName"] $wi.fields["Custom.PackageDisplayName"]
if (!$localKey) { continue }
if ($releasePlanWorkItems.ContainsKey($localKey) -and $releasePlanWorkItems[$localKey].id -ne $wi.id) {
Write-Warning "Already found parent [$($releasePlanWorkItems[$localKey].id)] with key [$localKey], using that one instead of [$($wi.id)]."
}
else {
Write-Verbose "[$($wi.id)]$localKey - Cached"
$releasePlanWorkItems[$localKey] = $wi
}
}

if ($key -and $releasePlanWorkItems.ContainsKey($key)) {
return $releasePlanWorkItems[$key]
}
return $null
}

$packageWorkItems = @{}
$packageWorkItemWithoutKeyFields = @{}

Expand Down Expand Up @@ -545,40 +495,17 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
}
}

$newparentItem = FindOrCreateReleasePlanParent $serviceName $pkgDisplayName -outputCommand $false
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
UpdateWorkItemParent $existingItem $newParentItem -outputCommand $outputCommand
return $existingItem
}

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

function FindOrCreateReleasePlanParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
{
$existingItem = FindReleasePlanWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
if ($existingItem) {
Write-Host "Found existing release plan work item [$($existingItem.id)]"
$newparentItem = FindOrCreatePackageGroupParent $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
UpdateWorkItemParent $existingItem $newParentItem
return $existingItem
}

$fields = @()
$fields += "`"PackageDisplayName=${packageDisplayName}`""
$fields += "`"ServiceName=${serviceName}`""
$productParentItem = FindOrCreatePackageGroupParent $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$title = "Release Plan - $($packageDisplayName)"
$workItem = CreateWorkItem $title "Release Plan" "Release" "Release" $fields $null $productParentItem.id

$localKey = BuildHashKey $serviceName $packageDisplayName
Write-Host "[$($workItem.id)]$localKey - Created release plan work item"
$releasePlanWorkItems[$localKey] = $workItem
return $workItem
}

function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
{
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
Expand Down

0 comments on commit 9ef244c

Please sign in to comment.