|
8 | 8 | (println "Usage: script/update_or_create_pr.clj branchname") |
9 | 9 | (System/exit 1)) |
10 | 10 |
|
11 | | -(def source-branch (first *command-line-args*)) |
12 | | -(def target-branch (str "update-" source-branch)) |
| 11 | +(def artifact-dirs ["_docs" "_site/docs"]) ;; Directories to copy |
13 | 12 |
|
14 | | -(when-not source-branch (usage)) |
| 13 | +(defn existing-pr? [target-branch] |
| 14 | + (let [pr-json |
| 15 | + (slurp |
| 16 | + (-> (str "https://api.github.com/repos/metabase/docs.metabase.github.io/pulls?head=metabase:" target-branch) |
| 17 | + (shell {:out :string :continue true})))] |
| 18 | + (some #(when (= target-branch (% "title")) (% "number")) |
| 19 | + (json/parse-string pr-json)))) |
15 | 20 |
|
16 | | -(def artifact-dirs ["_docs" "_site/docs"]) ;; Directories to copy |
| 21 | +(defn -main [& args] |
| 22 | + (let [source-branch (or (first args) (usage)) |
| 23 | + target-branch (str "update-" source-branch) |
| 24 | + _ (println "Swithcing to target branch.") |
| 25 | + _ (shell "git" "checkout" "-B" target-branch) |
| 26 | + _ (doseq [ad artifact-dirs] |
| 27 | + (println "Adding" ad "...") |
| 28 | + (shell "git" "add" ad)) |
| 29 | + {:keys [exit]} (shell {:continue true} "git" "diff" "--cached" "--quiet")] |
| 30 | + |
| 31 | + (if (zero? exit) |
| 32 | + (println "→ No changes to commit.") |
| 33 | + (do |
| 34 | + (println "→ Changes detected, committing...") |
| 35 | + (shell "git" "commit" "-m" (str "[auto] adding content to " target-branch)) |
| 36 | + (shell "git" "push" "--force" "origin" target-branch) |
| 37 | + (println "→ Branch updated successfully."))) |
| 38 | + |
| 39 | + (println "→ Checking for existing PR...") |
| 40 | + |
| 41 | + (if (existing-pr?) |
| 42 | + (println "✓ PR already exists: #" existing-pr?) |
| 43 | + (do |
| 44 | + (println "→ Creating new PR...") |
| 45 | + (shell "gh" "pr" "create" |
| 46 | + "--repo" "metabase/docs.metabase.github.io" |
| 47 | + "--title" target-branch |
| 48 | + "--body" (str "updated: " (pr-str artifact-dirs)) |
| 49 | + "--head" target-branch))))) |
| 50 | + |
| 51 | +(when (= *file* (System/getProperty "babashka.file")) |
| 52 | + (apply -main *command-line-args*)) |
| 53 | + |
| 54 | +(defmacro the-env [] |
| 55 | + (into {} (for [k (keys &env)] |
| 56 | + [(name k) k]))) |
17 | 57 |
|
18 | | -(doseq [ad artifact-dirs] |
19 | | - (println "Adding" ad "...") |
20 | | - (shell "git" "add" ad)) |
21 | | - |
22 | | -(let [{:keys [exit]} (shell |
23 | | - {:continue true} |
24 | | - "git" "diff" "--cached" "--quiet")] |
25 | | - (if (zero? exit) |
26 | | - (println "→ No changes to commit.") |
27 | | - (do |
28 | | - (println "→ Changes detected, committing...") |
29 | | - (shell "git" "commit" "-m" target-branch) |
30 | | - (shell "git" "push" "--force" "origin" target-branch) |
31 | | - (println "→ Branch updated successfully.")))) |
32 | | - |
33 | | -(println "→ Checking for existing PR...") |
34 | | - |
35 | | -(def pr-json |
36 | | - (slurp |
37 | | - (-> (str "https://api.github.com/repos/metabase/docs.metabase.github.io/pulls?head=metabase:" target-branch) |
38 | | - (shell {:out :string :continue true})))) |
39 | | - |
40 | | -(def existing-pr? |
41 | | - (some #(when (= target-branch (% "title")) (% "number")) |
42 | | - (json/parse-string pr-json))) |
43 | | - |
44 | | -(if existing-pr? |
45 | | - (println "✓ PR already exists: #" existing-pr) |
46 | | - (do |
47 | | - (println "→ Creating new PR...") |
48 | | - (shell "gh" "pr" "create" |
49 | | - "--repo" "metabase/docs.metabase.github.io" |
50 | | - "--title" target-branch |
51 | | - "--body" (str "updated: " (pr-str artifact-dirs)) |
52 | | - "--head" target-branch))) |
| 58 | +(defmacro nocommit-repl [] |
| 59 | + `(clojure.main/repl |
| 60 | + :init (fn [] |
| 61 | + (remove-ns '~'temp) |
| 62 | + (create-ns '~'temp) |
| 63 | + (doseq [[binding# value#] (the-env)] |
| 64 | + (intern '~'temp (symbol binding#) value#))) |
| 65 | + :prompt (fn [] (printf "paused.%s=> " (peek (clojure.string/split (str *ns*) #"\.")))) |
| 66 | + :eval (fn [f#] (binding [clojure.test/*test-out* *out*] (eval f#))) |
| 67 | + :read clojure.core.server/repl-read |
| 68 | + :print clojure.pprint/pprint)) |
0 commit comments