summary refs log tree commit diff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/jira-CR.php34
1 files changed, 21 insertions, 13 deletions
diff --git a/.local/bin/jira-CR.php b/.local/bin/jira-CR.php
index 88b91da..f9e673d 100755
--- a/.local/bin/jira-CR.php
+++ b/.local/bin/jira-CR.php
@@ -17,7 +17,7 @@ function get_jira(array $statuses): array {
     $padlen = 50;
     print(str_pad("\rGetting tickets from jira...", $padlen));
     $statuses = implode(' ', array_map(fn($x)=>"-s'$x'", $statuses));
-    $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' $statuses --columns=KEY,LABELS --plain | grep -v '^KEY\b'")));
+    $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' --reverse $statuses --columns=KEY,LABELS --plain | grep -v '^KEY\b'")));
     $tickets = array_map(fn($x) => explode("\t", $x)[0], $ticket_lines);
     $ticketLabels = array_combine(
         $tickets,
@@ -218,19 +218,27 @@ function process_pr($pr, $tickets, $ticketLabels, $onlyShowNeedsReview = false)
     return ['', ''];
 }
 
-foreach ($prs_json as $pr) {
-    [$terminal, $html] = process_pr($pr, $tickets, $ticketLabels);
-    if (!empty($terminal) && !empty($html)) {
-        echo $terminal;
-        file_put_contents("/tmp/jira-CR.html", $html, FILE_APPEND);
-    }
-}
+foreach ($tickets as $ticket) {
+    $hasPR = false;
+    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;
 
-$has_no_pr = array_diff($tickets, array_keys($has_pr));
-foreach ($has_no_pr as $ticket) {
-    $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);
+        if ($pr_ticket == $ticket) {
+            $hasPR = true;
+            [$terminal, $html] = process_pr($pr, $tickets, $ticketLabels);
+            if (!empty($terminal) && !empty($html)) {
+                echo $terminal;
+                file_put_contents("/tmp/jira-CR.html", $html, FILE_APPEND);
+            }
+        }
+    }
+    if ($hasPR === false) {
+        $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);
+    }
 }
 
 // Also show tickets which are past CR but no longer has two reviews