Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushgaud committed Nov 15, 2023
1 parent d69cc87 commit 57cb436
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
38 changes: 18 additions & 20 deletions src/wrike_ist/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,23 @@
(if-let [pr (.-pull_request payload)]
(loop [links (extract-details pr)]
(when-let [{:keys [state] :as details} (first links)]
(let [check-valid-task-promise (wrike/check-valid-task details)]
(js/Promise.all
(case state
:draft [(wrike/link-pr details) check-valid-task-promise]
:open [(wrike/link-pr details)
(wrike/progress-task details (core/getInput "opened"))
check-valid-task-promise]
:merged [(wrike/complete-task details (core/getInput "merged"))
check-valid-task-promise]
:closed [(wrike/cancel-task details (core/getInput "closed"))
check-valid-task-promise]
:else [check-valid-task-promise]))
(.then
(fn [result]
(.info js/console (str "Main function success: " result))
(js/Promise.resolve result))
(.catch
(fn [error]
(.error js/console (str "Main function error: " error))
(js/Promise.reject error)))))
(-> (case state
:draft
(wrike/link-pr details)

:open
(js/Promise.all
[(wrike/link-pr details)
(wrike/progress-task details (core/getInput "opened"))])

:merged
(wrike/complete-task details (core/getInput "merged"))

:closed
(wrike/cancel-task details (core/getInput "closed"))

;; else ignore
(js/Promise.resolve))
(.catch #(core/setFailed (.-message %))))
(recur (rest links))))
(js/console.log "No pull_request in payload"))))
39 changes: 25 additions & 14 deletions src/wrike_ist/wrike.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@


(defn check-valid-task
[{:keys [permalink target-branch]}]
[permalink target-branch]
(js/Promise.
(fn [resolve reject]
(when (and target-branch (str/starts-with? target-branch "main"))
Expand All @@ -108,31 +108,42 @@
(reject (js/Error. "check-valid-task: Task not found in folder")))))))))))

(defn link-pr
[{:keys [pr-url permalink] :as details}]
(.then
(find-task permalink)
(fn [{:strs [id]}]
(let [uri (str "https://www.wrike.com/api/v4/tasks/" id "/comments")]
(-> (http/get uri {:headers (headers)})

(.then (fn find-existing-link [response]
[{:keys [pr-url permalink target-branch] :as details}]
(let [check-valid-task-promise (check-valid-task permalink target-branch)]
(-> (find-task permalink)
(.then
(fn [{:strs [id]}]
(let [uri (str "https://www.wrike.com/api/v4/tasks/" id "/comments")]
(-> (http/get uri {:headers (headers)})
(.then
(fn find-existing-link [response]
(reduce
(fn [ok comment]
(if (.includes (get comment "text") pr-url)
(reduced (js/Promise.reject :present))
ok))
(js/Promise.resolve)
(get (parse-body response) "data"))))
(.then (fn add-link-comment [& _]
(.then
(fn add-link-comment [& _]
(let [comment-text (link-html details)
params (clj->js {:text comment-text
:plainText false})]
(http/post uri {:headers (headers)
:body (js/JSON.stringify params)}))))
(.then #(.log js/console (str "link-pr: PR link sent to task")))
(.catch #(if (= % :present)
(.log js/console (str "link-pr: PR link already in comments"))
(js/Promise.resolve %))))))))
(.then #(.log js/console (str "link-pr: PR link sent to task")))
(.catch
#(if (= % :present)
(.log js/console (str "link-pr: PR link already in comments"))
(js/Promise.resolve %)))))))
(.then
(fn [_]
(js/Promise.all [check-valid-task-promise]))
(.catch #(js/Promise.reject %))))))





(defn folder-statuses
[folder-id]
Expand Down

0 comments on commit 57cb436

Please sign in to comment.