diff options
| author | Zach DeCook <zach.decook@bettercarpeople.com> | 2026-06-25 15:10:32 -0400 |
|---|---|---|
| committer | Zach DeCook <zach.decook@bettercarpeople.com> | 2026-06-25 15:10:32 -0400 |
| commit | c1fd498db1b50c89064101ac7d863ed1a150bba4 (patch) | |
| tree | ba1d668def9704e80028cbefcc66e4035a30a159 /.local/bin | |
| parent | 26f833747da6dfb4ed58ce6a005bb425ba496433 (diff) | |
| download | dotfiles-c1fd498db1b50c89064101ac7d863ed1a150bba4.tar.gz | |
move process_pr into its own function
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/jira-CR.php | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/.local/bin/jira-CR.php b/.local/bin/jira-CR.php index bd2d910..bcbe873 100755 --- a/.local/bin/jira-CR.php +++ b/.local/bin/jira-CR.php @@ -13,13 +13,6 @@ if (!function_exists('array_any')) { } } -$ansired = "\033[31m"; -$ansigreen = "\033[32m"; -$ansiyellow = "\033[33m"; -$ansiblue = "\033[34m"; -$ansicyan = "\033[36m"; -$ansireset = "\033[0m"; - $padlen = 50; print(str_pad("\rGetting tickets from jira...", $padlen)); $ticket_lines = explode("\n", rtrim(shell_exec("jira-cli issues list -q'project IS NOT EMPTY and project != AUTO and project != NET and project != MSP and project != SYST and project != LOYAL and Sprint in openSprints()' --order-by='Sprint' -s'Code Review' --columns=KEY,LABELS --plain | grep -v '^KEY\b'"))); @@ -81,7 +74,16 @@ $prs_json = array_merge(...$prs_jsons); $output = ""; $has_pr = []; file_put_contents("/tmp/jira-CR.html", ""); -foreach ($prs_json as $pr) { + +function process_pr($pr, $tickets) { + global $has_pr; + $ansired = "\033[31m"; + $ansigreen = "\033[32m"; + $ansiyellow = "\033[33m"; + $ansiblue = "\033[34m"; + $ansicyan = "\033[36m"; + $ansireset = "\033[0m"; + $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; @@ -180,21 +182,34 @@ foreach ($prs_json as $pr) { $comments = $commentNames ? (str_repeat("💬", count($commentNames)) . ": " . implode(", ", $commentNames) . '. ') : ''; $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"; + $output = "$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); + return [$output, $html_output]; } + return ['', '']; } + +foreach ($prs_json as $pr) { + [$terminal, $html] = process_pr($pr, $tickets); + if (!empty($terminal) && !empty($html)) { + echo $terminal; + file_put_contents("/tmp/jira-CR.html", $html, FILE_APPEND); + } +} + $has_no_pr = array_diff($tickets, array_keys($has_pr)); foreach ($has_no_pr as $ticket) { - echo "https://proactivedealersolutions.atlassian.net/browse/$ticket Has no PR\n"; + $output = "https://proactivedealersolutions.atlassian.net/browse/$ticket Has no PR\n"; + echo($output); + file_put_contents("/tmp/jira-CR.html", "<li>" . $output . "</li>", FILE_APPEND); } exit(1); |
