Created
October 20, 2021 14:56
-
-
Save nimatt/6fd5b690f9b5d42981abced74c00fd82 to your computer and use it in GitHub Desktop.
Get PBIs for merged PRs in dev that aren't in main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$token = '<access token>' | |
$auth = "Basic $([Convert]::ToBase64String([System.Text.ASCIIEncoding]::ASCII.GetBytes(":$token")))" | |
$headers = @{ "Authorization" = $auth } | |
$baseUrl = '<project url>' | |
$repoId = '<repo id>' | |
$prs = git log --pretty="%s" origin/main..origin/develop | Select-String 'Merged PR ' | % {$_.ToString().Split(' ')[2].TrimEnd(':')} | |
$prData = $prs | % { Invoke-RestMethod -Method Get "$baseUrl/_apis/git/repositories/$repoId/pullrequests/$($_)?api-version=6.0&includeWorkItemRefs=true" -Headers $headers } | |
$items = ($prData._links.workItems.href | % { Invoke-RestMethod -Method Get $_ -Headers $headers }).value.url | % { Invoke-RestMethod -Method Get "$($_)?`$expand=relations" -Headers $headers } | |
$tasks = $items | ? {$_.fields.'System.WorkItemType' -eq 'Task'} | |
$parents = ($tasks.relations | ? {$_.attributes.name -eq 'Parent'}).url | % { Invoke-RestMethod -Method Get $_ -Headers $headers } | |
$doneItems = ($items | ? {$_.fields.'System.WorkItemType' -ne 'Task'}) + $parents | ? {$_.fields.'System.State' -eq 'Done'} | |
$bugs = $doneItems | ? {$_.fields.'System.WorkItemType' -eq 'Bug'} | |
$pbis = $doneItems | ? {$_.fields.'System.WorkItemType' -eq 'Product Backlog Item'} | |
$bugs | % {"$($_.id) (Bug): $($_.fields.'System.Title')"} | Sort-Object -Unique | |
$pbis | % {"$($_.id) (PBI): $($_.fields.'System.Title')"} | Sort-Object -Unique |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment