forked from valerauko/wrike-ist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update wrike-ist action to include Github links in Azure (#3)
- Loading branch information
Showing
14 changed files
with
32,274 additions
and
6,260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(ns wrike-ist.azure | ||
(:require [httpurr.client.node :as http] | ||
[clojure.string :as str])) | ||
(defn- azure-token [] | ||
(some-> js/process .-env .-AZURE_TOKEN .trim)) | ||
|
||
(defn- headers [] | ||
{:Authorization (str "Basic " (js/btoa (str ":" (azure-token)))) | ||
:Content-Type "application/json"}) | ||
|
||
(defn parse-body | ||
[response] | ||
(js->clj (js/JSON.parse (:body response)))) | ||
|
||
(defn link-html | ||
[{:keys [id pr-url target-branch repository-name title]}] | ||
(if (empty? title) | ||
(str "Pull request for " target-branch ": " "<a href=\"" pr-url "\">" " (#" id ")</a>") | ||
(str "Pull request for " repository-name " on branch " target-branch ": " "<a href=\"" pr-url "\">" title " (#" id ")</a>"))) | ||
|
||
(defn find-task | ||
[url] | ||
(let [pattern #"https://dev\.azure\.com/([^/]+)/([^/]+)/_workitems/edit/(\d+)" | ||
matches (re-seq pattern url)] | ||
(js/Promise. | ||
(fn [resolve reject] | ||
(if (seq matches) | ||
(let [[_ organization project task-id] (first matches)] | ||
(resolve {:organization organization | ||
:project project | ||
:task-id (js/parseInt task-id)})) | ||
(reject (js/Error. "No task ID found"))))))) | ||
|
||
(defn link-pr | ||
[{:keys [pr-url permalink] :as details}] | ||
(.then | ||
(find-task permalink) | ||
(fn [{:keys [organization project task-id]}] | ||
(js/console.log (str "link-pr: Found organization:" organization " project:" project " task-id:" task-id)) | ||
(js/console.log (str "headers:" (headers))) | ||
(let [uri (str "https://dev.azure.com/" organization "/" project "/_apis/wit/workitems/" task-id "/comments?api-version=7.0-preview.3")] | ||
;; (js/console.log (str "uri:" uri)) | ||
(-> (http/get uri {:headers (headers)}) | ||
(.then (fn find-existing-link [response] | ||
;; (js/console.log (str "find-existing-link: response:" 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) "comments")))) | ||
(.then (fn add-link-comment [& _] | ||
(let [comment-text (link-html details) | ||
params (clj->js {:text comment-text})] | ||
(js/console.log (str "add-link-comment: params:" (js/JSON.stringify params))) | ||
(-> (http/post uri {:headers (headers) | ||
:body (js/JSON.stringify params)}) | ||
(.then (fn [response] | ||
(js/console.log (str "add-link-comment: response:" response))))) | ||
))) | ||
(.then #(js/console.log "PR link sent to task")) | ||
(.catch #(if (= % :present) | ||
(js/console.log "PR link already in comments") | ||
(js/Promise.reject %)))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns wrike-ist.azure-test | ||
(:require [cljs.test :refer-macros [deftest is testing]] | ||
[wrike-ist.azure :refer [link-html]])) | ||
|
||
(deftest link-html-test | ||
(testing "No title" | ||
(let [url "https://github.com/valerauko/wrike-ist/pull/9001" | ||
data {:pr-url url}] | ||
(is (= url (re-find (re-pattern url) (link-html data)))))) | ||
(testing "With title" | ||
(let [url "https://github.com/valerauko/wrike-ist/pull/9001" | ||
title "hoge" | ||
data {:pr-url url :title title}] | ||
(is (= url (re-find (re-pattern url) (link-html data)))) | ||
(is (= title (re-find (re-pattern title) (link-html data))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.