Skip to content

Commit

Permalink
test: add tests for pure functions, add body and footer to commit-msg…
Browse files Browse the repository at this point in the history
….txt
  • Loading branch information
batovpasha committed Dec 3, 2024
1 parent 2f8d8ec commit a866bf9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
6 changes: 5 additions & 1 deletion commit-msg.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
very good commit message
feat: very good commit message

Optional body

Optional footer
31 changes: 16 additions & 15 deletions src/pre_commit_jira/hooks/add_jira_ticket.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
(:require [clojure.string :as str])
(:require [clojure.test :refer [is with-test]]))

(defn- get-current-branch-name
(defn get-current-branch-name
[]
(-> (shell/sh "git" "symbolic-ref" "--short" "HEAD")
(:out)
(str/replace "\n" "")))

(defn- get-jira-ticket-from
[string]
(let [ticket-pattern #"[A-Z]+-\d+"]
(re-find ticket-pattern string)))
(with-test
(defn get-jira-ticket-from
[string]
(let [ticket-pattern #"[A-Z]+-\d+"]
(re-find ticket-pattern string)))

(is (= "TICKET-123" (get-jira-ticket-from "feature/TICKET-123-some-feature")))
(is (= nil (get-jira-ticket-from "feature/some-feature"))))

(comment
(get-jira-ticket-from "feature/TICKET-123-feature-name"))
(with-test
(defn special-commit?
[commit-msg]
(let [is-merge-commit (str/starts-with? commit-msg "Merge ")]
is-merge-commit))

(defn- special-commit?
[commit-msg]
(let [is-merge-commit (str/starts-with? commit-msg "Merge ")]
is-merge-commit))
(is (= true (special-commit? "Merge pull request")))
(is (= true (special-commit? "Merge branch 'develop' into feature/TICKET-123-some-feature"))))

(with-test
(defn prepend-jira-ticket
Expand All @@ -35,8 +40,6 @@
(is (= "feat: TICKET-123 simple solution for a big trouble"
(prepend-jira-ticket "feat: simple solution for a big trouble" "TICKET-123"))))

(test #'prepend-jira-ticket)

(comment (prepend-jira-ticket "feat: commit\nOptional body\nOptional footer" "TICKET-123"))

(defn add-jira-ticket
Expand All @@ -54,5 +57,3 @@
(not (special-commit? commit-msg)))
(->> (prepend-jira-ticket commit-msg ticket-from-branch)
(spit commit-msg-file-path)))))

(add-jira-ticket "commit-msg.txt")

0 comments on commit a866bf9

Please sign in to comment.