-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnew-commit-every-minute.bb
More file actions
executable file
·44 lines (38 loc) · 1006 Bytes
/
new-commit-every-minute.bb
File metadata and controls
executable file
·44 lines (38 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bb
(require '[clojure.java.shell :refer [sh]])
(require '[clojure.string :as s]) ; why is this a separate ns 😒
(defn changes? []
(->> (sh "git" "diff" "--exit-code")
:exit
zero?
not))
(defn new-files? []
(->> (sh "git" "diff-index" "--quiet" "HEAD" "--")
:exit
zero?))
(defn commit-count []
(->> (sh "git" "rev-list" "--count" "HEAD")
:out
s/trim
Integer/parseInt
inc))
(defn commit! []
(when (or (changes?)
(new-files?))
(let [n (commit-count)]
(sh "git" "add" "-A")
(sh "git" "commit" "-m" (str n))
(println (str (java.time.Instant/now)) n)
true)))
; for better aesthetics
(defn wait-until-next-full-minute []
(let [m (* 60 1000)
now (System/currentTimeMillis)
next-m (* m (quot (+ now m) m))
remaining (- next-m now)]
(Thread/sleep remaining)))
(loop []
(wait-until-next-full-minute)
(when (commit!)
(sh "git" "push"))
(recur))