-
Notifications
You must be signed in to change notification settings - Fork 12
/
common.clj
45 lines (35 loc) · 1.46 KB
/
common.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
(ns metav.domain.version.common
(:require
[metav.domain.version.protocols :as protocols]))
(def default-initial-subversions [0 1 0])
(defn bump-subversions [subversions level]
(let [[major minor patch] subversions]
(case level
:major [(inc major) 0 0]
:minor [major (inc minor) 0]
:patch [major minor (inc patch)])))
(defn duplicating-version? [v level]
(let [[_ minor patch] (protocols/subversions v)
distance (protocols/distance v)
same-patch? (= level :patch)
same-minor? (and (= level :minor)
(= patch 0))
same-major? (and (= level :major)
(= patch 0)
(= minor 0))]
(and (= distance 0)
(or same-patch?
same-minor?
same-major?))))
(defn going-backwards? [old-version new-version]
(pos? (compare old-version new-version)))
(defn assert-bump? [old-version level new-version]
(when (duplicating-version? old-version level)
(throw (Exception. (str "Aborted released, bumping with level: " level
" would create version: " new-version " pointing to the same commit as version: " old-version "."))))
(when (going-backwards? old-version new-version)
(throw (Exception. (str "Can't bump version to an older one : " old-version " -> " new-version " isn't allowed.")))))
(defn bump [v level]
(let [new-v (protocols/bump v level)]
(assert-bump? v level new-v)
new-v))