From 6482e59ef11ad5f94de387b907d5693f474ba5ed Mon Sep 17 00:00:00 2001 From: gauravsaralms <43203065+gauravsaralMs@users.noreply.github.com> Date: Tue, 21 May 2019 14:51:34 +0530 Subject: [PATCH] adding script in example which can be used for PR review reminder (#601) --- examples/PRReviewReminder.md | 15 +++++++++++ examples/PRReviewReminder.ps1 | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 examples/PRReviewReminder.md create mode 100644 examples/PRReviewReminder.ps1 diff --git a/examples/PRReviewReminder.md b/examples/PRReviewReminder.md new file mode 100644 index 00000000..a027db7b --- /dev/null +++ b/examples/PRReviewReminder.md @@ -0,0 +1,15 @@ +# PR Review Reminder + +## When to use + +PRs where user is added as a reviewer and have not commented in last n days can be detected using this script. + +## How to use + +### Script Mode + +1. Invoke the Script with required params- + +```cmd +.\PRReviewReminder.ps1 -organization https://dev.azure.com/fabrikam -username user@fabrikam.com -notReviewedInLastNDays 1 -project fabrikamProject +``` diff --git a/examples/PRReviewReminder.ps1 b/examples/PRReviewReminder.ps1 new file mode 100644 index 00000000..6c57bb2e --- /dev/null +++ b/examples/PRReviewReminder.ps1 @@ -0,0 +1,48 @@ +#--------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +param( + [String]$organization, + [String]$project, + [String]$username, + [int]$notReviewedInLastNDays +) + +$prlist = az repos pr list --reviewer $username --org $organization -p $project -o json | ConvertFrom-Json +$prReminderList = @() +$lastNDays = -1 * $notReviewedInLastNDays + +foreach ($pr in $prlist) { + $repositoryId = $pr.repository.id + $pullrequestId = $pr.pullRequestId + $nDaysBefore = (Get-Date).ToUniversalTime().AddDays($lastNDays) + $lastUpdatedDate = $nDaysBefore + $threads = az devops invoke --area git --resource pullRequestThreads --org $organization --route-parameters repositoryId=$repositoryId pullRequestId=$pullrequestId --http-method GET --api-version 5.1-preview -o json | ConvertFrom-Json + + foreach($thread in $threads.value) { + $comments = $thread.comments + + foreach($comment in $comments) { + $commentDate = ([datetime]$comment.lastUpdatedDate).ToUniversalTime() + if($comment.author.uniqueName -eq $username -and $commentDate -gt $lastUpdatedDate) { + $lastUpdatedDate = $commentDate + } + } + } + + if($lastUpdatedDate -eq $nDaysBefore) { + $prReminderList += ($pr) + } +} + +if($prReminderList.Length -eq 0) { + Write-Host "No pull requests pending to be reviewed at this moment.." +} elseif($prReminderList.Length -gt 0) { + Write-Host "Pull requests not reviewed/updated in last "$notReviewedInLastNDays" days:" +} + +foreach($pr in $prReminderList) { + Write-Host $pr.pullRequestId $pr.title +}