Skip to content

Commit ce659ae

Browse files
authored
Merge pull request #42 from Teamwork/add_head_ref
2 parents 1961abf + e401855 commit ce659ae

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/github.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ github::get_pr_number() {
1313
}
1414

1515
github::get_pr_body() {
16-
jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH"
16+
jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" | sed -r 's/^#{1,3}\ /#### /g'
17+
}
18+
19+
github::get_head_ref() {
20+
jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH"
21+
}
22+
23+
github::get_base_ref() {
24+
jq --raw-output .pull_request.base.ref "$GITHUB_EVENT_PATH"
1725
}
1826

1927
github::get_repository_full_name() {

src/teamwork.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ teamwork::remove_tag() {
7171
teamwork::pull_request_opened() {
7272
local -r pr_url=$(github::get_pr_url)
7373
local -r pr_title=$(github::get_pr_title)
74+
local -r head_ref=$(github::get_head_ref)
75+
local -r base_ref=$(github::get_base_ref)
7476
local -r user=$(github::get_sender_user)
7577
local -r pr_stats=$(github::get_pr_patch_stats)
7678
local -r pr_body=$(github::get_pr_body)
@@ -79,14 +81,16 @@ teamwork::pull_request_opened() {
7981
teamwork::add_comment "
8082
**$user** opened a PR: **$pr_title**
8183
[$pr_url]($pr_url)
84+
\`$base_ref\` <- \`$head_ref\`
8285
8386
---
8487
85-
${pr_body//###/####}
88+
${pr_body}
8689
8790
---
8891
8992
🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ➕ ${pr_stats_array[2]} additions / ➖ ${pr_stats_array[3]} deletions
93+
9094
"
9195

9296
teamwork::add_tag "PR Open"

tests/events/pull_request_opened.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
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": "# Test heading \n This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
66
"head": {
7+
"ref": "pr-branch",
78
"repo": {
89
"full_name": "teamwork/github-sync"
910
}
1011
},
12+
"base": {
13+
"ref": "main"
14+
},
1115
"html_url": "https://github.com/teamwork/github-sync/pull/1",
1216
"title": "This is an example of a title for the PR.",
1317
"commits": 1,
@@ -18,4 +22,4 @@
1822
"sender": {
1923
"login": "username"
2024
}
21-
}
25+
}

0 commit comments

Comments
 (0)