Skip to content

Commit 8269902

Browse files
author
Marc Navarro
authored
Add different message when a PR is merged or not (#26)
* 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
1 parent 1abfc75 commit 8269902

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

src/github.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ github::get_pr_title() {
2828
jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH"
2929
}
3030

31+
github::get_pr_merged() {
32+
jq --raw-output .pull_request.merged "$GITHUB_EVENT_PATH"
33+
}
34+
3135
github::get_sender_user() {
3236
jq --raw-output .sender.login "$GITHUB_EVENT_PATH"
3337
}

src/teamwork.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,19 @@ teamwork::pull_request_closed() {
4747
local -r user=$(github::get_sender_user)
4848
local -r pr_url=$(github::get_pr_url)
4949
local -r pr_title=$(github::get_pr_title)
50+
local -r pr_merged=$(github::get_pr_merged)
5051

51-
teamwork::add_comment "
52-
**$user** merged a PR: **$pr_title**
53-
[$pr_url]($pr_url)
54-
"
52+
if [ "$pr_merged" == "true" ]; then
53+
teamwork::add_comment "
54+
**$user** merged a PR: **$pr_title**
55+
[$pr_url]($pr_url)
56+
"
57+
else
58+
teamwork::add_comment "
59+
**$user** closed a PR without merging: **$pr_title**
60+
[$pr_url]($pr_url)
61+
"
62+
fi
5563
}
5664

5765
teamwork::pull_request_review_submitted() {

tests/events/pull_request_closed.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"action": "closed",
3+
"number": 1,
4+
"pull_request": {
5+
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
6+
"head": {
7+
"repo": {
8+
"full_name": "teamwork/github-sync"
9+
}
10+
},
11+
"html_url": "https://github.com/teamwork/github-sync/pull/1",
12+
"title": "This is an example of a title for the PR.",
13+
"merged": false
14+
},
15+
"sender": {
16+
"login": "username"
17+
}
18+
}

tests/events/pull_request_merged.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"action": "closed",
33
"number": 1,
4-
"merged": true,
54
"pull_request": {
65
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
76
"head": {
@@ -10,7 +9,8 @@
109
}
1110
},
1211
"html_url": "https://github.com/teamwork/github-sync/pull/1",
13-
"title": "This is an example of a title for the PR."
12+
"title": "This is an example of a title for the PR.",
13+
"merged": true
1414
},
1515
"sender": {
1616
"login": "username"

0 commit comments

Comments
 (0)