Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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