diff options
| author | Zach DeCook <zach.decook@bettercarpeople.com> | 2026-06-25 09:20:41 -0400 |
|---|---|---|
| committer | Zach DeCook <zach.decook@bettercarpeople.com> | 2026-06-25 09:20:41 -0400 |
| commit | 26f833747da6dfb4ed58ce6a005bb425ba496433 (patch) | |
| tree | c76b8726806cb71256c1a662a21ced9a5d5d9ee7 /.local | |
| parent | cc7724139f1687aa6ec6cb6680612ea008964851 (diff) | |
| download | dotfiles-26f833747da6dfb4ed58ce6a005bb425ba496433.tar.gz | |
jira-CR.php: Make an HTML file for easier pasting into slack
Diffstat (limited to '.local')
| -rwxr-xr-x | .local/bin/jira-CR.php | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/.local/bin/jira-CR.php b/.local/bin/jira-CR.php index a1e26b0..bd2d910 100755 --- a/.local/bin/jira-CR.php +++ b/.local/bin/jira-CR.php @@ -35,12 +35,22 @@ function get_gh(string $repo): array { $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 50 -R BetterCarPeople/$repo --json '$params'"), true); + $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'); if (! $file) { @@ -70,6 +80,7 @@ if (empty(array_filter($prs_jsons))) { $prs_json = array_merge(...$prs_jsons); $output = ""; $has_pr = []; +file_put_contents("/tmp/jira-CR.html", ""); foreach ($prs_json as $pr) { $pr_ticket = null; $pr_ticket = in_array($pr['headRefName'], $tickets) ? $pr['headRefName'] : null; @@ -100,6 +111,7 @@ foreach ($prs_json as $pr) { $failedPipes[] = $scr['name']; } } + $failedPipes = array_unique($failedPipes); $failed = $failedPipes ? (str_repeat("๐งช๐", count($failedPipes)) . ": " . implode(", ", $failedPipes) . '. ') : ''; $failed = $failed ? ($ansicyan . $failed . $ansireset) : ""; @@ -133,6 +145,7 @@ foreach ($prs_json as $pr) { $approvers[] = $r['author']['login']; } } + $approvers = array_unique($approvers); // 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) { @@ -145,7 +158,7 @@ foreach ($prs_json as $pr) { $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); + $changeNames = array_filter($changeNames, fn($n) => $n != $name_in_both); } } @@ -169,6 +182,14 @@ foreach ($prs_json as $pr) { $review_status = $changes . $reviewRequests . $approvals . $comments; echo "$pr[url]?T=$title($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"; + $html_output = str_replace($ansired, "", $html_output); + $html_output = str_replace($ansigreen, "", $html_output); + $html_output = str_replace($ansiyellow, "", $html_output); + $html_output = str_replace($ansiblue, "", $html_output); + $html_output = str_replace($ansicyan, "", $html_output); + $html_output = str_replace($ansireset, "", $html_output); + file_put_contents("/tmp/jira-CR.html", $html_output, FILE_APPEND); } } $has_no_pr = array_diff($tickets, array_keys($has_pr)); |
