From 129d3e487459c90ac2b4189714c313dc3f3a4e20 Mon Sep 17 00:00:00 2001 From: yannig Date: Thu, 19 Nov 2020 14:06:16 +0000 Subject: [PATCH 1/3] Add the description when a PR is created as customer facing team don't have access to Github --- src/teamwork.sh | 4 +++- tests/events/pull_request_opened.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/teamwork.sh b/src/teamwork.sh index c0d1e4d4..fe37d698 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -37,12 +37,14 @@ teamwork::pull_request_opened() { local -r pr_title=$(github::get_pr_title) local -r user=$(github::get_sender_user) local -r pr_stats=$(github::get_pr_patch_stats) + local -r pr_body=$(github::get_pr_body) IFS=" " read -r -a pr_stats_array <<< "$pr_stats" teamwork::add_comment " **$user** opened a PR: **$pr_title** [$pr_url]($pr_url) - +--- + ${pr_body//###/####} --- 🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ${pr_stats_array[2]} additions / ${pr_stats_array[3]} deletions diff --git a/tests/events/pull_request_opened.json b/tests/events/pull_request_opened.json index 7931dbfb..bad041dd 100644 --- a/tests/events/pull_request_opened.json +++ b/tests/events/pull_request_opened.json @@ -2,7 +2,7 @@ "action": "opened", "number": 1, "pull_request": { - "body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456", + "body": "### Task\r\n- [Implement Smart Inbox Settings](https://digitalcrew.teamwork.com/#tasks/21419431)\r\n - Implement ``\r\n - Implement ``\r\n\r\n### Screencap\r\n#### ``\r\n![conditionsbuilder](https://user-images.githubusercontent.com/621330/52656284-abc69580-2efe-11e9-89af-9b0dab68c494.gif)\r\n\r\n#### ``\r\n- UI Explanation\r\n![conditionrow](https://user-images.githubusercontent.com/621330/52656775-bb92a980-2eff-11e9-8492-4b550b584a1e.png)\r\n- Blank State\r\n![blankconditionrow](https://user-images.githubusercontent.com/621330/52656835-e2e97680-2eff-11e9-994e-1ff426a6b7e9.png)\r\n- Empty State for not provided values\r\n - Tags\r\n ![notags](https://user-images.githubusercontent.com/621330/52656880-fa286400-2eff-11e9-8206-fee059f08356.png)\r\n - Companies\r\n ![nocompanies](https://user-images.githubusercontent.com/621330/52656897-04e2f900-2f00-11e9-82b4-88e7f58b05d7.png)\r\n- Validation Errors\r\n - Tags\r\n ![notselectedtagerror](https://user-images.githubusercontent.com/621330/52656942-2643e500-2f00-11e9-9d06-7ec813e35c2b.png)\r\n - Companies\r\n ![notselectedcompanyerror](https://user-images.githubusercontent.com/621330/52656955-2e038980-2f00-11e9-8ede-5738fb0fdd74.png)\r\n- Row Error (loading data error)\r\n![conditionrowunexpectederror](https://user-images.githubusercontent.com/621330/52656976-3b207880-2f00-11e9-9a9f-f01c3c417715.png)\r\n- All Possible Condition Rows\r\n![allpossibleconditions](https://user-images.githubusercontent.com/621330/52657021-5be8ce00-2f00-11e9-91e1-910730e4bef6.png)", "head": { "repo": { "full_name": "teamwork/github-sync" From b462376af95af7b0d05a3366dfa42141491eaf89 Mon Sep 17 00:00:00 2001 From: yannig Date: Thu, 19 Nov 2020 14:22:40 +0000 Subject: [PATCH 2/3] PR state now add a tag to the task: PR Open, PR Approved, PR Merged --- src/teamwork.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/teamwork.sh b/src/teamwork.sh index fe37d698..1aee9883 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -32,6 +32,38 @@ teamwork::add_comment() { log::message "$response" } +teamwork::add_tag() { + local -r tag_name=$1 + + if [ "$ENV" == "test" ]; then + log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Tag: ${tag_name//\"/}" + return + fi + + response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \ + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }" ) + + log::message "$response" +} + +teamwork::remove_tag() { + local -r tag_name=$1 + + if [ "$ENV" == "test" ]; then + log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Tag: ${tag_name//\"/}" + return + fi + + response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \ + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" ) + + log::message "$response" +} + teamwork::pull_request_opened() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) @@ -49,6 +81,8 @@ teamwork::pull_request_opened() { 🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ${pr_stats_array[2]} additions / ${pr_stats_array[3]} deletions " + + teamwork::add_tag "PR Open" } teamwork::pull_request_closed() { @@ -62,11 +96,14 @@ teamwork::pull_request_closed() { **$user** merged a PR: **$pr_title** [$pr_url]($pr_url) " + teamwork::add_tag "PR Merged" + teamwork::remove_tag "PR Open" else teamwork::add_comment " **$user** closed a PR without merging: **$pr_title** [$pr_url]($pr_url) " + teamwork::remove_tag "PR Open" fi } From 82335578971ea7201ef4b159ec623d9295558063 Mon Sep 17 00:00:00 2001 From: Yannick Chartois Date: Thu, 19 Nov 2020 18:22:16 +0000 Subject: [PATCH 3/3] Update README.md adding a bit of documentation --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 2b4b0ec7..fafe794d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,13 @@ Please note, the comment will be created in Teamwork under the account you have ![Teamwork pr comment](./.github/assets/teamwork_pr_comment.png) +Tags are added automatically on the task: +- A new PR is open: tag `PR Open` +- A PR is approved: tag `PR Approved` added +- A PR is merged: tags `PR Open` and `PR Approved` removed, tag `PR merged` added +- A PR is closed: tags `PR Open` and `PR Approved` removed + + ## Contributing * Open a PR: https://github.com/Teamwork/github-sync/pulls * Open an issue: https://github.com/Teamwork/github-sync/issues