Skip to content

Commit

Permalink
Make it possible to disable closed/merged (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerauko committed May 30, 2023
2 parents 19320de + 3e3b3ff commit 5d7031b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: node_modules
key: node-${{ hashFiles('yarn.lock') }}
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/.m2
key: maven-${{ hashFiles('shadow-cljs.edn') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: wrike-ist
env:
WRIKE_TOKEN: ${{ secrets.WRIKE_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: node_modules
key: node-${{ hashFiles('yarn.lock') }}
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/.m2
key: maven-${{ hashFiles('shadow-cljs.edn') }}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ Specifies the status to move the task to when the linked PR is merged.

If not specified or not found, falls back to the first Completed status in your workflow.

The transition can be disabled by setting the `merged` value to `"-"`.

#### `closed`

Specifies the status to move the task to when the linked PR is closed without merging.

If not specified or not found, falls back to the first Cancelled status in your workflow.

The transition can be disabled by setting the `closed` value to `"-"`.

## Development

```shell
Expand Down
4 changes: 2 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ branding:
inputs:
merged:
required: false
description: Status to move task to when the PR is merged. Defaults to the first Completed status in your workflow.
description: Status to move task to when the PR is merged. Defaults to the first Completed status in your workflow. Can be disabled by setting it to "-".
closed:
required: false
description: Status to move task to when the PR is closed without merging. Defaults to the first Cancelled status in your workflow.
description: Status to move task to when the PR is closed without merging. Defaults to the first Cancelled status in your workflow. Can be disabled by setting it to "-".
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wrike-ist",
"version": "1.3.2",
"version": "1.4.0",
"description": "GitHub Action for Wrike automation",
"main": "resources/main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14212,8 +14212,8 @@ wrike_ist.wrike.next_status=function(a,b){b=cljs.core.__destructure_map(b);var c
c)?cljs.core.reduced(g):cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.get.cljs$core$IFn$_invoke$arity$2(f,"group"),d)?f:g},cljs.core.PersistentArrayMap.EMPTY,e)})};
wrike_ist.wrike.update_task_status=function(a,b){a=cljs.core.__destructure_map(a);var c=cljs.core.get.cljs$core$IFn$_invoke$arity$2(a,"id");a=cljs.core.get.cljs$core$IFn$_invoke$arity$2(a,"parentIds");a=cljs.core.nth.cljs$core$IFn$_invoke$arity$3(a,0,null);return wrike_ist.wrike.next_status(a,b).then(function(d){d=cljs.core.__destructure_map(d);var e=cljs.core.get.cljs$core$IFn$_invoke$arity$2(d,"id");d=["https://www.wrike.com/api/v4/tasks/",cljs.core.str.cljs$core$IFn$_invoke$arity$1(c)].join("");
e=cljs.core.clj__GT_js(new cljs.core.PersistentArrayMap(null,1,[cljs$cst$213$customStatus,e],null));return httpurr.client.node.put(d,new cljs.core.PersistentArrayMap(null,2,[cljs$cst$183$headers,wrike_ist.wrike.headers(),cljs$cst$184$body,JSON.stringify(e)],null))})};
wrike_ist.wrike.complete_task=function(a,b){a=cljs.core.__destructure_map(a);a=cljs.core.get.cljs$core$IFn$_invoke$arity$2(a,cljs$cst$207$permalink);return wrike_ist.wrike.find_task(a).then(function(c){return wrike_ist.wrike.update_task_status(c,new cljs.core.PersistentArrayMap(null,2,[cljs$cst$211$wanted_status,b,cljs$cst$212$wanted_group,"Completed"],null))})};
wrike_ist.wrike.cancel_task=function(a,b){a=cljs.core.__destructure_map(a);a=cljs.core.get.cljs$core$IFn$_invoke$arity$2(a,cljs$cst$207$permalink);return wrike_ist.wrike.find_task(a).then(function(c){return wrike_ist.wrike.update_task_status(c,new cljs.core.PersistentArrayMap(null,2,[cljs$cst$211$wanted_status,b,cljs$cst$212$wanted_group,"Cancelled"],null))})};wrike_ist.core={};
wrike_ist.wrike.complete_task=function(a,b){a=cljs.core.__destructure_map(a);a=cljs.core.get.cljs$core$IFn$_invoke$arity$2(a,cljs$cst$207$permalink);return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2("-",b)?console.log('Skipping `merged` transition because it\'s set to "-"'):wrike_ist.wrike.find_task(a).then(function(c){return wrike_ist.wrike.update_task_status(c,new cljs.core.PersistentArrayMap(null,2,[cljs$cst$211$wanted_status,b,cljs$cst$212$wanted_group,"Completed"],null))})};
wrike_ist.wrike.cancel_task=function(a,b){a=cljs.core.__destructure_map(a);a=cljs.core.get.cljs$core$IFn$_invoke$arity$2(a,cljs$cst$207$permalink);return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2("-",b)?console.log('Skipping `closed` transition because it\'s set to "-"'):wrike_ist.wrike.find_task(a).then(function(c){return wrike_ist.wrike.update_task_status(c,new cljs.core.PersistentArrayMap(null,2,[cljs$cst$211$wanted_status,b,cljs$cst$212$wanted_group,"Cancelled"],null))})};wrike_ist.core={};
wrike_ist.core.extract_details=function(a){var b=a.body;return cljs.core.truth_(b)&&(b=cljs.core.re_find(/https:\/\/www.wrike.com\/open\.htm\?id=(\d+)/,b),cljs.core.truth_(b))?(b=cljs.core.nth.cljs$core$IFn$_invoke$arity$3(b,0,null),new cljs.core.PersistentArrayMap(null,4,[cljs$cst$214$state,a.merged?cljs$cst$215$merged:cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(a.state,"closed")?cljs$cst$216$closed:cljs$cst$217$open,cljs$cst$207$permalink,b,cljs$cst$205$pr_url,a.html_url,cljs$cst$206$title,a.title],
null)):null};
wrike_ist.core.main=function(){var a=shadow.js.shim.module$$actions$github.context.payload.pull_request;if(cljs.core.truth_(a)){a=wrike_ist.core.extract_details(a);if(cljs.core.truth_(a)){var b=cljs.core.__destructure_map(a),c=cljs.core.get.cljs$core$IFn$_invoke$arity$2(b,cljs$cst$214$state);return function(){switch(c instanceof cljs.core.Keyword?c.fqn:null){case "open":return wrike_ist.wrike.link_pr(b);case "merged":return wrike_ist.wrike.complete_task(b,shadow.js.shim.module$$actions$core.getInput("merged"));case "closed":return wrike_ist.wrike.cancel_task(b,
Expand Down
4 changes: 2 additions & 2 deletions resources/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions src/wrike_ist/wrike.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@

(defn complete-task
[{:keys [permalink]} wanted-status]
(.then
(find-task permalink)
#(update-task-status % {:wanted-status wanted-status
:wanted-group "Completed"})))
(if-not (= "-" wanted-status)
(.then
(find-task permalink)
#(update-task-status % {:wanted-status wanted-status
:wanted-group "Completed"}))
(js/console.log "Skipping `merged` transition because it's set to \"-\"")))

(defn cancel-task
[{:keys [permalink]} wanted-status]
(.then
(find-task permalink)
#(update-task-status % {:wanted-status wanted-status
:wanted-group "Cancelled"})))
(if-not (= "-" wanted-status)
(.then
(find-task permalink)
#(update-task-status % {:wanted-status wanted-status
:wanted-group "Cancelled"}))
(js/console.log "Skipping `closed` transition because it's set to \"-\"")))
14 changes: 12 additions & 2 deletions test/wrike_ist/wrike_test.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns wrike-ist.wrike-test
(:require [cljs.test :refer-macros [deftest is testing run-tests]]
[wrike-ist.wrike :refer [link-html]]))
(:require [cljs.test :refer-macros [deftest is testing]]
[wrike-ist.wrike :refer [cancel-task
complete-task
link-html]]))

(deftest link-html-test
(testing "No title"
Expand All @@ -13,3 +15,11 @@
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)))))))

(deftest cancel-task-test
(testing "Does nothing if `merged` is configured explicitly as \"-\""
(is (= nil (cancel-task {} "-")))))

(deftest complete-task-test
(testing "Does nothing if `merged` is configured explicitly as \"-\""
(is (= nil (complete-task {} "-")))))

0 comments on commit 5d7031b

Please sign in to comment.