I wrote a sample PowerShell code snippet to crawl across all opened Pull requests in multiple repositories inside an Azure DevOps project and list the ones out where myself or the team/group I am part of assigned as a reviewer.
End result is this:
End result is this:
This file contains 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
# fetch all the release pipelines metadata for the project | |
$ProjectName = 'BitPro.AzDeploy' | |
# Need the UserEmail as this is the unique name | |
$UserEmail = 'ddhami@foo.com' | |
# generate a list of User & Groups names to search for in the PR | |
$IDs = New-Object -TypeName System.Collections.ArrayList | |
$UserObject = az devops user show --user $UserEmail | ConvertFrom-Json | |
$IDs.Add($UserObject.Id) | |
# Fetch all the teams and generate a list of teams a user is member of | |
$Teams = az devops team list --project $ProjectName | ConvertFrom-Json | |
foreach ($team in $Teams) { | |
$TeamMembers = (az devops team list-member --team $team.Name --project $ProjectName | | |
ConvertFrom-Json).identity | |
if ($UserEmail -in $TeamMembers.uniqueName) | |
{ | |
#$TeamObject = az devops team show -- | |
$null = $IDs.Add($team.Id) | |
} | |
} | |
# Fetch the PRs in a Project | |
$PRs = az repos pr list --project $ProjectName | ConvertFrom-Json | |
# Iterate over each PR to find the reviewers and check if the user or groups is present | |
$PrsAssignedToUser = foreach ($pr in $PRs) { | |
$reviewersId = @($pr.reviewers.Id) | |
if ($IDs.Where( { $PSItem -in $reviewersId })) { | |
$pr | |
} | |
} | |
# Display the result | |
$PrsAssignedToUser | Select-Object -Property title,@{l='Repo';E={$PSItem.repository.name}},@{l='Reviewers';E={$PSItem.reviewers.displayname}} |