diff --git a/package.json b/package.json index 77981fa..610bca3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wrike-ist", - "version": "1.4.0", + "version": "1.5.0", "description": "GitHub Action for Wrike automation", "main": "resources/main.js", "scripts": { diff --git a/resources/index.js b/resources/index.js index 469debc..275d193 100755 --- a/resources/index.js +++ b/resources/index.js @@ -12128,30 +12128,30 @@ cljs.core.into_array.cljs$core$IFn$_invoke$arity$2=function(a,b){a=function(d,e) cljs.core.js_invoke=function(a){for(var b=[],c=arguments.length,d=0;;)if(d (case state - :open (wrike/link-pr details) - :merged (wrike/complete-task details (core/getInput "merged")) - :closed (wrike/cancel-task details (core/getInput "closed")) - (js/Promise.resolve)) - (.catch #(core/setFailed (.-message %)))) - (js/console.log "Not task link in PR text")) + (loop [links (extract-details pr)] + (when-let [{:keys [state] :as details} (first links)] + (-> (case state + :open (wrike/link-pr details) + :merged (wrike/complete-task details (core/getInput "merged")) + :closed (wrike/cancel-task details (core/getInput "closed")) + (js/Promise.resolve)) + (.catch #(core/setFailed (.-message %)))) + (recur (rest links)))) (js/console.log "No pull_request in payload")))) diff --git a/test/wrike_ist/core_test.cljs b/test/wrike_ist/core_test.cljs index 69d1198..d7a5c81 100644 --- a/test/wrike_ist/core_test.cljs +++ b/test/wrike_ist/core_test.cljs @@ -1,6 +1,24 @@ (ns wrike-ist.core-test - (:require [cljs.test :refer-macros [deftest is testing run-tests]] - [wrike-ist.core :refer [extract-details]])) + (:require [cljs.test :refer-macros [deftest is testing]] + [wrike-ist.core :refer [extract-details + find-links]])) + +(deftest links-test + (testing "No link in text" + (is (= nil (find-links "")))) + (testing "One link in text" + (let [url "https://www.wrike.com/open.htm?id=1"] + (is (= (list url) (find-links (str "a\n" url "\nb")))))) + (testing "Multiple links in text" + (let [url-1 "https://www.wrike.com/open.htm?id=1" + url-2 "https://www.wrike.com/open.htm?id=2"] + (is (= (list url-1 url-2) (find-links (str url-1 "\nfoo: " url-2 "\n")))))) + (testing "No separator around the link" + ;; anything \b matches will do + (let [url "https://www.wrike.com/open.htm?id=1"] + (is (= nil (find-links (str "1" url)))) + (is (= nil (find-links (str url "b")))) + (is (= nil (find-links (str "1" url "b"))))))) (deftest extract-details-test (testing "No .body in payload" @@ -10,37 +28,44 @@ (let [payload (clj->js {:body ""})] (is (= nil (extract-details payload))))) (testing "Extract link from payload" - (let [url "https://www.wrike.com/open.htm?id=1" - payload (clj->js {:body (str "a\n" url "\nb")})] - (is (= url (:permalink (extract-details payload)))))) + (testing "One link" + (let [url "https://www.wrike.com/open.htm?id=1" + payload (clj->js {:body (str "a\n" url "\nb")})] + (is (= url (:permalink (first (extract-details payload))))))) + (testing "Multiple links" + (let [url-1 "https://www.wrike.com/open.htm?id=1" + url-2 "https://www.wrike.com/open.htm?id=2" + payload (clj->js {:body (str "a\n" url-1 "\nb " url-2)})] + (is (= url-1 (:permalink (first (extract-details payload))))) + (is (= url-2 (:permalink (second (extract-details payload)))))))) (testing "Extract pull request URL from payload" (let [url "https://github.com/valerauko/wrike-ist/pull/9001" payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :html_url url})] - (is (= url (:pr-url (extract-details payload)))))) + (is (= url (:pr-url (first (extract-details payload))))))) (testing "Extract pull request title from payload" (let [title "hoge" payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :title title})] - (is (= title (:title (extract-details payload)))))) + (is (= title (:title (first (extract-details payload))))))) (testing "Translating pull request state" (let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :merged true :state "closed"})] - (is (= :merged (:state (extract-details payload))))) + (is (= :merged (:state (first (extract-details payload)))))) (let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :merged true})] - (is (= :merged (:state (extract-details payload))))) + (is (= :merged (:state (first (extract-details payload)))))) (let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :merged false :state "closed"})] - (is (= :closed (:state (extract-details payload))))) + (is (= :closed (:state (first (extract-details payload)))))) (let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :state "closed"})] - (is (= :closed (:state (extract-details payload))))) + (is (= :closed (:state (first (extract-details payload)))))) (let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1" :merged false :state "open"})] - (is (= :open (:state (extract-details payload))))) + (is (= :open (:state (first (extract-details payload)))))) (let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"})] - (is (= :open (:state (extract-details payload))))))) + (is (= :open (:state (first (extract-details payload))))))))