diff --git a/src/main/kotlin/com/wire/github/response/model/PullRequest.kt b/src/main/kotlin/com/wire/github/response/model/PullRequest.kt index 036a4cf..2d97795 100644 --- a/src/main/kotlin/com/wire/github/response/model/PullRequest.kt +++ b/src/main/kotlin/com/wire/github/response/model/PullRequest.kt @@ -10,6 +10,9 @@ data class PullRequest( val title: String, val body: String? = null, val user: User, - val merged: Boolean? = false, - val number: Int + val number: Int, + val additions: Int = 0, + val deletions: Int = 0, + val draft: Boolean = false, + val merged: Boolean? = false ) diff --git a/src/main/kotlin/com/wire/github/response/model/Review.kt b/src/main/kotlin/com/wire/github/response/model/Review.kt index 255434a..4376be1 100644 --- a/src/main/kotlin/com/wire/github/response/model/Review.kt +++ b/src/main/kotlin/com/wire/github/response/model/Review.kt @@ -7,4 +7,8 @@ data class Review( val body: String? = null, val user: User, val state: String -) +) { + val approved: Boolean get() = state.equals("approved", ignoreCase = true) + val changesRequested: Boolean get() = state.equals("changes_requested", ignoreCase = true) + val commented: Boolean get() = state.equals("commented", ignoreCase = true) +} diff --git a/src/main/kotlin/com/wire/github/util/TemplateHandler.kt b/src/main/kotlin/com/wire/github/util/TemplateHandler.kt index dee78f9..8b75fc5 100644 --- a/src/main/kotlin/com/wire/github/util/TemplateHandler.kt +++ b/src/main/kotlin/com/wire/github/util/TemplateHandler.kt @@ -30,7 +30,7 @@ class TemplateHandler { populateTemplate( mustache = template, model = response - ) + )?.takeIf { it.isNotBlank() } } catch (exception: MustacheNotFoundException) { logger.error("MustacheNotFoundException: $exception") null diff --git a/src/main/resources/templates/en/commit_comment.created.template b/src/main/resources/templates/en/commit_comment.created.template index 1573964..6299079 100644 --- a/src/main/resources/templates/en/commit_comment.created.template +++ b/src/main/resources/templates/en/commit_comment.created.template @@ -1,7 +1,4 @@ -**[{{repository.fullName}}]** New comment on commit {{comment.id}} +{{! Fired on the "commit_comment" event (action=created): a comment left directly on a commit via GitHub's commit view. This is NOT a PR review comment and NOT an issue/PR conversation comment. }} +**@{{comment.user.login}}** [commented on a commit]({{comment.htmlUrl}}): -**Comment on line {{comment.line}} by {{comment.user.login}}** {{{comment.body}}} - -[comment]({{comment.htmlUrl}}) -— diff --git a/src/main/resources/templates/en/issue_comment.created.template b/src/main/resources/templates/en/issue_comment.created.template index 419547a..06030e4 100644 --- a/src/main/resources/templates/en/issue_comment.created.template +++ b/src/main/resources/templates/en/issue_comment.created.template @@ -1,6 +1,7 @@ -**[{{repository.fullName}}]** New comment by **{{sender.login}}** on issue **{{{issue.title}}}** +{{! Fired on the "issue_comment" event (action=created). }} +{{! This also fires for top-level comments on Pull Requests, because GitHub models a PR's conversation timeline as an issue. }} +{{! It does not fire for inline diff-line review comments — those are pull_request_review_comment events, which we intentionally do not notify on. }} +**{{{issue.title}}}** +**@{{comment.user.login}}** [commented]({{comment.htmlUrl}}): {{{comment.body}}} - -[comment]({{comment.htmlUrl}}) -— diff --git a/src/main/resources/templates/en/issues.closed.template b/src/main/resources/templates/en/issues.closed.template index b97d57d..f5f47eb 100644 --- a/src/main/resources/templates/en/issues.closed.template +++ b/src/main/resources/templates/en/issues.closed.template @@ -1,4 +1,3 @@ -**[{{repository.fullName}}]** Issue **{{{issue.title}}}** {{action}} by **{{sender.login}}** - -[issue]({{issue.htmlUrl}}) -— +{{! Fired on the "issues" event (action=closed): an issue — never a pull request — was closed. }} +{{! Closing or merging a PR comes through pull_request.closed instead. }} +[**{{{issue.title}}}**]({{issue.htmlUrl}}) {{action}} by **@{{sender.login}}** diff --git a/src/main/resources/templates/en/issues.opened.template b/src/main/resources/templates/en/issues.opened.template index 06a67dd..63ad527 100644 --- a/src/main/resources/templates/en/issues.opened.template +++ b/src/main/resources/templates/en/issues.opened.template @@ -1,6 +1,4 @@ -**[{{repository.fullName}}]** Issue **{{{issue.title}}}** {{action}} by **{{issue.user.login}}** +{{! Fired on the "issues" event (action=opened): a new issue (never a pull request) was created. }} +[**{{{issue.title}}}**]({{issue.htmlUrl}}) {{action}} by **@{{issue.user.login}}** {{{issue.body}}} - -[issue]({{issue.htmlUrl}}) -— diff --git a/src/main/resources/templates/en/issues.reopened.template b/src/main/resources/templates/en/issues.reopened.template index c1b041f..0b76f6c 100644 --- a/src/main/resources/templates/en/issues.reopened.template +++ b/src/main/resources/templates/en/issues.reopened.template @@ -1,6 +1,4 @@ -**[{{repository.fullName}}]** Issue **{{{issue.title}}}** {{action}} by **{{sender.login}}** +{{! Fired on the "issues" event (action=reopened): a previously closed issue (never a pull request) was reopened. }} +[**{{{issue.title}}}**]({{issue.htmlUrl}}) {{action}} by **@{{sender.login}}** {{{issue.body}}} - -{{issue.htmlUrl}} -— diff --git a/src/main/resources/templates/en/pull_request.closed.template b/src/main/resources/templates/en/pull_request.closed.template index c0219e6..d66da7c 100644 --- a/src/main/resources/templates/en/pull_request.closed.template +++ b/src/main/resources/templates/en/pull_request.closed.template @@ -1,10 +1,3 @@ -{{#pullRequest.merged}} -🚀 **Pull Request Merged!** by **{{ pullRequest.user.login }}** -{{/pullRequest.merged}} -{{^pullRequest.merged}} -❌ **Pull Request Closed!** by **{{ pullRequest.user.login }}** -{{/pullRequest.merged}} - -📦 **Repository:** {{repository.fullName}} -🔖 **Title:** {{pullRequest.title}} -🔗 **PR Link:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) +{{! Fired on the "pull_request" event (action=closed). }} +{{! GitHub uses action=closed for BOTH merged and merely-closed PRs, so this template branches on pullRequest.merged to tell them apart. }} +[**{{{pullRequest.title}}}**]({{pullRequest.htmlUrl}}): {{#pullRequest.merged}}🚀 **Merged**{{/pullRequest.merged}}{{^pullRequest.merged}}❌ **Closed**{{/pullRequest.merged}} by **@{{sender.login}}** diff --git a/src/main/resources/templates/en/pull_request.opened.template b/src/main/resources/templates/en/pull_request.opened.template index 58e1704..6b24a4b 100644 --- a/src/main/resources/templates/en/pull_request.opened.template +++ b/src/main/resources/templates/en/pull_request.opened.template @@ -1,5 +1,8 @@ -🟢 **New Pull Request Opened!** by **{{pullRequest.user.login}}** +{{! Fired on the "pull_request" event (action=opened): a PR was newly opened. }} +{{! Gated on NOT draft: a PR opened directly as a draft renders nothing and sends no notification. It is announced later by pull_request.ready_for_review.template when the draft is marked ready. }} +{{! The reopened action (action=reopened) has no template and is intentionally silent. }} +{{^pullRequest.draft}} +[**{{pullRequest.title}}**]({{pullRequest.htmlUrl}}) (+{{pullRequest.additions}}/-{{pullRequest.deletions}}) by **@{{pullRequest.user.login}}** -📦 **Repository:** {{repository.fullName}} -🔖 **Title:** {{pullRequest.title}} -🔗 **PR Link:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) +{{{pullRequest.body}}} +{{/pullRequest.draft}} diff --git a/src/main/resources/templates/en/pull_request.ready_for_review.template b/src/main/resources/templates/en/pull_request.ready_for_review.template new file mode 100644 index 0000000..00ceab4 --- /dev/null +++ b/src/main/resources/templates/en/pull_request.ready_for_review.template @@ -0,0 +1,5 @@ +{{! Fired on the "pull_request" event (action=ready_for_review): a draft PR was marked ready for review. }} +{{! Mirrors pull_request.opened so a PR that started as a draft is still announced once — at the moment it becomes ready, rather than when it was first opened as a draft. }} +[**{{pullRequest.title}}**]({{pullRequest.htmlUrl}}) (+{{pullRequest.additions}}/-{{pullRequest.deletions}}) by **@{{pullRequest.user.login}}** + +{{{pullRequest.body}}} diff --git a/src/main/resources/templates/en/pull_request_review.submitted.template b/src/main/resources/templates/en/pull_request_review.submitted.template index 522a398..7247e9c 100644 --- a/src/main/resources/templates/en/pull_request_review.submitted.template +++ b/src/main/resources/templates/en/pull_request_review.submitted.template @@ -1,6 +1,7 @@ -{{#review.body}}**[{{repository.fullName}}]** Pull request review **{{pullRequest.title}}** was {{action}} by **{{review.user.login}}** - +{{! Fired on the "pull_request_review" event: a reviewer finished a review via "Review changes". }} +{{! SURPRISE: a bare Approve carries no body, so only the prefix line renders. }} +{{! Any inline diff-line comments made in the same review arrive as separate pull_request_review_comment events, which we intentionally do not notify on. }} +[**{{{pullRequest.title}}}**]({{pullRequest.htmlUrl}}): {{#review.approved}}✅ **Approved** by {{/review.approved}}{{#review.changesRequested}}🔴 **Changes requested** by {{/review.changesRequested}} **@{{review.user.login}}** {{#review.commented}}Commented{{/review.commented}} +{{#review.body}} {{{review.body}}} - -[pull request]({{pullRequest.htmlUrl}}) -—{{/review.body}} +{{/review.body}} diff --git a/src/main/resources/templates/en/pull_request_review_comment.created.template b/src/main/resources/templates/en/pull_request_review_comment.created.template deleted file mode 100644 index 835bab4..0000000 --- a/src/main/resources/templates/en/pull_request_review_comment.created.template +++ /dev/null @@ -1,4 +0,0 @@ -**{{pullRequest.title}}** -**@{{comment.user.login}}** [commented]({{comment.htmlUrl}}): - -{{{comment.body}}} diff --git a/src/main/resources/templates/en/push.template b/src/main/resources/templates/en/push.template index 51b2108..18b37d0 100644 --- a/src/main/resources/templates/en/push.template +++ b/src/main/resources/templates/en/push.template @@ -1,9 +1,10 @@ +{{! Fired on the "push" event (no action segment): commits pushed to any branch or tag. }} +{{! Also fires for force-pushes and for branch/tag deletions. }} +{{! A deletion carries no commits, so the commits-empty guard below renders nothing for it. }} {{^commits.isEmpty}} -**[{{repository.fullName}}]** Push by **{{sender.login}}** +**@{{sender.login}}** [pushed]({{compare}}) to **{{repository.fullName}}**: {{#commits}} - - {{{message}}} +- {{{message}}} {{/commits}} - -[compare]({{compare}}) -—{{/commits.isEmpty}} +{{/commits.isEmpty}}