summary refs log tree commit diff
path: root/.local/bin/jira-CR.php
blob: e87d265815e478b29f154e06ab73bc694587634d (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env php
<?php
$padlen = 50;
print(str_pad("\rGetting tickets from jira...", $padlen));
$tickets = explode("\n", rtrim(`jira-cli issues list -q"project IS NOT EMPTY and project != AUTO and project != NET and project != MSP and project != SYST and project != LOYAL" --order-by="Sprint" -s"Code Review" --columns=KEY --plain | grep -v '^KEY$'`));

print(str_pad("\rGetting OnBDC2 PR's from github...", $padlen));
$prs_jsons[] = json_decode(`gh pr list -R BetterCarPeople/OnBDC2 --json 'title,url,statusCheckRollup,reviews,author,reviewDecision,reviewRequests,headRefName'`, true);
print(str_pad("\rGetting maple-ai PR's from github...", $padlen));
$prs_jsons[] = json_decode(`gh pr list -R BetterCarPeople/maple-ai --json 'title,url,statusCheckRollup,reviews,author,reviewDecision,reviewRequests,headRefName'`, true);
print(str_pad("\rGetting maple-web PR's from github...", $padlen));
$prs_jsons[] = json_decode(`gh pr list -R BetterCarPeople/maple-web --json 'title,url,statusCheckRollup,reviews,author,reviewDecision,reviewRequests,headRefName'`, true);

print(str_pad("\r", $padlen));
print("\r");

$prs_json = array_merge(...$prs_jsons);
$output = "";
foreach ($prs_json as $pr) {
    $pr_ticket = null;
    $pr_ticket = in_array($pr['headRefName'], $tickets) ? $pr['headRefName'] : null;
    $pr_ticket ??= (preg_match("/^[^: ]*/", $pr['title'], $matches) && in_array($matches[0], $tickets)) ? $matches[0] : null;
    if ($pr_ticket) {
        // These are github PR's that are in code review in Jira
        $title = str_pad($pr['title'], 38);
        if (strlen($title) > 38) {
            $title = substr($title,0,35)."...";
        }
        $author = $pr['author']['login'];

        // Show approvers
        $review_status = "";

        $changeNames = [];
        foreach ($pr['reviews'] as $r) {
            if ($r['state'] === "CHANGES_REQUESTED") {
                $changeNames[] = $r['author']['login'];
            }
        }
        $changes = $changeNames ? (str_repeat("❌", count($changeNames)) . ": " . implode(", ", $changeNames) . '. ') : '';

        $requestNames = [];
        foreach ($pr['reviewRequests'] as $rr) {
            if ($rr['__typename'] === "Team") {
                $requestNames[] = $rr['name'];
            } else {
                $requestNames[] = $rr['login'];
            }
        }
        $reviewRequests = $requestNames ? (str_repeat("🟡", count($requestNames)) . ": " . implode(", ", $requestNames) . '. ') : '';

        $approvers = [];
        foreach ($pr['reviews'] as $r) {
            if ($r['state'] === "APPROVED") {
                $approvers[] = $r['author']['login'];
            }
        }
        $approvals = $approvers ? (str_repeat("✅", count($approvers)) . ": " . implode(", ", $approvers) . '. ') : '';

        $commentNames = [];
        foreach ($pr['reviews'] as $r) {
            $newName = $r['author']['login'];
            if ($r['state'] === "COMMENTED" && !in_array($newName, $approvers) && !in_array($newName, $requestNames) && $newName != $author) {
                $commentNames[] = $newName;
            }
        }
        $commentNames = array_unique($commentNames);
        $comments = $commentNames ? (str_repeat("💬", count($commentNames)) . ": " . implode(", ", $commentNames) . '. ') : '';

        $review_status = $changes . $reviewRequests . $approvals . $comments;
        // Show review requested for
        // show other review statuses
        
        echo "$pr[url]?T=$title($author)\t$review_status\n";
    }
}
exit(1);