Skip to content

Commit 697a7c6

Browse files
committed
improve watch-ci task
1 parent 8931f93 commit 697a7c6

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

bb.edn

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,11 @@
8383
:choices-doc "list of branches"
8484
:prompt :select})
8585
branch (if (= "current" branch)
86-
(let [current (str/trim
87-
(:out (shell {:dir (t/env "MB_DIR" (fn []
88-
(println "Please set MB_DIR to your metabase repo!")
89-
(System/exit 1))) :out :string}
90-
"git rev-parse --abbrev-ref HEAD")))]
91-
(do (println (c/green (c/bold "Checking current branch: " current)))
86+
(let [current (t/current-branch)]
87+
(do (println (c/green (c/bold "Using current branch: " (t/current-branch))))
9288
current))
9389
branch)]
94-
(pp/pprint dl/pretty)
95-
(loop []
96-
(let [check (dl/checks-for-branch branch)]
97-
(print (str "\n[ " (.format (java.text.SimpleDateFormat. "hh:mm:ss a") (java.util.Date.)) " ]"))
98-
(doseq [[status count] check] (print (str/join (repeat count (dl/pretty status)))) (print "|")) (flush)
99-
(when-not (= (keys check) [:success])
100-
(Thread/sleep 10000) (recur))))))}
90+
(bb.watch-ci/branch branch)))}
10191

10292
install-autotab {:doc "Prints shell code to autocomplete tasks using bb.
10393
Note: for fish shell please make sure ~/.config/fish/completions exists."

bb/tasks.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
(print (c/white "="))
6262
(println (c/cyan value))))))
6363

64-
(defn mb-env []
64+
(defn mb-dir []
6565
(env "MB_DIR" (fn []
6666
(println (c/red "Please put the path of your metabase repository into the MB_DIR env variable like so:"))
6767
(println (c/white "export MB_DIR=path/to/metabase"))
@@ -99,3 +99,10 @@
9999
_ (bencode/write-bencode out {"op" "eval" "code" expr})
100100
bytes (get (bencode/read-bencode in) "value")]
101101
(String. bytes)))
102+
103+
(defn current-branch
104+
"Returns current metabase repo branch, as given by MB_DIR"
105+
[]
106+
(str/trim
107+
(:out (shell {:dir (mb-dir) :out :string}
108+
"git rev-parse --abbrev-ref HEAD"))))

bb/watch_ci.clj

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
(ns bb.watch-ci
2+
(:require [babashka.process :refer [shell]]
3+
[bask.colors :as c]
4+
[bb.cli :as cli]
5+
[bb.tasks :as t]
6+
[clojure.string :as str]
7+
[bb.dl-and-run :as dl]
8+
[clojure.pprint :as pp]
9+
[table.core :as table]))
10+
11+
(defn checks-for-branch [branch]
12+
(->> (str "https://api.github.com/repos/metabase/metabase/commits/" branch "/check-runs")
13+
dl/gh-get
14+
:check_runs
15+
(mapv #(select-keys % [:conclusion :name :html_url]))
16+
(mapv #(update % :conclusion (fnil keyword "in-progress")))
17+
(sort-by :conclusion)))
18+
19+
(defn tc [color & s]
20+
(let [cm {:bold 1
21+
:gray 30 :grey 30 :red 31 :green 32 :yellow 33
22+
:blue 34 :magenta 35 :cyan 36 :white 37
23+
:on-gray 40 :on-grey 40 :on-red 41 :on-green 42 :on-yellow 43
24+
:on-blue 44 :on-magenta 45 :on-cyan 46 :on-white 47}]
25+
(if-let [c (get cm color)]
26+
(str "[" c "m" (str/join s) "\033[0m")
27+
(str/join s))))
28+
29+
(defn colorize-line [line]
30+
(or (first (for [[re color] [[#"success" :green] [#"in-progress" :cyan] [#"failure" :red] [#"skipped" :yellow]]
31+
:when (re-find re line)]
32+
(tc color line)))
33+
line))
34+
35+
(defn branch [branch]
36+
(loop []
37+
(let [checks (checks-for-branch branch)]
38+
(println (tc :red (tc :bold branch)) (str "[ " (.format (java.text.SimpleDateFormat. "hh:mm:ss a") (java.util.Date.)) " ]"))
39+
(->> (table/table-str checks)
40+
str/split-lines
41+
(map colorize-line)
42+
(str/join "\n")
43+
println)
44+
(if (= #{:success} (set (map :conclusion checks)))
45+
(do
46+
(println (tc :green branch "passed."))
47+
(System/exit 0))
48+
(do (Thread/sleep 10000)
49+
(recur))))))

0 commit comments

Comments
 (0)