File: PRReviewReminder.ps1

package info (click to toggle)
azure-devops-cli-extension 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,680 kB
  • sloc: python: 160,797; xml: 198; sh: 61; makefile: 56
file content (48 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
}