Skip to content

Commit

Permalink
Merge pull request #42 from Teamwork/add_head_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
seanogdev authored Jul 22, 2021
2 parents 1961abf + e401855 commit ce659ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ github::get_pr_number() {
}

github::get_pr_body() {
jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH"
jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" | sed -r 's/^#{1,3}\ /#### /g'
}

github::get_head_ref() {
jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH"
}

github::get_base_ref() {
jq --raw-output .pull_request.base.ref "$GITHUB_EVENT_PATH"
}

github::get_repository_full_name() {
Expand Down
6 changes: 5 additions & 1 deletion src/teamwork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ teamwork::remove_tag() {
teamwork::pull_request_opened() {
local -r pr_url=$(github::get_pr_url)
local -r pr_title=$(github::get_pr_title)
local -r head_ref=$(github::get_head_ref)
local -r base_ref=$(github::get_base_ref)
local -r user=$(github::get_sender_user)
local -r pr_stats=$(github::get_pr_patch_stats)
local -r pr_body=$(github::get_pr_body)
Expand All @@ -79,14 +81,16 @@ teamwork::pull_request_opened() {
teamwork::add_comment "
**$user** opened a PR: **$pr_title**
[$pr_url]($pr_url)
\`$base_ref\` <- \`$head_ref\`
---
${pr_body//###/####}
${pr_body}
---
🔢 ${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"
Expand Down
8 changes: 6 additions & 2 deletions tests/events/pull_request_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"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": "# Test heading \n This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
"head": {
"ref": "pr-branch",
"repo": {
"full_name": "teamwork/github-sync"
}
},
"base": {
"ref": "main"
},
"html_url": "https://github.com/teamwork/github-sync/pull/1",
"title": "This is an example of a title for the PR.",
"commits": 1,
Expand All @@ -18,4 +22,4 @@
"sender": {
"login": "username"
}
}
}

0 comments on commit ce659ae

Please sign in to comment.