diff options
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/jira-CR.php | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/.local/bin/jira-CR.php b/.local/bin/jira-CR.php index 6da5d7b..a1e26b0 100755 --- a/.local/bin/jira-CR.php +++ b/.local/bin/jira-CR.php @@ -42,12 +42,21 @@ function get_gh(string $repo): array { } } catch (\Throwable $e) { } - return json_decode(shell_exec("cat /tmp/prs_$repo.json"), true); + $file = fopen("/tmp/prs_$repo.json", 'r'); + if (! $file) { + print("\nThere is no backup file to use for {$repo}.\n"); + exit(1); + } + $date = (new DateTime('@'.fstat($file)['mtime'])) + ->setTimezone(new DateTimeZone(date_default_timezone_get())) + ->format('Y-m-d H:i:s T'); + print("\n{$repo}: Using backup file modified on " . $date . "\n"); + return json_decode(shell_exec("cat /tmp/prs_$repo.json"), true) ?? []; } $prs_jsons = []; $prs_jsons[] = get_gh("OnBDC2"); -$prs_jsons[] = get_gh("maple-ai"); +//$prs_jsons[] = get_gh("maple-ai"); $prs_jsons[] = get_gh("maple-web"); print(str_pad("\r", $padlen)); @@ -99,13 +108,6 @@ foreach ($prs_json as $pr) { // Show approvers $review_status = ""; - $changeNames = []; - foreach ($pr['reviews'] as $r) { - if ($r['state'] === "CHANGES_REQUESTED") { - $changeNames[] = $r['author']['login']; - } - } - $changeNames = array_unique($changeNames); $requestNames = []; foreach ($pr['reviewRequests'] as $rr) { @@ -117,6 +119,14 @@ foreach ($prs_json as $pr) { } $requestNames = array_unique($requestNames); + $changeNames = []; + foreach ($pr['reviews'] as $r) { + if ($r['state'] === "CHANGES_REQUESTED" && ! in_array($r['author']['login'], $requestNames)) { + $changeNames[] = $r['author']['login']; + } + } + $changeNames = array_unique($changeNames); + $approvers = []; foreach ($pr['reviews'] as $r) { if ($r['state'] === "APPROVED") { @@ -124,6 +134,21 @@ foreach ($prs_json as $pr) { } } + // If the same name has both CHANGES_REQUESTED and APPROVED, then go with the newer of the two. + foreach (array_intersect($changeNames, $approvers) as $name_in_both) { + $both_reviews = array_filter($pr['reviews'], fn($r) => $r['author']['login'] == $name_in_both && in_array($r['state'], ["CHANGES_REQUESTED", "APPROVED"])); + //usort($both_reviews, fn($a, $b) => $a['submittedAt'] <=> $b['submittedAt']); + $last = end($both_reviews); + //echo(json_encode($both_reviews)); + if ($last['state'] == 'CHANGES_REQUESTED') { + // Remove from approvers + $approvers = array_filter($approvers, fn($n) => $n != $name_in_both); + } elseif ($last['state'] == 'APPROVED') { + // Remove from changeNames + //$changeNames = array_filter($changeNames, fn($n) => $n != $name_in_both); + } + } + $commentNames = []; foreach ($pr['reviews'] as $r) { $newName = $r['author']['login']; |
