|
1 | 1 | #!/usr/bin/env bb |
2 | 2 | (ns update-or-create-pr |
3 | | - (:require [babashka.process :as p :refer [sh shell]] |
4 | | - [babashka.fs :as fs] |
| 3 | + (:require [babashka.process :as p] |
5 | 4 | [cheshire.core :as json] |
6 | 5 | [clojure.string :as str])) |
7 | 6 |
|
|
15 | 14 |
|
16 | 15 | (defn existing-pr? [target-branch] |
17 | 16 | (let [pr-data (-> |
18 | | - (shell {:out :string :continue true} |
19 | | - "curl" |
20 | | - (str "https://api.github.com/repos/metabase/docs.metabase.github.io/pulls?head=metabase:" "update-" "doc-update-detection")) |
| 17 | + (p/shell {:out :string :continue true} |
| 18 | + "curl" |
| 19 | + (str "https://api.github.com/repos/metabase/docs.metabase.github.io/pulls?head=metabase:" "update-" "doc-update-detection")) |
21 | 20 | :out |
22 | 21 | json/parse-string) |
23 | 22 | pr-num (some #(when (= target-branch (get % "title")) |
24 | 23 | (get % "number")) |
25 | 24 | pr-data)] |
26 | | - (println "→ PR number:" o) |
| 25 | + (println "→ PR number:" pr-num) |
27 | 26 | (boolean pr-num))) |
28 | 27 |
|
29 | 28 | (defn -main [& args] |
30 | 29 | (let [source-branch (or (first args) (usage)) |
31 | 30 | target-branch (str "update-" source-branch) |
32 | 31 | _ (println "Swithcing to target branch.") |
33 | | - _ (shell "git" "checkout" "-B" target-branch) |
| 32 | + _ (p/shell "git" "checkout" "-B" target-branch) |
34 | 33 | _ (doseq [ad artifact-dirs] |
35 | 34 | (println "Adding" ad "...") |
36 | | - (shell "git" "add" ad)) |
37 | | - {:keys [exit]} (shell {:continue true} "git" "diff" "--cached" "--quiet")] |
| 35 | + (p/shell "git" "add" ad)) |
| 36 | + {:keys [exit]} (p/shell {:continue true} "git" "diff" "--cached" "--quiet")] |
38 | 37 |
|
39 | 38 | (if (zero? exit) |
40 | 39 | (println "→ No changes to commit.") |
41 | 40 | (do |
42 | 41 | (println "→ Changes detected, committing...") |
43 | | - (shell "git" "commit" "-m" (str "[auto] adding content to " target-branch)) |
44 | | - (shell "git" "push" "--force" "origin" target-branch) |
| 42 | + (p/shell "git" "commit" "-m" (str "[auto] adding content to " target-branch)) |
| 43 | + (p/shell "git" "push" "--force" "origin" target-branch) |
45 | 44 | (println "→ Branch updated successfully."))) |
46 | 45 |
|
47 | 46 | (println "→ Checking for existing PR...") |
|
50 | 49 | (println "✓ PR already exists: #" existing-pr?) |
51 | 50 | (do |
52 | 51 | (println "→ Creating new PR...") |
53 | | - (shell "gh" "pr" "create" |
54 | | - "--repo" "metabase/docs.metabase.github.io" |
55 | | - "--title" target-branch |
56 | | - "--body" (str "updated: " (pr-str artifact-dirs)) |
57 | | - "--head" target-branch))))) |
| 52 | + (p/shell "gh" "pr" "create" |
| 53 | + "--repo" "metabase/docs.metabase.github.io" |
| 54 | + "--title" target-branch |
| 55 | + "--body" (str "updated: " (pr-str artifact-dirs)) |
| 56 | + "--head" target-branch))))) |
58 | 57 |
|
59 | 58 | (when (= *file* (System/getProperty "babashka.file")) |
60 | 59 | (apply -main *command-line-args*)) |
|
0 commit comments