Skip to content

Commit 902549e

Browse files
committed
fix the script
1 parent b54e068 commit 902549e

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

script/update_or_create_pr.clj

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,61 @@
88
(println "Usage: script/update_or_create_pr.clj branchname")
99
(System/exit 1))
1010

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
1312

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))))
1520

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])))
1757

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

Comments
 (0)