Skip to content

Commit 06e6254

Browse files
Marc Navarromiguelbemartin
Marc Navarro
andauthored
Add PR stats to open/closed pull request comment (#31)
* Add PR stats to open pull request comment * Add PR stats to close pull request comment * Fix linter errors * Update style comment * Update style comment * Update style comment Co-authored-by: Miguel Ángel Martín <miguelbemartin@gmail.com>
1 parent f4f87a7 commit 06e6254

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
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_patch_stats() {
32+
jq --raw-output '.pull_request | "\(.commits) \(.changed_files) \(.additions) \(.deletions)"' "$GITHUB_EVENT_PATH"
33+
}
34+
3135
github::get_pr_merged() {
3236
jq --raw-output .pull_request.merged "$GITHUB_EVENT_PATH"
3337
}

src/teamwork.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ teamwork::pull_request_opened() {
3636
local -r pr_url=$(github::get_pr_url)
3737
local -r pr_title=$(github::get_pr_title)
3838
local -r user=$(github::get_sender_user)
39+
local -r pr_stats=$(github::get_pr_patch_stats)
40+
IFS=" " read -r -a pr_stats_array <<< "$pr_stats"
3941

4042
teamwork::add_comment "
41-
**$user** opened a PR: **$pr_title**
42-
[$pr_url]($pr_url)
43+
**$user** opened a PR: **$pr_title**
44+
[$pr_url]($pr_url)
45+
46+
---
47+
48+
🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ${pr_stats_array[2]} additions / ${pr_stats_array[3]} deletions
4349
"
4450
}
4551

@@ -74,7 +80,9 @@ teamwork::pull_request_review_submitted() {
7480
teamwork::add_comment "
7581
**$user** submitted a review to the PR: **$pr_title**
7682
[$pr_url]($pr_url)
83+
7784
---
85+
7886
Review: **$review_state**
7987
$comment
8088
"

tests/events/pull_request_opened.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
}
1010
},
1111
"html_url": "https://github.com/teamwork/github-sync/pull/1",
12-
"title": "This is an example of a title for the PR."
12+
"title": "This is an example of a title for the PR.",
13+
"commits": 1,
14+
"additions": 2,
15+
"deletions": 3,
16+
"changed_files": 4
1317
},
1418
"sender": {
1519
"login": "username"

0 commit comments

Comments
 (0)