Skip to content

Commit 19a8da4

Browse files
authored
Merge pull request #33 from Teamwork/yannig-hackathon
Yannig hackathon
2 parents 13d74e1 + f375178 commit 19a8da4

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ Please note, the comment will be created in Teamwork under the account you have
5959

6060
![Teamwork pr comment](./.github/assets/teamwork_pr_comment.png)
6161

62+
Tags are added automatically on the task:
63+
- A new PR is open: tag `PR Open`
64+
- A PR is approved: tag `PR Approved` added
65+
- A PR is merged: tags `PR Open` and `PR Approved` removed, tag `PR merged` added
66+
- A PR is closed: tags `PR Open` and `PR Approved` removed
67+
68+
6269
## Contributing
6370
* Open a PR: https://github.com/Teamwork/github-sync/pulls
6471
* Open an issue: https://github.com/Teamwork/github-sync/issues

src/teamwork.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,57 @@ teamwork::add_comment() {
3232
log::message "$response"
3333
}
3434

35+
teamwork::add_tag() {
36+
local -r tag_name=$1
37+
38+
if [ "$ENV" == "test" ]; then
39+
log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Tag: ${tag_name//\"/}"
40+
return
41+
fi
42+
43+
response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \
44+
-u "$TEAMWORK_API_TOKEN"':' \
45+
-H 'Content-Type: application/json; charset=utf-8' \
46+
-d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }" )
47+
48+
log::message "$response"
49+
}
50+
51+
teamwork::remove_tag() {
52+
local -r tag_name=$1
53+
54+
if [ "$ENV" == "test" ]; then
55+
log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Tag: ${tag_name//\"/}"
56+
return
57+
fi
58+
59+
response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \
60+
-u "$TEAMWORK_API_TOKEN"':' \
61+
-H 'Content-Type: application/json; charset=utf-8' \
62+
-d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" )
63+
64+
log::message "$response"
65+
}
66+
3567
teamwork::pull_request_opened() {
3668
local -r pr_url=$(github::get_pr_url)
3769
local -r pr_title=$(github::get_pr_title)
3870
local -r user=$(github::get_sender_user)
3971
local -r pr_stats=$(github::get_pr_patch_stats)
72+
local -r pr_body=$(github::get_pr_body)
4073
IFS=" " read -r -a pr_stats_array <<< "$pr_stats"
4174

4275
teamwork::add_comment "
4376
**$user** opened a PR: **$pr_title**
4477
[$pr_url]($pr_url)
45-
78+
---
79+
${pr_body//###/####}
4680
---
4781
4882
🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ${pr_stats_array[2]} additions / ${pr_stats_array[3]} deletions
4983
"
84+
85+
teamwork::add_tag "PR Open"
5086
}
5187

5288
teamwork::pull_request_closed() {
@@ -60,11 +96,14 @@ teamwork::pull_request_closed() {
6096
**$user** merged a PR: **$pr_title**
6197
[$pr_url]($pr_url)
6298
"
99+
teamwork::add_tag "PR Merged"
100+
teamwork::remove_tag "PR Open"
63101
else
64102
teamwork::add_comment "
65103
**$user** closed a PR without merging: **$pr_title**
66104
[$pr_url]($pr_url)
67105
"
106+
teamwork::remove_tag "PR Open"
68107
fi
69108
}
70109

tests/events/pull_request_opened.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"action": "opened",
33
"number": 1,
44
"pull_request": {
5-
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
5+
"body": "### Task\r\n- [Implement Smart Inbox Settings](https://digitalcrew.teamwork.com/#tasks/21419431)\r\n - Implement `<ConditionsBuilder/>`\r\n - Implement `<ConditonRow/>`\r\n\r\n### Screencap\r\n#### `<ConditionsBuilder/>`\r\n![conditionsbuilder](https://user-images.githubusercontent.com/621330/52656284-abc69580-2efe-11e9-89af-9b0dab68c494.gif)\r\n\r\n#### `<ConditonRow/>`\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)",
66
"head": {
77
"repo": {
88
"full_name": "teamwork/github-sync"

0 commit comments

Comments
 (0)