From 9c367a12777a77f7faa96a820076df70adfbcd1f Mon Sep 17 00:00:00 2001 From: Sean O'Grady Date: Thu, 22 Jul 2021 00:50:56 +0100 Subject: [PATCH 1/6] Add head & base ref, limit markdown headings --- src/github.sh | 10 +++++++++- src/teamwork.sh | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/github.sh b/src/github.sh index d806c865..93512621 100644 --- a/src/github.sh +++ b/src/github.sh @@ -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}/####/' +} + +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() { diff --git a/src/teamwork.sh b/src/teamwork.sh index f1eec798..45fafd51 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -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) @@ -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" From 094856254342422053ef990612d3ee3d76fc20e7 Mon Sep 17 00:00:00 2001 From: Sean O'Grady Date: Thu, 22 Jul 2021 00:54:54 +0100 Subject: [PATCH 2/6] linting --- src/teamwork.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/teamwork.sh b/src/teamwork.sh index 45fafd51..586f9cc6 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -81,7 +81,7 @@ teamwork::pull_request_opened() { teamwork::add_comment " **$user** opened a PR: **$pr_title** [$pr_url]($pr_url) -`$base_ref` <- `$head_ref` +\`$base_ref\` <- \`$head_ref\` --- From 90458980e601a744332eb8f67da3e83add406d52 Mon Sep 17 00:00:00 2001 From: Sean O'Grady Date: Thu, 22 Jul 2021 00:56:02 +0100 Subject: [PATCH 3/6] add to tests --- tests/events/pull_request_opened.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/events/pull_request_opened.json b/tests/events/pull_request_opened.json index 7931dbfb..91404e16 100644 --- a/tests/events/pull_request_opened.json +++ b/tests/events/pull_request_opened.json @@ -4,10 +4,14 @@ "pull_request": { "body": "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, @@ -18,4 +22,4 @@ "sender": { "login": "username" } -} \ No newline at end of file +} From 5ed9cb942e9341a4ce3ef21e57d7b71062b08186 Mon Sep 17 00:00:00 2001 From: Sean O'Grady Date: Thu, 22 Jul 2021 01:13:57 +0100 Subject: [PATCH 4/6] tweak regex --- src/github.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github.sh b/src/github.sh index 93512621..86a274c2 100644 --- a/src/github.sh +++ b/src/github.sh @@ -13,7 +13,7 @@ github::get_pr_number() { } github::get_pr_body() { - jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" | sed -r 's/#{1,3}/####/' + jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" | sed -r 's/^#{1,3}\ /#### /' } github::get_head_ref() { From 92ef0f37440a77ca98a30f5e5d8f1af344dd9160 Mon Sep 17 00:00:00 2001 From: Sean O'Grady Date: Thu, 22 Jul 2021 01:17:52 +0100 Subject: [PATCH 5/6] run global --- src/github.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github.sh b/src/github.sh index 86a274c2..726b906b 100644 --- a/src/github.sh +++ b/src/github.sh @@ -13,7 +13,7 @@ github::get_pr_number() { } github::get_pr_body() { - jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" | sed -r 's/^#{1,3}\ /#### /' + jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" | sed -r 's/^#{1,3}\ /#### /g' } github::get_head_ref() { From e401855ffdba6b3fb0318157676d6e7a142ac032 Mon Sep 17 00:00:00 2001 From: Sean O'Grady Date: Thu, 22 Jul 2021 12:43:01 +0100 Subject: [PATCH 6/6] add heading to body --- tests/events/pull_request_opened.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/events/pull_request_opened.json b/tests/events/pull_request_opened.json index 91404e16..88e64a11 100644 --- a/tests/events/pull_request_opened.json +++ b/tests/events/pull_request_opened.json @@ -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": "# 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": {