From 86aca88aad57b3441fd84ad0039cf16718799ea0 Mon Sep 17 00:00:00 2001 From: Marc Navarro Date: Fri, 30 Oct 2020 17:40:42 +0100 Subject: [PATCH 1/6] Add PR stats to open pull request comment --- src/github.sh | 4 ++++ src/teamwork.sh | 4 ++++ tests/events/pull_request_opened.json | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/github.sh b/src/github.sh index 84266a09..d806c865 100644 --- a/src/github.sh +++ b/src/github.sh @@ -28,6 +28,10 @@ github::get_pr_title() { jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH" } +github::get_pr_patch_stats() { + jq --raw-output '.pull_request | "\(.commits) \(.changed_files) \(.additions) \(.deletions)"' "$GITHUB_EVENT_PATH" +} + github::get_pr_merged() { jq --raw-output .pull_request.merged "$GITHUB_EVENT_PATH" } diff --git a/src/teamwork.sh b/src/teamwork.sh index fc0a238d..556b4501 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -36,10 +36,14 @@ teamwork::pull_request_opened() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) local -r user=$(github::get_sender_user) + local -r pr_stats=$(github::get_pr_patch_stats) + local -r pr_stats_array=($pr_stats) teamwork::add_comment " **$user** opened a PR: **$pr_title** [$pr_url]($pr_url) + --- + Stats: ${$pr_stats_array[0]} commits, ${$pr_stats_array[1]} files changed, +${$pr_stats_array[2]}, -${$pr_stats_array[3]} " } diff --git a/tests/events/pull_request_opened.json b/tests/events/pull_request_opened.json index 2f5b8423..7931dbfb 100644 --- a/tests/events/pull_request_opened.json +++ b/tests/events/pull_request_opened.json @@ -9,7 +9,11 @@ } }, "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.", + "commits": 1, + "additions": 2, + "deletions": 3, + "changed_files": 4 }, "sender": { "login": "username" From d0205a1148c0cbf7afa3eb1e40aa2df6dfdda821 Mon Sep 17 00:00:00 2001 From: Marc Navarro Date: Fri, 30 Oct 2020 17:43:24 +0100 Subject: [PATCH 2/6] Add PR stats to close pull request comment --- src/teamwork.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/teamwork.sh b/src/teamwork.sh index 556b4501..ebe18b99 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -52,11 +52,15 @@ teamwork::pull_request_closed() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) local -r pr_merged=$(github::get_pr_merged) + local -r pr_stats=$(github::get_pr_patch_stats) + local -r pr_stats_array=($pr_stats) if [ "$pr_merged" == "true" ]; then teamwork::add_comment " **$user** merged a PR: **$pr_title** [$pr_url]($pr_url) +--- + Stats: ${$pr_stats_array[0]} commits, ${$pr_stats_array[1]} files changed, +${$pr_stats_array[2]}, -${$pr_stats_array[3]} " else teamwork::add_comment " From 54e74cee18c0c03250bcc760991a0fb0bae20dea Mon Sep 17 00:00:00 2001 From: Marc Navarro Date: Fri, 30 Oct 2020 17:49:20 +0100 Subject: [PATCH 3/6] Fix linter errors --- src/teamwork.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/teamwork.sh b/src/teamwork.sh index ebe18b99..2bb57290 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -37,13 +37,13 @@ teamwork::pull_request_opened() { local -r pr_title=$(github::get_pr_title) local -r user=$(github::get_sender_user) local -r pr_stats=$(github::get_pr_patch_stats) - local -r pr_stats_array=($pr_stats) + IFS=" " read -r -a pr_stats_array <<< "$pr_stats" teamwork::add_comment " **$user** opened a PR: **$pr_title** [$pr_url]($pr_url) --- - Stats: ${$pr_stats_array[0]} commits, ${$pr_stats_array[1]} files changed, +${$pr_stats_array[2]}, -${$pr_stats_array[3]} + Stats: ${pr_stats_array[0]} commits, ${pr_stats_array[1]} files changed, +${pr_stats_array[2]}, -${pr_stats_array[3]} " } @@ -53,14 +53,14 @@ teamwork::pull_request_closed() { local -r pr_title=$(github::get_pr_title) local -r pr_merged=$(github::get_pr_merged) local -r pr_stats=$(github::get_pr_patch_stats) - local -r pr_stats_array=($pr_stats) + IFS=" " read -r -a pr_stats_array <<< "$pr_stats" if [ "$pr_merged" == "true" ]; then teamwork::add_comment " **$user** merged a PR: **$pr_title** [$pr_url]($pr_url) --- - Stats: ${$pr_stats_array[0]} commits, ${$pr_stats_array[1]} files changed, +${$pr_stats_array[2]}, -${$pr_stats_array[3]} + Stats: ${pr_stats_array[0]} commits, ${pr_stats_array[1]} files changed, +${pr_stats_array[2]}, -${pr_stats_array[3]} " else teamwork::add_comment " From bf94b6a96476bc8d797b96e7f947463360fd0983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel=20Marti=CC=81n?= Date: Sun, 8 Nov 2020 17:43:09 +0100 Subject: [PATCH 4/6] Update style comment --- src/teamwork.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/teamwork.sh b/src/teamwork.sh index 2bb57290..0cedf85b 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -40,10 +40,10 @@ teamwork::pull_request_opened() { IFS=" " read -r -a pr_stats_array <<< "$pr_stats" teamwork::add_comment " - **$user** opened a PR: **$pr_title** - [$pr_url]($pr_url) - --- - Stats: ${pr_stats_array[0]} commits, ${pr_stats_array[1]} files changed, +${pr_stats_array[2]}, -${pr_stats_array[3]} +**$user** opened a PR: **$pr_title** +[$pr_url]($pr_url) +--- +🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ✚ ${pr_stats_array[2]} lines & − ${pr_stats_array[3]} lines " } @@ -52,15 +52,11 @@ teamwork::pull_request_closed() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) local -r pr_merged=$(github::get_pr_merged) - local -r pr_stats=$(github::get_pr_patch_stats) - IFS=" " read -r -a pr_stats_array <<< "$pr_stats" if [ "$pr_merged" == "true" ]; then teamwork::add_comment " **$user** merged a PR: **$pr_title** [$pr_url]($pr_url) ---- - Stats: ${pr_stats_array[0]} commits, ${pr_stats_array[1]} files changed, +${pr_stats_array[2]}, -${pr_stats_array[3]} " else teamwork::add_comment " From 85042eb72c284d430878164703880ba2ce312fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel=20Marti=CC=81n?= Date: Sun, 8 Nov 2020 17:47:41 +0100 Subject: [PATCH 5/6] Update style comment --- src/teamwork.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/teamwork.sh b/src/teamwork.sh index 0cedf85b..ce756adb 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -42,8 +42,10 @@ teamwork::pull_request_opened() { teamwork::add_comment " **$user** opened a PR: **$pr_title** [$pr_url]($pr_url) + --- -🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ✚ ${pr_stats_array[2]} lines & − ${pr_stats_array[3]} lines + +🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ✚ ${pr_stats_array[2]} additions & − ${pr_stats_array[3]} deletions " } @@ -78,7 +80,9 @@ teamwork::pull_request_review_submitted() { teamwork::add_comment " **$user** submitted a review to the PR: **$pr_title** [$pr_url]($pr_url) + --- + Review: **$review_state** $comment " From 28f0d176b8205da679d821c50cbefda4cceed039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=CC=81ngel=20Marti=CC=81n?= Date: Sun, 8 Nov 2020 17:49:35 +0100 Subject: [PATCH 6/6] Update style comment --- src/teamwork.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/teamwork.sh b/src/teamwork.sh index ce756adb..c0d1e4d4 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -45,7 +45,7 @@ teamwork::pull_request_opened() { --- -🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ✚ ${pr_stats_array[2]} additions & − ${pr_stats_array[3]} deletions +🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ${pr_stats_array[2]} additions / ${pr_stats_array[3]} deletions " }