Skip to content

Commit

Permalink
Add PR stats to open/closed pull request comment (#31)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Marc Navarro and miguelbemartin authored Nov 8, 2020
1 parent f4f87a7 commit 06e6254
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
12 changes: 10 additions & 2 deletions src/teamwork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ 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)
IFS=" " read -r -a pr_stats_array <<< "$pr_stats"

teamwork::add_comment "
**$user** opened a PR: **$pr_title**
[$pr_url]($pr_url)
**$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]} additions / ${pr_stats_array[3]} deletions
"
}

Expand Down Expand Up @@ -74,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
"
Expand Down
6 changes: 5 additions & 1 deletion tests/events/pull_request_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 06e6254

Please sign in to comment.