From cc22b4d4f89c8125dda8b207222b99741af81f73 Mon Sep 17 00:00:00 2001 From: Christopher Schraer <32145632+chschrae@users.noreply.github.com> Date: Tue, 13 Feb 2024 10:49:05 -0800 Subject: [PATCH] Updated Update script to correctly update features (#212) * 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 --- scripts/ADOUpdateFeature.ps1 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/ADOUpdateFeature.ps1 b/scripts/ADOUpdateFeature.ps1 index ebcfd281..7ab50e6c 100644 --- a/scripts/ADOUpdateFeature.ps1 +++ b/scripts/ADOUpdateFeature.ps1 @@ -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