Skip to content

Commit e4740a7

Browse files
authored
better grouping (#370)
1 parent 05690e0 commit e4740a7

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

script/_test/find_broken_workflows.clj

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,57 @@
2626
(into []
2727
(filter
2828
(fn [{:keys [name]}]
29-
(and (str/includes? name from)
30-
(str/includes? name to))))
29+
(let [[from-name to-name] (str/split name #"->")]
30+
(and (str/includes? from-name from)
31+
(str/includes? to-name to)))))
3132
all-runs)))
3233

3334
(defn- ->epoch [time-str]
3435
(/ (.toEpochMilli (java.time.Instant/parse time-str)) 1000))
3536

37+
(defn- print-runs-report [head-ref-name runs-for-ref url]
38+
(if (some (comp #{"failure"} :conclusion) runs-for-ref)
39+
(do (println)
40+
(ice/p [:red "====== runs for: " head-ref-name " ======"])
41+
(pp/print-table
42+
(->>
43+
runs-for-ref
44+
(map #(dissoc % :workflowName :displayTitle :number :status))
45+
(sort-by (comp - ->epoch :createdAt)))))
46+
(ice/p [:green [:bold "OK "] url " | " head-ref-name])))
47+
48+
(defn- gather-runs-for-open-prs [open-prs runs]
49+
(for [{head-ref-name :headRefName
50+
url :url} open-prs
51+
:let [local-runs (runs-for-head-ref-name head-ref-name runs)]]
52+
[head-ref-name local-runs]))
53+
3654
(defn -main []
3755
(let [_ (println "Finding open PRs with process_docs_changes.yml workflow ...")
3856
runs (all-runs)
3957
_ (println "Found" (count runs) "runs for process_docs_changes.yml workflow")
4058
_ (println "Finding open PRs with process_docs_changes.yml workflow ...")
41-
open-prs (set (open-prs))]
42-
(println "Found" (count open-prs) "open PRs with process_docs_changes.yml workflow")
43-
(doseq [{head-ref-name :headRefName
44-
url :url} open-prs
45-
:let [runz (runs-for-head-ref-name head-ref-name runs)]]
46-
(if (some (comp #{"failure"} :conclusion) runz)
47-
(do (println) (println) (println)
48-
(ice/p [:red "====== runs for: " head-ref-name " ======"])
49-
(pp/print-table
50-
(->>
51-
runz
52-
(map #(dissoc % :workflowName :displayTitle :number :status))
53-
(sort-by (comp - ->epoch :createdAt)))))
54-
(ice/p [:green [:bold "OK "] url " | " head-ref-name])))))
59+
open-prs (set (open-prs))
60+
_ (println "Found" (count open-prs) "open PRs with process_docs_changes.yml workflow")
61+
local-runs (gather-runs-for-open-prs open-prs runs)
62+
sorted-runs (sort-by
63+
(fn [[_k vs]]
64+
(count (filter #{"failure"} (map :conclusion vs))))
65+
local-runs)]
66+
(doseq [[head-ref-name runs-for-ref] sorted-runs]
67+
(print-runs-report head-ref-name runs-for-ref (:url (first runs-for-ref))))))
5568

5669
(when (= *file* (System/getProperty "babashka.file"))
5770
(-main))
71+
72+
(comment
73+
74+
(def runz (all-runs))
75+
76+
(count runz)
77+
78+
(def open-prz (open-prs))
79+
80+
(update-vals (into {} (gather-runs-for-open-prs open-prz runz)) #(take 2 %))
81+
82+
)

script/merge.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
:require true}
1717
:source-branch {:ref "<source-branch>"
1818
:desc "The source branch of the triggering PR."
19-
:alias :r}
19+
:alias :r
20+
:require true}
2021
:dry-run {:desc "If set, will not execute the command, just print it out."
2122
:coerce :boolean
2223
:default false}}
@@ -97,6 +98,7 @@
9798
(let [{:keys [source-branch target-branch]
9899
dry-run? :dry-run
99100
:as opts} (cli/parse-opts args cli-spec)
101+
[source-branch target-branch] (mapv str/trim [source-branch target-branch])
100102
pr-number (source+target-branch->pr-number source-branch target-branch)]
101103
(when-not pr-number
102104
(throw (ex-info (ice/p-str [:red "No PR found for source branch "] [:bold source-branch] " and target branch " [:bold target-branch] ".")

0 commit comments

Comments
 (0)