Ignore comments in PR body + unit test
* ignore markdown comments in PR body * unit test coverage for issue-id extraction from PR webhook
This commit is contained in:
parent
0c52b24b51
commit
6e60802803
|
@ -80,7 +80,8 @@
|
|||
|
||||
(defn extract-issue-number
|
||||
[pr-body pr-title]
|
||||
(let [extract (fn [source]
|
||||
(let [cleaned-body (str/replace pr-body #"(?m)^\[comment.*$" "")
|
||||
extract (fn [source]
|
||||
(mapcat #(keep
|
||||
(fn [s]
|
||||
(try (let [issue-number (Integer/parseInt (second s))]
|
||||
|
@ -88,7 +89,8 @@
|
|||
issue-number))
|
||||
(catch NumberFormatException _)))
|
||||
(re-seq % source)) keywords))]
|
||||
(concat (extract pr-body)
|
||||
(log/debug cleaned-body)
|
||||
(concat (extract cleaned-body)
|
||||
(extract pr-title))))
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
(ns commiteth.test.webhooks
|
||||
(:require [clojure.test :refer :all]
|
||||
[commiteth.routes.webhooks :as webhooks]))
|
||||
|
||||
|
||||
(deftest test-issue-number-extraction
|
||||
(testing "Basic fixes case from PR body"
|
||||
(let [title "foo"
|
||||
body "fixes #123"]
|
||||
(is (= '(123) (webhooks/extract-issue-number body title)))))
|
||||
(testing "Basic fixes case from PR title"
|
||||
(let [title "My title (fixes: #123)"
|
||||
body "no use for a body"]
|
||||
(is (= '(123) (webhooks/extract-issue-number body title)))))
|
||||
(testing "Commented issue number ignored in PR body"
|
||||
(let [title "foo"
|
||||
body "
|
||||
fixes #123
|
||||
[comment]: # (To auto-close issue on merge, please insert the related issue number after # i.e fixes #566)
|
||||
"]
|
||||
(is (= '(123) (webhooks/extract-issue-number body title))))
|
||||
))
|
Loading…
Reference in New Issue