M src/veneer/cloud/backend.cljs +18 -1
@@ 38,6 38,10 @@
"Commit a workspace onto a service/repository/branch"
(fn [service & _] service))
+(defmulti release!
+ "Mark a commit as release"
+ (fn [service & _] service))
+
;; ### Multimethod implementations to delegate to appropriate service backend
(defmethod query :github [service & qp]
@@ 58,9 62,14 @@
(go (into [:github] (<! (apply github/fetch-path path)))))
(defmethod fetch-path :bitbucket [[service & path]]
(go (into [:bitbucket] (<! (apply bitbucket/fetch-path path)))))
+
(defmethod commit! :github [service & params]
(apply github/commit! params))
+(defmethod release! :github [service slug hash tag-name]
+ (github/release! slug hash tag-name))
+
+
(s/fdef
fetch-path
:ret
@@ 79,4 88,12 @@
(fn [digit]
(let [num (js/parseInt digit)]
(if (js/isNaN num) digit num))))
- (vec)))
No newline at end of file
+ (vec)))
+
+(defn vec->semver
+ "Convert a vector of numbers into a semantic version"
+ [v]
+ (->> v
+ (filter integer?)
+ (take 3)
+ (str/join ".")))
No newline at end of file
M src/veneer/cloud/github.cljs +15 -6
@@ 327,7 327,7 @@
user repo
(-> (str "/repos/" user "/" repo)
req? <? :body js->clj
- (get "default_branch" "master"))))))))
+ (get "default_branch" "main"))))))))
(defn fetch
([fmt user repo branch sha path]
@@ 558,24 558,33 @@
"veneer-repository"))))]
slug))
-(defn update-or-create-branch! [slug branch commit-sha]
+(defn update-or-create-ref! [slug ref-type name commit-sha]
(go-try
(if
- (-> (str "/repos/" slug "/git/ref/heads/" branch)
+ (-> (str "/repos/" slug "/git/ref/" ref-type "/" name)
req? <? :status (= 404))
; create
(<? (req?
(str "/repos/" slug "/git/refs")
{:method "POST"
:body (str
- "{\"ref\":" (pr-str (str "refs/heads/" branch))
+ "{\"ref\":" (pr-str (str "refs/" ref-type "/" name))
",\"sha\":\"" commit-sha "\"}")}))
; update
(<? (req?
- (str "/repos/" slug "/git/refs/heads/" branch)
+ (str "/repos/" slug "/git/refs/" ref-type "/" name)
{:method "PATCH"
:body (str "{\"sha\":\"" commit-sha "\"}")})))))
+(defn update-or-create-branch! [slug branch commit-sha]
+ (update-or-create-ref! slug "heads" branch commit-sha))
+
+(defn update-or-create-tag! [slug tag commit-sha]
+ (update-or-create-ref! slug "tags" tag commit-sha))
+
+(defn release! [slug hash tag]
+ (update-or-create-tag! slug tag hash))
+
(defn commit! [workspace assets message]
(let [progress (chan)]
(go
@@ 653,7 662,7 @@
(some-> workspace :manifest :origin :branch)
branch
- (if-not (str/blank? branch-name) branch-name "master")
+ (if-not (str/blank? branch-name) branch-name "main")
update
(binding [*request-context* "updating branch"]
M src/veneer/commands.cljs +54 -24
@@ 622,30 622,35 @@
(defn perform-commit!
"Commit changes to workspace to a cloud backend"
- []
- (when-let [msg (js/prompt "Please enter a commit message", "")]
- (m/update!
- nil [:manifest :name]
- (fn [n]
- (or n
- (js/prompt
- "Please name the repository:"
- "my-project"))))
- (cloud-progress
- (cloudbe/commit!
- (-> @model& :manifest :origin :service
- (or (-> @cfg/cfg& :cloud :default-service) :github)
- keyword)
- @model&
- @assets/assets& msg)
- (n/progress! "Committing...")
- #(do
- (n/info! [:<>
- [:h2 "Success!"]
- [:p "Committed as " (->> % :commit-hash (take 8))]])
- (m/update! nil [:manifest]
- assoc :origin
- (-> % :workspace :manifest :origin))))))
+ ([] (perform-commit! nil nil))
+ ([message callback-hash]
+ (when-let [msg (or
+ message
+ (js/prompt "Please enter a commit message", ""))]
+ (m/update!
+ nil [:manifest :name]
+ (fn [n]
+ (or n
+ (js/prompt
+ "Please name the repository:"
+ "my-project"))))
+ (cloud-progress
+ (cloudbe/commit!
+ (-> @model& :manifest :origin :service
+ (or (-> @cfg/cfg& :cloud :default-service) :github)
+ keyword)
+ @model&
+ @assets/assets& msg)
+ (n/progress! "Committing...")
+ #(do
+ (n/info! [:<>
+ [:h2 "Success!"]
+ [:p "Committed as " (->> % :commit-hash (take 8))]])
+ (m/update! nil [:manifest]
+ assoc :origin
+ (-> % :workspace :manifest :origin))
+ (when callback-hash
+ (callback-hash (->> % :commit-hash))))))))
(defcmd :project/cloud.commit
#(perform-commit!))
@@ 660,6 665,31 @@
(when (js/confirm "Commit immediately to remote repository?")
(perform-commit!)))))
+(defn next-version [version]
+ (if version
+ (-> version
+ cloudbe/semver->vec
+ (as-> v (update v (dec (count v)) inc))
+ cloudbe/vec->semver)
+ "0.1"))
+
+(defcmd :project/cloud.release
+ (fn []
+ (when-let [version
+ (js/prompt "Release current version as"
+ (-> @model& :manifest :version next-version str))]
+ (m/update! nil [:manifest :version] (constantly version))
+ (let [manifest (:manifest @model&)]
+ (perform-commit!
+ (str "Release " version)
+ #(cloudbe/release!
+ (-> manifest :origin :service
+ (or (-> @cfg/cfg& :cloud :default-service) :github)
+ keyword)
+ (-> manifest :origin :slug)
+ %
+ version))))))
+
(defn cloud-checkout! [path]
(cloud-progress
(checkout/checkout path)
M src/veneer/util/hid.cljs +1 -1
@@ 651,7 651,7 @@
#{cmd snd "b"} :project/cloud.branch
; #{cmd snd "m"} :project/cloud.pull
#{cmd snd "p"} :project/cloud.use-packages
-; #{cmd snd "r"} :project/cloud.tag-release
+ #{cmd snd "e"} :project/cloud.release
#{cmd "f7"} :project/cloud.builds
#{} :project/global.preferences