mirror of
https://github.com/status-im/open-bounty.git
synced 2025-02-19 20:58:32 +00:00
Parse issue URLs during issue number extraction
This commit is contained in:
parent
400f848e08
commit
df93a502df
@ -82,20 +82,25 @@
|
|||||||
(when (issues/is-bounty-issue? issue-id)
|
(when (issues/is-bounty-issue? issue-id)
|
||||||
(issues/update-open-status issue-id true)))
|
(issues/update-open-status issue-id true)))
|
||||||
|
|
||||||
(def ^:const keywords
|
(defn pr-keywords [prefix]
|
||||||
[#"(?i)close:?\s+#(\d+)"
|
(mapv
|
||||||
#"(?i)closes:?\s+#(\d+)"
|
#(re-pattern (str "(?i)" %1 ":?\\s+" prefix "(\\d+)"))
|
||||||
#"(?i)closed:?\s+#(\d+)"
|
["close"
|
||||||
#"(?i)fix:?\s+#(\d+)"
|
"closes"
|
||||||
#"(?i)fixes:?\s+#(\d+)"
|
"closed"
|
||||||
#"(?i)fixed:?\s+#(\d+)"
|
"fix"
|
||||||
#"(?i)resolve:?\s?#(\d+)"
|
"fixes"
|
||||||
#"(?i)resolves:?\s+#(\d+)"
|
"fixed"
|
||||||
#"(?i)resolved:?\s+#(\d+)"])
|
"resolve"
|
||||||
|
"resolves"
|
||||||
|
"resolved"]))
|
||||||
|
|
||||||
(defn extract-issue-number
|
(defn extract-issue-number
|
||||||
[pr-body pr-title]
|
[owner repo pr-body pr-title]
|
||||||
(let [cleaned-body (str/replace pr-body #"(?m)^\[comment.*$" "")
|
(let [cleaned-body (str/replace pr-body #"(?m)^\[comment.*$" "")
|
||||||
|
keywords (concat (pr-keywords "#")
|
||||||
|
(when-not (or (str/blank? owner) (str/blank? repo))
|
||||||
|
(pr-keywords (str "https://github.com/" owner "/" repo "/"))))
|
||||||
extract (fn [source]
|
extract (fn [source]
|
||||||
(mapcat #(keep
|
(mapcat #(keep
|
||||||
(fn [s]
|
(fn [s]
|
||||||
@ -169,7 +174,7 @@
|
|||||||
pr-body :body
|
pr-body :body
|
||||||
pr-title :title} :pull_request}]
|
pr-title :title} :pull_request}]
|
||||||
(log/info "handle-pull-request-event" event-type owner repo repo-id login pr-body pr-title)
|
(log/info "handle-pull-request-event" event-type owner repo repo-id login pr-body pr-title)
|
||||||
(if-let [issue (some->> (extract-issue-number pr-body pr-title)
|
(if-let [issue (some->> (extract-issue-number owner repo pr-body pr-title)
|
||||||
(first)
|
(first)
|
||||||
(issues/get-issue repo-id))]
|
(issues/get-issue repo-id))]
|
||||||
(if-not (:commit_sha issue) ; no PR has been merged yet referencing this issue
|
(if-not (:commit_sha issue) ; no PR has been merged yet referencing this issue
|
||||||
|
@ -4,14 +4,20 @@
|
|||||||
|
|
||||||
(deftest test-github-keywords
|
(deftest test-github-keywords
|
||||||
(testing "Several keywords in mixed case"
|
(testing "Several keywords in mixed case"
|
||||||
(let [res (set (extract-issue-number "body"
|
(let [res (set (extract-issue-number "" "" "body"
|
||||||
"Fixes #12 and cloSes #000028 and also resolved \n#32"))]
|
"Fixes #12 and cloSes #000028 and also resolved \n#32"))]
|
||||||
(is (= #{12 28 32} res))))
|
(is (= #{12 28 32} res))))
|
||||||
(testing "Ignoring big numbers and zeroes"
|
(testing "Ignoring big numbers and zeroes"
|
||||||
(let [res (set (extract-issue-number "body"
|
(let [res (set (extract-issue-number "" "" "body"
|
||||||
"Fixes #298374298229087345 and closes #0xFFEF"))]
|
"Fixes #298374298229087345 and closes #0xFFEF"))]
|
||||||
(is (= #{} res))))
|
(is (= #{} res))))
|
||||||
(testing "Consider both body and title"
|
(testing "Consider both body and title"
|
||||||
(let [res (set (extract-issue-number "Fixes #1"
|
(let [res (set (extract-issue-number "" ""
|
||||||
|
"Fixes #1"
|
||||||
"Fixes #2"))]
|
"Fixes #2"))]
|
||||||
|
(is (= #{1 2} res))))
|
||||||
|
(testing "Use issue URL instead of number"
|
||||||
|
(let [res (set (extract-issue-number "status-im" "status-react"
|
||||||
|
"Fixes https://github.com/status-im/status-react/1"
|
||||||
|
"Fixes https://github.com/status-im/status-react/2"))]
|
||||||
(is (= #{1 2} res)))))
|
(is (= #{1 2} res)))))
|
||||||
|
@ -7,15 +7,15 @@
|
|||||||
(testing "Basic fixes case from PR body"
|
(testing "Basic fixes case from PR body"
|
||||||
(let [title "foo"
|
(let [title "foo"
|
||||||
body "fixes #123"]
|
body "fixes #123"]
|
||||||
(is (= '(123) (webhooks/extract-issue-number body title)))))
|
(is (= '(123) (webhooks/extract-issue-number "" "" body title)))))
|
||||||
(testing "Basic fixes case from PR title"
|
(testing "Basic fixes case from PR title"
|
||||||
(let [title "My title (fixes: #123)"
|
(let [title "My title (fixes: #123)"
|
||||||
body "no use for a body"]
|
body "no use for a body"]
|
||||||
(is (= '(123) (webhooks/extract-issue-number body title)))))
|
(is (= '(123) (webhooks/extract-issue-number "" "" body title)))))
|
||||||
(testing "Commented issue number ignored in PR body"
|
(testing "Commented issue number ignored in PR body"
|
||||||
(let [title "foo"
|
(let [title "foo"
|
||||||
body "
|
body "
|
||||||
fixes #123
|
fixes #123
|
||||||
[comment]: # (To auto-close issue on merge, please insert the related issue number after # i.e fixes #566)
|
[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))))))
|
(is (= '(123) (webhooks/extract-issue-number "" "" body title))))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user