From db9fdf8868279711c408876b2e3097edeaf00534 Mon Sep 17 00:00:00 2001 From: Luca Rospocher Date: Wed, 26 Aug 2026 14:51:19 +0200 Subject: [PATCH 1/6] fix: Fix 2 template properties deserialization WPB-28090 - Add 2 new templates for PR ready for review and reopened --- docker-compose.yml | 6 +----- helm/githubapp/templates/NOTES.txt | 6 ------ src/main/kotlin/com/wire/github/Routing.kt | 2 +- .../kotlin/com/wire/github/response/model/PullRequest.kt | 2 +- src/main/kotlin/com/wire/github/response/model/Review.kt | 4 ++-- src/main/kotlin/com/wire/github/util/TemplateHandler.kt | 3 ++- .../templates/en/pull_request.ready_for_review.template | 3 +++ .../resources/templates/en/pull_request.reopened.template | 3 +++ 8 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/templates/en/pull_request.ready_for_review.template create mode 100644 src/main/resources/templates/en/pull_request.reopened.template diff --git a/docker-compose.yml b/docker-compose.yml index 575d591..9b58b0f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,12 +13,8 @@ services: - WIRE_SDK_API_TOKEN=${WIRE_SDK_API_TOKEN} - WIRE_SDK_APP_ID=${WIRE_SDK_APP_ID} - WIRE_SDK_CRYPTOGRAPHY_STORAGE_PASSWORD=${WIRE_SDK_CRYPTOGRAPHY_STORAGE_PASSWORD} - - WIRE_SDK_USER_ID=${WIRE_SDK_USER_ID} - - WIRE_SDK_EMAIL=${WIRE_SDK_EMAIL} - - WIRE_SDK_PASSWORD=${WIRE_SDK_PASSWORD} - - WIRE_SDK_ENVIRONMENT=${WIRE_SDK_ENVIRONMENT} ports: - - "${GHAPP_SERVER_PORT}:${GHAPP_SERVER_PORT}" + - "${GHAPP_SERVER_PORT:-8083}:${GHAPP_SERVER_PORT:-8083}" volumes: - github-app:/app depends_on: diff --git a/helm/githubapp/templates/NOTES.txt b/helm/githubapp/templates/NOTES.txt index d0d8a69..fbd553b 100644 --- a/helm/githubapp/templates/NOTES.txt +++ b/helm/githubapp/templates/NOTES.txt @@ -37,12 +37,6 @@ MONITORING & DEBUGGING: CONFIGURATION: {{- range .Values.env }} -{{- if eq .name "WIRE_SDK_ENVIRONMENT" }} -- Wire SDK Environment: {{ .value | default "Not configured" }} -{{- end }} -{{- if eq .name "WIRE_ENV" }} -- Wire Environment: {{ .value | default "Not configured" }} -{{- end }} {{- if eq .name "PORT" }} - Application Port: {{ .value | default "8080" }} {{- end }} diff --git a/src/main/kotlin/com/wire/github/Routing.kt b/src/main/kotlin/com/wire/github/Routing.kt index 55fa189..709a73c 100644 --- a/src/main/kotlin/com/wire/github/Routing.kt +++ b/src/main/kotlin/com/wire/github/Routing.kt @@ -37,7 +37,7 @@ fun Application.configureRouting() { routing { trace { - application.log.info(it.buildText()) + application.log.debug(it.buildText()) } get("/health") { 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 acb5278..d7c40f8 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,6 @@ data class PullRequest( val title: String, val body: String, val user: User, - val merged: Boolean, + val merged: Boolean? = null, val number: Int ) 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 b46bb5a..785096e 100644 --- a/src/main/kotlin/com/wire/github/response/model/Review.kt +++ b/src/main/kotlin/com/wire/github/response/model/Review.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable @Serializable data class Review( - val body: String, - val user: User, + val body: String? = null, + val user: User? = null, val state: String ) diff --git a/src/main/kotlin/com/wire/github/util/TemplateHandler.kt b/src/main/kotlin/com/wire/github/util/TemplateHandler.kt index 2b63bcd..abb4919 100644 --- a/src/main/kotlin/com/wire/github/util/TemplateHandler.kt +++ b/src/main/kotlin/com/wire/github/util/TemplateHandler.kt @@ -22,13 +22,14 @@ class TemplateHandler { event = event, action = response.action ) + logger.info("Template found for this action: ${template.name}") populateTemplate( mustache = template, model = response ) } catch (exception: MustacheNotFoundException) { - logger.error("MustacheNotFoundException: $exception") + logger.info("MustacheNotFoundException: $exception") null } 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..bf93503 --- /dev/null +++ b/src/main/resources/templates/en/pull_request.ready_for_review.template @@ -0,0 +1,3 @@ +🟢 **New Pull Request Ready for Review!** by **{{pullRequest.user.login}}** +**Repository:** {{repository.fullName}} +**PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} diff --git a/src/main/resources/templates/en/pull_request.reopened.template b/src/main/resources/templates/en/pull_request.reopened.template new file mode 100644 index 0000000..75e019b --- /dev/null +++ b/src/main/resources/templates/en/pull_request.reopened.template @@ -0,0 +1,3 @@ +🟢 **New Pull Request Reopened!** by **{{pullRequest.user.login}}** +**Repository:** {{repository.fullName}} +**PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} From edd35ca0a01c0bf22e71f16182e58f3769c2d7d1 Mon Sep 17 00:00:00 2001 From: Luca Rospocher Date: Wed, 26 Aug 2026 16:44:56 +0200 Subject: [PATCH 2/6] Switch to sender.login - Claude comments, making all the body fields nullable in all objects --- .github/workflows/staging.yml | 2 +- src/main/kotlin/com/wire/github/Routing.kt | 8 +++++++- src/main/kotlin/com/wire/github/response/model/Comment.kt | 2 +- src/main/kotlin/com/wire/github/response/model/Issue.kt | 2 +- .../kotlin/com/wire/github/response/model/PullRequest.kt | 2 +- .../templates/en/pull_request.ready_for_review.template | 2 +- .../resources/templates/en/pull_request.reopened.template | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index fb1fb70..bafc8f9 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -1,4 +1,4 @@ -name: Build +name: Staging on: workflow_dispatch: diff --git a/src/main/kotlin/com/wire/github/Routing.kt b/src/main/kotlin/com/wire/github/Routing.kt index 709a73c..efa1a57 100644 --- a/src/main/kotlin/com/wire/github/Routing.kt +++ b/src/main/kotlin/com/wire/github/Routing.kt @@ -22,6 +22,7 @@ import io.ktor.server.routing.post import io.ktor.server.routing.routing import java.util.UUID import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.SerializationException import org.koin.core.context.GlobalContext @Suppress("LongMethod") @@ -84,7 +85,12 @@ fun Application.configureRouting() { ) } - val response = KtxSerializer.json.decodeFromString(payload) + val response = try { + KtxSerializer.json.decodeFromString(payload) + } catch (exception: SerializationException) { + application.log.error("Failed to deserialize $event delivery $delivery", exception) + return@post call.response.status(HttpStatusCode.BadRequest) + } // Handle event response and send message val messageTemplate = templateHandler.handleEvent( diff --git a/src/main/kotlin/com/wire/github/response/model/Comment.kt b/src/main/kotlin/com/wire/github/response/model/Comment.kt index 19e1143..6a89097 100644 --- a/src/main/kotlin/com/wire/github/response/model/Comment.kt +++ b/src/main/kotlin/com/wire/github/response/model/Comment.kt @@ -5,7 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class Comment( - val body: String, + val body: String? = null, val user: User, @SerialName("html_url") val htmlUrl: String, diff --git a/src/main/kotlin/com/wire/github/response/model/Issue.kt b/src/main/kotlin/com/wire/github/response/model/Issue.kt index 3697877..188043e 100644 --- a/src/main/kotlin/com/wire/github/response/model/Issue.kt +++ b/src/main/kotlin/com/wire/github/response/model/Issue.kt @@ -8,7 +8,7 @@ data class Issue( @SerialName("html_url") val htmlUrl: String, val title: String, - val body: String, + val body: String? = null, val user: User, val number: Int ) 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 d7c40f8..b84152b 100644 --- a/src/main/kotlin/com/wire/github/response/model/PullRequest.kt +++ b/src/main/kotlin/com/wire/github/response/model/PullRequest.kt @@ -8,7 +8,7 @@ data class PullRequest( @SerialName("html_url") val htmlUrl: String, val title: String, - val body: String, + val body: String? = null, val user: User, val merged: Boolean? = null, val number: Int 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 index bf93503..cf776a7 100644 --- a/src/main/resources/templates/en/pull_request.ready_for_review.template +++ b/src/main/resources/templates/en/pull_request.ready_for_review.template @@ -1,3 +1,3 @@ -🟢 **New Pull Request Ready for Review!** by **{{pullRequest.user.login}}** +🟢 **New Pull Request Ready for Review!** by **{{sender.login}}** **Repository:** {{repository.fullName}} **PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} diff --git a/src/main/resources/templates/en/pull_request.reopened.template b/src/main/resources/templates/en/pull_request.reopened.template index 75e019b..ddb003a 100644 --- a/src/main/resources/templates/en/pull_request.reopened.template +++ b/src/main/resources/templates/en/pull_request.reopened.template @@ -1,3 +1,3 @@ -🟢 **New Pull Request Reopened!** by **{{pullRequest.user.login}}** +🟢 **New Pull Request Reopened!** by **{{sender.login}}** **Repository:** {{repository.fullName}} **PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} From 8ea39c20de4efd09da6a16d023a03813c40bee66 Mon Sep 17 00:00:00 2001 From: Luca Rospocher Date: Wed, 26 Aug 2026 17:53:46 +0200 Subject: [PATCH 3/6] Use the same format for all templates --- .../templates/en/commit_comment.created.template | 7 ------- .../templates/en/issue_comment.created.template | 10 ++++------ .../en/pull_request_review.submitted.template | 10 ++++------ .../en/pull_request_review_comment.created.template | 11 +++++------ src/main/resources/templates/en/push.template | 5 ++--- 5 files changed, 15 insertions(+), 28 deletions(-) delete mode 100644 src/main/resources/templates/en/commit_comment.created.template diff --git a/src/main/resources/templates/en/commit_comment.created.template b/src/main/resources/templates/en/commit_comment.created.template deleted file mode 100644 index 1573964..0000000 --- a/src/main/resources/templates/en/commit_comment.created.template +++ /dev/null @@ -1,7 +0,0 @@ -**[{{repository.fullName}}]** New comment on commit {{comment.id}} - -**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..ad79fc4 100644 --- a/src/main/resources/templates/en/issue_comment.created.template +++ b/src/main/resources/templates/en/issue_comment.created.template @@ -1,6 +1,4 @@ -**[{{repository.fullName}}]** New comment by **{{sender.login}}** on issue **{{{issue.title}}}** - -{{{comment.body}}} - -[comment]({{comment.htmlUrl}}) -— +📝 **New comment** on issue/PR **{{{issue.title}}}** by **{{sender.login}}** +**Text:** {{{comment.body}}} +**Repository:** {{repository.fullName}} +**Comment:** [link]({{comment.htmlUrl}}) 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..5d56bac 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,4 @@ -{{#review.body}}**[{{repository.fullName}}]** Pull request review **{{pullRequest.title}}** was {{action}} by **{{review.user.login}}** - -{{{review.body}}} - -[pull request]({{pullRequest.htmlUrl}}) -—{{/review.body}} +📝 **Pull request review {{pullRequest.title}}** was **{{action}}** by **{{review.user.login}}** +**Text:** {{{review.body}}} +**Repository:** {{repository.fullName}} +**PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} 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 index f8d6fd1..09c4d4d 100644 --- a/src/main/resources/templates/en/pull_request_review_comment.created.template +++ b/src/main/resources/templates/en/pull_request_review_comment.created.template @@ -1,6 +1,5 @@ -**[{{repository.fullName}}]** Pull request review **{{pullRequest.title}}** was commented by **{{comment.user.login}}** - -{{{comment.body}}} - -[comment]({{comment.htmlUrl}}) -— +📝 **Pull request review {{pullRequest.title}}** was **commented** by **{{comment.user.login}}** +**Text:** {{{comment.body}}} +**Repository:** {{repository.fullName}} +**PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} +**Comment:** [link]({{comment.htmlUrl}}) diff --git a/src/main/resources/templates/en/push.template b/src/main/resources/templates/en/push.template index 51b2108..03ffc93 100644 --- a/src/main/resources/templates/en/push.template +++ b/src/main/resources/templates/en/push.template @@ -1,9 +1,8 @@ {{^commits.isEmpty}} -**[{{repository.fullName}}]** Push by **{{sender.login}}** - +🫸 **Push** by **{{sender.login}}** {{#commits}} - {{{message}}} {{/commits}} - [compare]({{compare}}) +**Repository:** {{repository.fullName}} —{{/commits.isEmpty}} From 8415c2bfed7455f89d60beefce0d61d3caf042fe Mon Sep 17 00:00:00 2001 From: Luca Rospocher Date: Wed, 26 Aug 2026 18:18:14 +0200 Subject: [PATCH 4/6] Ignore submitted if review.body is missing (happens when it's not a full review but just a comment --- .../com/wire/github/util/TemplateHandler.kt | 1 + .../en/pull_request_review.submitted.template | 4 +- src/main/resources/templates/en/push.template | 2 +- .../wire/github/util/TemplateHandlerTest.kt | 104 ++++++++++++++++++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt diff --git a/src/main/kotlin/com/wire/github/util/TemplateHandler.kt b/src/main/kotlin/com/wire/github/util/TemplateHandler.kt index abb4919..e497ee5 100644 --- a/src/main/kotlin/com/wire/github/util/TemplateHandler.kt +++ b/src/main/kotlin/com/wire/github/util/TemplateHandler.kt @@ -63,6 +63,7 @@ class TemplateHandler { .apply { mustache.execute(PrintWriter(this), model).flush() }.toString() + .takeIf { it.isNotBlank() } private companion object { const val LANGUAGE_ENGLISH = "en" 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 5d56bac..aacf44c 100644 --- a/src/main/resources/templates/en/pull_request_review.submitted.template +++ b/src/main/resources/templates/en/pull_request_review.submitted.template @@ -1,4 +1,6 @@ -📝 **Pull request review {{pullRequest.title}}** was **{{action}}** by **{{review.user.login}}** +{{#review.body}} +📝 **Pull request review {{pullRequest.title}}** has been **{{review.state}}** by **{{review.user.login}}** **Text:** {{{review.body}}} **Repository:** {{repository.fullName}} **PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} +{{/review.body}} diff --git a/src/main/resources/templates/en/push.template b/src/main/resources/templates/en/push.template index 03ffc93..ed48ec3 100644 --- a/src/main/resources/templates/en/push.template +++ b/src/main/resources/templates/en/push.template @@ -3,6 +3,6 @@ {{#commits}} - {{{message}}} {{/commits}} -[compare]({{compare}}) +**Compare:** [link]({{compare}}) **Repository:** {{repository.fullName}} —{{/commits.isEmpty}} diff --git a/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt b/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt new file mode 100644 index 0000000..c37d201 --- /dev/null +++ b/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt @@ -0,0 +1,104 @@ +package com.wire.github.util + +import com.wire.github.response.model.Commit +import com.wire.github.response.model.GitHubResponse +import com.wire.github.response.model.PullRequest +import com.wire.github.response.model.Repository +import com.wire.github.response.model.Review +import com.wire.github.response.model.User +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertNull + +class TemplateHandlerTest { + private val templateHandler = TemplateHandler() + + @Test + fun `does not render a submitted pull request review without a body`() { + val message = templateHandler.handleEvent( + event = "pull_request_review", + response = reviewResponse(body = null) + ) + + assertNull(message) + } + + @Test + fun `does not render a submitted pull request review with a blank body`() { + val message = templateHandler.handleEvent( + event = "pull_request_review", + response = reviewResponse(body = "") + ) + + assertNull(message) + } + + @Test + fun `renders a submitted pull request review with a body`() { + val message = templateHandler.handleEvent( + event = "pull_request_review", + response = reviewResponse(body = "Looks good") + ) + + assertContains(message.orEmpty(), "Looks good") + } + + @Test + fun `does not render a push with no commits`() { + val message = templateHandler.handleEvent( + event = "push", + response = pushResponse(commits = emptyList()) + ) + + assertNull(message) + } + + @Test + fun `renders a push with commits`() { + val message = templateHandler.handleEvent( + event = "push", + response = pushResponse(commits = listOf(Commit(message = "Add feature"))) + ) + + assertContains(message.orEmpty(), "Add feature") + } + + private fun reviewResponse(body: String?) = + GitHubResponse( + action = "submitted", + pullRequest = PullRequest( + htmlUrl = "https://github.com/wire/example/pull/1", + title = "Example pull request", + user = user, + number = 1 + ), + review = Review( + body = body, + user = user, + state = "approved" + ), + sender = user, + repository = Repository( + fullName = "wire/example", + name = "example" + ) + ) + + private fun pushResponse(commits: List) = + GitHubResponse( + commits = commits, + sender = user, + compare = "https://github.com/wire/example/compare/main", + repository = Repository( + fullName = "wire/example", + name = "example" + ) + ) + + private companion object { + val user = User( + avatarUrl = "https://github.com/wire.png", + login = "wire" + ) + } +} From 1e2f6fe823d2a09e320ad632b23ac78d206b284d Mon Sep 17 00:00:00 2001 From: Luca Rospocher Date: Thu, 27 Aug 2026 09:30:05 +0200 Subject: [PATCH 5/6] Baris comments, moving dynamic text at the end, avoid PR title duplication --- .../resources/templates/en/issue_comment.created.template | 5 +++-- .../templates/en/pull_request_review.submitted.template | 4 ++-- .../en/pull_request_review_comment.created.template | 4 ++-- src/main/resources/templates/en/push.template | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/resources/templates/en/issue_comment.created.template b/src/main/resources/templates/en/issue_comment.created.template index ad79fc4..d94903d 100644 --- a/src/main/resources/templates/en/issue_comment.created.template +++ b/src/main/resources/templates/en/issue_comment.created.template @@ -1,4 +1,5 @@ -📝 **New comment** on issue/PR **{{{issue.title}}}** by **{{sender.login}}** -**Text:** {{{comment.body}}} +📝 **New comment** on PR/issue **{{{issue.title}}}** by **{{sender.login}}** **Repository:** {{repository.fullName}} +**PR/issue:** [#{{issue.number}}]({{issue.htmlUrl}}) - {{issue.title}} **Comment:** [link]({{comment.htmlUrl}}) +**Text:** {{{comment.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 aacf44c..f5de3d7 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,6 @@ {{#review.body}} -📝 **Pull request review {{pullRequest.title}}** has been **{{review.state}}** by **{{review.user.login}}** -**Text:** {{{review.body}}} +📝 **Pull request** has been **{{review.state}}** by **{{review.user.login}}** **Repository:** {{repository.fullName}} **PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} +**Text:** {{{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 index 09c4d4d..e1505dc 100644 --- a/src/main/resources/templates/en/pull_request_review_comment.created.template +++ b/src/main/resources/templates/en/pull_request_review_comment.created.template @@ -1,5 +1,5 @@ -📝 **Pull request review {{pullRequest.title}}** was **commented** by **{{comment.user.login}}** -**Text:** {{{comment.body}}} +📝 **Pull request** was **commented** by **{{comment.user.login}}** **Repository:** {{repository.fullName}} **PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} **Comment:** [link]({{comment.htmlUrl}}) +**Text:** {{{comment.body}}} diff --git a/src/main/resources/templates/en/push.template b/src/main/resources/templates/en/push.template index ed48ec3..8e02928 100644 --- a/src/main/resources/templates/en/push.template +++ b/src/main/resources/templates/en/push.template @@ -1,8 +1,8 @@ {{^commits.isEmpty}} 🫸 **Push** by **{{sender.login}}** +**Repository:** {{repository.fullName}} {{#commits}} - {{{message}}} {{/commits}} **Compare:** [link]({{compare}}) -**Repository:** {{repository.fullName}} —{{/commits.isEmpty}} From 8eef285aa19c08c9a9ca1b61b7c4614aa0c0a0d9 Mon Sep 17 00:00:00 2001 From: Luca Rospocher Date: Thu, 27 Aug 2026 10:05:59 +0200 Subject: [PATCH 6/6] Change emoji by state, tweak message of PR review submitted --- .../com/wire/github/response/model/Review.kt | 9 ++- .../en/pull_request_review.submitted.template | 2 +- .../wire/github/util/TemplateHandlerTest.kt | 61 +++++++++++++------ 3 files changed, 51 insertions(+), 21 deletions(-) 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 785096e..0adf5a1 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,11 @@ data class Review( val body: String? = null, val user: User? = null, val state: String -) +) { + val emoji: String + get() = when (state) { + "approved" -> "✅" + "changes_requested" -> "🔄" + else -> "📝" + } +} 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 f5de3d7..37f133e 100644 --- a/src/main/resources/templates/en/pull_request_review.submitted.template +++ b/src/main/resources/templates/en/pull_request_review.submitted.template @@ -1,5 +1,5 @@ {{#review.body}} -📝 **Pull request** has been **{{review.state}}** by **{{review.user.login}}** +{{review.emoji}} **Pull request** update: **{{review.state}}** by **{{review.user.login}}** **Repository:** {{repository.fullName}} **PR:** [#{{pullRequest.number}}]({{pullRequest.htmlUrl}}) - {{pullRequest.title}} **Text:** {{{review.body}}} diff --git a/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt b/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt index c37d201..33609eb 100644 --- a/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt +++ b/src/test/kotlin/com/wire/github/util/TemplateHandlerTest.kt @@ -41,6 +41,27 @@ class TemplateHandlerTest { ) assertContains(message.orEmpty(), "Looks good") + assertContains(message.orEmpty(), "✅") + } + + @Test + fun `renders a note emoji for a commented pull request review`() { + val message = templateHandler.handleEvent( + event = "pull_request_review", + response = reviewResponse(body = "A comment", state = "commented") + ) + + assertContains(message.orEmpty(), "📝") + } + + @Test + fun `renders a change emoji for a pull request review with requested changes`() { + val message = templateHandler.handleEvent( + event = "pull_request_review", + response = reviewResponse(body = "Please update this", state = "changes_requested") + ) + + assertContains(message.orEmpty(), "🔄") } @Test @@ -63,26 +84,28 @@ class TemplateHandlerTest { assertContains(message.orEmpty(), "Add feature") } - private fun reviewResponse(body: String?) = - GitHubResponse( - action = "submitted", - pullRequest = PullRequest( - htmlUrl = "https://github.com/wire/example/pull/1", - title = "Example pull request", - user = user, - number = 1 - ), - review = Review( - body = body, - user = user, - state = "approved" - ), - sender = user, - repository = Repository( - fullName = "wire/example", - name = "example" - ) + private fun reviewResponse( + body: String?, + state: String = "approved" + ) = GitHubResponse( + action = "submitted", + pullRequest = PullRequest( + htmlUrl = "https://github.com/wire/example/pull/1", + title = "Example pull request", + user = user, + number = 1 + ), + review = Review( + body = body, + user = user, + state = state + ), + sender = user, + repository = Repository( + fullName = "wire/example", + name = "example" ) + ) private fun pushResponse(commits: List) = GitHubResponse(