Skip to content

Commit b5058da

Browse files
committed
update usage message for run-branch
- and add self-contained watch_ci.clj
1 parent 57a4c5c commit b5058da

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

bb/bb/dl_and_run.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
(println (c/white "Access tokens require") (c/cyan "repo scope") (c/white "for private repositories and") (c/cyan "public_repo scope") (c/white "for public repositories."))
7777
(println "More info at: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token")
7878
(println "You can make one (classic) here: https://github.com/settings/tokens")
79+
(println (c/bold "Be sure to tick the *repo* permission."))
7980
(System/exit 1))))
8081

8182
(defn download-and-run-latest-jar! [{:keys [branch port socket-repl]}]

watch_ci.clj

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bb
2+
3+
(ns watch-ci
4+
(:require [babashka.curl :as curl]
5+
[babashka.tasks :refer [shell]]
6+
[bask.colors :as c]
7+
[bb.cli :as cli]
8+
[cheshire.core :as json]
9+
[clojure.edn :as edn]
10+
[clojure.pprint :as pp]
11+
[clojure.string :as str]
12+
[selmer.parser :refer [<<]]))
13+
14+
(defn env
15+
([] (into {} (System/getenv)))
16+
([env-var] (env env-var (fn [] (println "Warning: cannot find " (c/red env-var) " in env."))))
17+
([env-var error-thunk] (or ((env) (name env-var)) (error-thunk))))
18+
19+
(defn- gh-GET [url]
20+
(try (-> url
21+
(curl/get {:headers {"Accept" "application/vnd.github+json" "Authorization" (str "Bearer " (env "GH_TOKEN"))}})
22+
:body
23+
(json/decode true))
24+
(catch Exception e
25+
(let [{:keys [status]} (ex-data e)]
26+
(when (= status 401) (println (c/red "Is your GH_TOKEN out of date?")))
27+
(throw (ex-info (str "Error trying to get url " url " status: " status)
28+
{:status status :url url}))))))
29+
30+
(def mb-dir (env "MB_DIR" (fn []
31+
(println (c/red "Please set MB_DIR env variable to your metabase directory!"))
32+
(System/exit 1))))
33+
34+
(defn current-branch []
35+
(->> "git rev-parse --abbrev-ref HEAD"
36+
(shell {:dir mb-dir :out :string})
37+
:out
38+
str/trim))
39+
40+
(def branch (current-branch))
41+
42+
(defn checks-for-branch
43+
;; note: this is a ref, so it can e.g. also be a sha.
44+
[]
45+
(->> (str "https://api.github.com/repos/metabase/metabase/commits/" branch "/check-runs")
46+
gh-GET
47+
:check_runs
48+
(mapv (comp (fn [x] (if (nil? x) :in-progress (keyword x))) :conclusion))
49+
frequencies
50+
(sort-by first)
51+
reverse))
52+
53+
(def pretty {:success "" :skipped "⏭️ " :cancelled "⏹️" :in-progress "🔄" :failure ""})
54+
55+
(defn print-report-line [checks]
56+
(print (str "[" (.format (java.text.SimpleDateFormat. "hh:mm:ss a") (java.util.Date.)) "] "))
57+
(doseq [[status count] checks]
58+
(print (str/join (repeat count (pretty status)))) (print " "))
59+
(println)
60+
(flush))
61+
62+
(defn -main []
63+
;; (prn (env))
64+
(println "Legend:" (pr-str pretty))
65+
(loop [n 0]
66+
(let [checks (checks-for-branch)]
67+
(when (zero? (mod n 20))
68+
(println (c/green "Checking CI for branch:") (c/white branch) (c/green ".")))
69+
(print-report-line checks)
70+
(when-not (= (keys checks) [:success])
71+
(Thread/sleep 5000)
72+
(recur (inc n))))))
73+
74+
(when (= *file* (System/getProperty "babashka.file")) (-main))

0 commit comments

Comments
 (0)