Skip to content

Commit

Permalink
Updated Update script to correctly update features (#212)
Browse files Browse the repository at this point in the history
* Fixed script paths

* Fixing ADO script names and issue number

* Fixed json building in create script

* removing prints from create

* updated workflow to not erase issue body

* handling empty description and newlines better

* handling null string value

* removing more writes

* Updated ADO feature update to work properly

---------

Co-authored-by: Chris Schraer <[email protected]>
  • Loading branch information
chschrae and Chris Schraer authored Feb 13, 2024
1 parent 91aed17 commit cc22b4d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions scripts/ADOUpdateFeature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ param(
)

# Map the GitHub issue state to an ADO work item state
$adoState = if ($githubIssue.state -eq "open") { "New" }
elseif ($githubIssue.state -eq "closed") { "Done" }
$adoState = if ($newState -eq "open") { "New" }
elseif ($newState -eq "closed") { "Done" }
else {
Write-Host "Unknown GitHub issue state: $($githubIssue.state)"
Write-Host "Unknown GitHub issue state: $($newState)"
exit 0
}

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("`:$pat"))
$headers = @{
"Authorization" = "Basic $B64Pat"
}

$body = @{
id = $adoWorkItemId
fields = @{
"System.State" = $adoState
}
} | ConvertTo-Json
$body = @(
[ordered] @{ op = 'add'; path = '/fields/System.State'; value = "$adoState" }
)
# Convert the body to JSON
$bodyJson = ConvertTo-Json -InputObject $body

Invoke-RestMethod -Uri "https://dev.azure.com/$organization/$project/_apis/wit/workitems/$workItemId?api-version=6.0" -Method Patch -Body $body -ContentType "application/json-patch+json" -Headers $adoHeaders
Invoke-RestMethod -Uri "https://dev.azure.com/$organization/$project/_apis/wit/workitems/$($workItemId)?api-version=7.1" -Method Patch -Body $bodyJson -ContentType "application/json-patch+json" -Headers $headers

0 comments on commit cc22b4d

Please sign in to comment.