diff --git a/README.md b/README.md
index a86cf02e..d50ebd69 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

+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
diff --git a/src/teamwork.sh b/src/teamwork.sh
index c0d1e4d4..1aee9883 100644
--- a/src/teamwork.sh
+++ b/src/teamwork.sh
@@ -32,21 +32,57 @@ 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)
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
"
+
+ teamwork::add_tag "PR Open"
}
teamwork::pull_request_closed() {
@@ -60,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
}
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\r\n\r\n#### ``\r\n- UI Explanation\r\n\r\n- Blank State\r\n\r\n- Empty State for not provided values\r\n - Tags\r\n \r\n - Companies\r\n \r\n- Validation Errors\r\n - Tags\r\n \r\n - Companies\r\n \r\n- Row Error (loading data error)\r\n\r\n- All Possible Condition Rows\r\n",
"head": {
"repo": {
"full_name": "teamwork/github-sync"