-
Notifications
You must be signed in to change notification settings - Fork 12
/
git_operations.clj
72 lines (60 loc) · 3.13 KB
/
git_operations.clj
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(ns metav.domain.git-operations
(:require
[clojure.spec.alpha :as s]
[clojure.data.json :as json]
[metav.domain.context]
[metav.domain.metadata :as metadata]
[metav.domain.git :as git]
[metav.utils :as utils]
[metav.domain.context]))
(s/def ::working-dir-present (s/keys :req [:metav/working-dir]))
(s/def ::top-level-present (s/keys :req [:metav/top-level]))
;;----------------------------------------------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------------------------------------------
(defn check-committed? [context]
(-> context
(->> (utils/check-spec ::working-dir-present))
(-> :metav/working-dir
git/assert-committed?))
context)
;;----------------------------------------------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------------------------------------------
(def default-tag-options
#:metav.git{:without-sign false})
(s/def :metav.git/without-sign boolean?)
(s/def :metav.git.tag-repo/options (s/keys :opt [:metav.git/without-sign]))
(s/def ::tag-repo!-param (s/merge :metav/context
:metav.git.tag-repo/options))
(defn tag-repo! [context]
(let [context (-> context
(utils/merge&validate default-tag-options ::tag-repo!-param)
(check-committed?))
{:metav/keys [top-level tag]
:metav.git/keys [without-sign]} context
annotation (json/write-str (metadata/metadata-as-edn context))
tag-result (apply git/tag! top-level
tag
annotation
(when without-sign [:sign false]))]
(if (int? (first tag-result)) ;;error exit code if so return stderr
(throw (Exception. (str "Error with git tag command:" (get tag-result 2))))
(assoc context
:metav.release/tag-result {:git-res tag-result
:tag tag
:annotation annotation}))))
;;----------------------------------------------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------------------------------------------
(defn commit! [context msg]
(let [commit-res (-> context
(->> (utils/check-spec ::working-dir-present))
(-> :metav/working-dir
(git/commit! msg)))]
(assoc context :metav.git/committed
{:commit-res commit-res
:msg msg})))
;;----------------------------------------------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------------------------------------------
(defn push! [context]
(utils/check-spec ::top-level-present context)
(let [top-level (:metav/top-level context)]
(assoc context :metav.release/push-result (git/push! top-level))))