Skip to content

Commit

Permalink
Add different message when a PR is merged or not (#26)
Browse files Browse the repository at this point in the history
* Move merged key to the correct position inside pull_request

* Have different message when a closed PR is merged or not

* Add missing file containing the get_pr_merged function
  • Loading branch information
Marc Navarro authored Oct 1, 2020
1 parent 1abfc75 commit 8269902
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ github::get_pr_title() {
jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH"
}

github::get_pr_merged() {
jq --raw-output .pull_request.merged "$GITHUB_EVENT_PATH"
}

github::get_sender_user() {
jq --raw-output .sender.login "$GITHUB_EVENT_PATH"
}
Expand Down
16 changes: 12 additions & 4 deletions src/teamwork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ teamwork::pull_request_closed() {
local -r user=$(github::get_sender_user)
local -r pr_url=$(github::get_pr_url)
local -r pr_title=$(github::get_pr_title)
local -r pr_merged=$(github::get_pr_merged)

teamwork::add_comment "
**$user** merged a PR: **$pr_title**
[$pr_url]($pr_url)
"
if [ "$pr_merged" == "true" ]; then
teamwork::add_comment "
**$user** merged a PR: **$pr_title**
[$pr_url]($pr_url)
"
else
teamwork::add_comment "
**$user** closed a PR without merging: **$pr_title**
[$pr_url]($pr_url)
"
fi
}

teamwork::pull_request_review_submitted() {
Expand Down
18 changes: 18 additions & 0 deletions tests/events/pull_request_closed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"action": "closed",
"number": 1,
"pull_request": {
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
"head": {
"repo": {
"full_name": "teamwork/github-sync"
}
},
"html_url": "https://github.com/teamwork/github-sync/pull/1",
"title": "This is an example of a title for the PR.",
"merged": false
},
"sender": {
"login": "username"
}
}
4 changes: 2 additions & 2 deletions tests/events/pull_request_merged.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"action": "closed",
"number": 1,
"merged": true,
"pull_request": {
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
"head": {
Expand All @@ -10,7 +9,8 @@
}
},
"html_url": "https://github.com/teamwork/github-sync/pull/1",
"title": "This is an example of a title for the PR."
"title": "This is an example of a title for the PR.",
"merged": true
},
"sender": {
"login": "username"
Expand Down

0 comments on commit 8269902

Please sign in to comment.