diff options
Diffstat (limited to '.local/bin/jira-CR.php')
| -rwxr-xr-x | .local/bin/jira-CR.php | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/.local/bin/jira-CR.php b/.local/bin/jira-CR.php index 586f65b..ca87d55 100755 --- a/.local/bin/jira-CR.php +++ b/.local/bin/jira-CR.php @@ -28,26 +28,28 @@ function get_jira(array $statuses): array { [$tickets, $ticketLabels] = get_jira(['Code Review']); -function get_gh(string $repo): array { +function get_gh(string $repo, bool $cache = false): array { $padlen = 50; $params = 'title,url,statusCheckRollup,reviews,author,reviewDecision,reviewRequests,headRefName,mergeable,additions,deletions'; print(str_pad("\rGetting $repo PR's from github...", $padlen)); - try { - $data = json_decode(shell_exec("gh pr list -L 75 -R BetterCarPeople/$repo --json '$params'"), true); - if (array_filter($data)) { - file_put_contents("/tmp/prs_$repo.json", json_encode($data)); - return $data; - } - } catch (\Throwable $e) { + if ($cache == false) { try { - sleep(1); - // Try again one more time (because github's API works better hot) $data = json_decode(shell_exec("gh pr list -L 75 -R BetterCarPeople/$repo --json '$params'"), true); if (array_filter($data)) { file_put_contents("/tmp/prs_$repo.json", json_encode($data)); return $data; } } catch (\Throwable $e) { + try { + sleep(1); + // Try again one more time (because github's API works better hot) + $data = json_decode(shell_exec("gh pr list -L 75 -R BetterCarPeople/$repo --json '$params'"), true); + if (array_filter($data)) { + file_put_contents("/tmp/prs_$repo.json", json_encode($data)); + return $data; + } + } catch (\Throwable $e) { + } } } $file = fopen("/tmp/prs_$repo.json", 'r'); @@ -62,10 +64,14 @@ function get_gh(string $repo): array { return json_decode(shell_exec("cat /tmp/prs_$repo.json"), true) ?? []; } +$use_cache = false; +if ($argv[1] == "--cached") { + $use_cache = true; +} $prs_jsons = []; -$prs_jsons[] = get_gh("OnBDC2"); +$prs_jsons[] = get_gh("OnBDC2", $use_cache); //$prs_jsons[] = get_gh("maple-ai"); -$prs_jsons[] = get_gh("maple-web"); +$prs_jsons[] = get_gh("maple", $use_cache); print(str_pad("\r", $padlen)); print("\r"); @@ -80,7 +86,7 @@ $output = ""; $has_pr = []; file_put_contents("/tmp/jira-CR.html", ""); -function process_pr($pr, $tickets, $ticketLabels) { +function process_pr($pr, $tickets, $ticketLabels, $onlyShowNeedsReview = false) { global $has_pr; $ansired = "\033[31m"; $ansigreen = "\033[32m"; @@ -153,6 +159,9 @@ function process_pr($pr, $tickets, $ticketLabels) { } } $approvers = array_unique($approvers); + if ($onlyShowNeedsReview && count($approvers) >= 2) { + return ['', '']; + } // 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) { @@ -187,7 +196,8 @@ function process_pr($pr, $tickets, $ticketLabels) { $comments = $commentNames ? (str_repeat("💬", count($commentNames)) . ": " . implode(", ", $commentNames) . '. ') : ''; $review_status = $changes . $reviewRequests . $approvals . $comments; - $output = "$pr[url]?T=$title($author)$labelsText$plusminus$mergeable$pipeline_status$review_status\n"; + $output = sprintf("\e]8;;$pr[url]?T=$pr_ticket\e\\$title\e]8;;\e\\"); + $output .= "($author)$labelsText$plusminus$mergeable$pipeline_status$review_status\n"; $html_output = "<li><a href='" . htmlspecialchars("$pr[url]?T=$pr_ticket") . "'>" . htmlspecialchars($title) . "</a>" . htmlspecialchars("($author)$labelsText$plusminus$mergeable$pipeline_status$review_status") . "</li>\n"; @@ -217,6 +227,37 @@ foreach ($has_no_pr as $ticket) { file_put_contents("/tmp/jira-CR.html", "<li>" . $output . "</li>", FILE_APPEND); } +// Also show tickets which are past CR but no longer has two reviews +$madeTitle = false; +[$tickets, $ticketLabels] = get_jira(['Pending Demo', 'Ready To Test', 'Testing']); +foreach ($prs_json as $pr) { + [$terminal, $html] = process_pr($pr, $tickets, $ticketLabels, true); + if (!empty($terminal) && !empty($html)) { + if (!$madeTitle) { + $output = "=== Tickets past review, but need it again ==="; + echo "\n" . $output . "\n"; + file_put_contents("/tmp/jira-CR.html", "<h3>" . $output . "</h3><br/>\n", FILE_APPEND); + $madeTitle = true; + } + echo $terminal; + file_put_contents("/tmp/jira-CR.html", $html, FILE_APPEND); + } +} +[$tickets, $ticketLabels] = get_jira(['Pending Sign Off', 'Signed Off']); +foreach ($prs_json as $pr) { + [$terminal, $html] = process_pr($pr, $tickets, $ticketLabels, true); + if (!empty($terminal) && !empty($html)) { + if (!$madeTitle) { + $output = "=== Tickets past review, but need it again ==="; + echo "\n" . $output . "\n"; + file_put_contents("/tmp/jira-CR.html", "<br/><br/><b>" . $output . "</b><br/>\n", FILE_APPEND); + $madeTitle = true; + } + echo $terminal; + file_put_contents("/tmp/jira-CR.html", $html, FILE_APPEND); + } +} + exit(1); |
