Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 40 additions & 1 deletion src/teamwork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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//\"/}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is for testing, I would add to the message something like "Added tag".

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//\"/}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is for testing, I would add to the message something like "Removed tag".

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//###/####}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So replace all hading level 3 for level 4 headings isn't it?
Why? Just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's getting anything from 3, 4, 5 to 4,5..

I hope we are not using 2... And just because lvl 3 looks good in github, but way too big in Projects 😊

---

🔢 ${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() {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tests/events/pull_request_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<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)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public repository, we shouldn't be exposing our internal URLs. I would create a generic JSON just for testing purposes.

"head": {
"repo": {
"full_name": "teamwork/github-sync"
Expand Down