adding script in example which can be used for PR review reminder (#601)
This commit is contained in:
Родитель
98b51e0211
Коммит
6482e59ef1
|
@ -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
|
||||
```
|
|
@ -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
|
||||
}
|
Загрузка…
Ссылка в новой задаче