Last active
October 15, 2019 03:58
-
-
Save DexterPOSH/0221d7073faea76c67006f95ce87e2e7 to your computer and use it in GitHub Desktop.
Code snippet to fetch PRs where a user is assigned as a reviewer
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}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment