Skip to content

feat: mention mapped GitHub users in Wire - #184

Open
netbe wants to merge 3 commits into
mainfrom
codex/github-user-mentions
Open

netbe wants to merge 3 commits into
mainfrom
codex/github-user-mentions

Conversation

@netbe

@netbe netbe commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

GitHub notifications can now mention the corresponding Wire users. /github map <github-login> @Wire user registers a persistent, conversation-specific mapping using Wire's mention picker.

  • PR review requests mention the mapped requested reviewer.
  • PR reviews, inline comments, and issue/PR conversation comments resolve exact, case-sensitive @github-login tags in their bodies, excluding the reviewer/comment author.
  • Issue notifications resolve tags in the rendered title/body, excluding the issue author. Custom Actions messages resolve tags in their text.
  • Other notifications remain unchanged; unmapped tags stay plain text.

Build configuration now resolves plugin dependencies directly from Maven Central, avoiding missing transitive dependencies through the Plugin Portal.

Mention failures now fall back to plain-text delivery. Automatic review requests can resolve a unique mapping with different capitalization; explicit body tags remain case-sensitive. Mapping commands accept trailing whitespace after a selected Wire mention.

Validation: 52 focused tests passed after review fixes, including command dispatch, reviewer capitalization, author exclusions, repeated body/title offsets, and delivery when mention lookup fails. ktlintCheck, detekt, and git diff --check passed. Live Wire delivery has not been tested.

@netbe
netbe requested a review from a team as a code owner December 2, 2026 15:13
@claude

claude Bot commented Dec 2, 2026

Copy link
Copy Markdown

Review: mention mapped GitHub users in Wire

Overall this is a solid feature. Using UUID placeholders in TemplateHandler.mentionRanges to find where user-written fields land in the rendered message is a good approach. It handles text in headers that happens to match the body, Mustache escaping of non-marked fields, and emoji (UTF-16) offsets without needing per-template offset tables. The tests cover the tricky parts well (partial names, emails, URL paths, author exclusion, emoji offsets). Some notes below.

Potential bugs / behavioural issues

  1. Review-request lookup is case-sensitive, but GitHub logins are not. (AuthorMentions.kt reviewRequestMentions → RedisService.getAuthorMapping)
    hget(key, login) uses the exact requested_reviewer.login from the payload, which GitHub always sends in its canonical capitalization (e.g. Octocat). If someone runs /github map octocat @User, the reviewer is never mentioned, and the bot gives no hint why. The same mismatch means octocat and Octocat can end up as two separate hash entries that point to different Wire users. Some options:

    • store the field under login.lowercase() and keep the display form only for the confirmation message, or
    • at least do a case-insensitive lookup for the review-request path (one hgetall plus entries.firstOrNull { it.key.equals(login, true) }).
      For explicit @tags in bodies, exact case matching is documented and defensible. For the reviewer path, which is driven by GitHub's own payload, it is more likely to surprise users.
  2. Trailing whitespace makes /github map fail. MAPPING_COMMAND captures the target with (.+), and the mention must cover the whole capture (it.length == target.value.length). If a Wire client leaves a trailing space after the mention picker inserts the name (some clients do), the user gets the usage error even though they did everything right. Consider trimming the command first, or requiring only mention.offset == target.range.first && mention.offset + mention.length == command.trimEnd().length.

  3. Mentions inside code spans and blocks. A body like Run `@octocat` locally, or a fenced block that contains @octocat, still produces a native mention. This is minor, but you may want to note it in the README or skip backtick-delimited ranges.

Security

  • Any participant can overwrite a mapping (this is documented). Also note that selectedUser.userId comes from the client-supplied mention. A modified client could map a login to a Wire user who isn't in the conversation. The impact is low, because the mention would only be noise in this conversation, but it's worth knowing.
  • Mapping data is never cleaned up. There is no unmap or list command, and nothing deletes …:authors when the app leaves a conversation. That isn't a security issue, but users currently have no way to see or remove a wrong mapping. A /github map list or /github unmap <login> would round this out, either here or in a follow-up.

Code quality

  • repositoryMentions uses else -> return reviewRequestMentions(...) inside the val author = when expression. It works, but routing the pull_request case through the "author" when is a bit hidden. A top-level when (event) that dispatches to the review-request path and the body-tag path separately would be easier to follow.
  • mentionRanges lives in TemplateHandler but has to know which fields of which events are user-authored, and repositoryMentions repeats the same event list for authors. Consider keeping both event→field tables in one place (for example both in AuthorMentions.kt) so a new event can't be added to one and forgotten in the other.
  • title = mark(it.title)!!: if Issue.title is non-null, a small markRequired(value: String): String overload would avoid the !!.
  • registerMapping splits the command and then also runs MAPPING_COMMAND.matchEntire. Since the regex already anchors /github map, the split pre-check is only there to tell "not my command" apart from "malformed map". That's fine, but a short comment would help.
  • The help text says map a PR reviewer, but the feature now covers comment, review, issue and Actions tags as well. Something like "map a GitHub login to a Wire user for mentions" would be more accurate.
  • @Suppress("TooManyFunctions") on RedisService is acceptable. Alternatively, a small AuthorMappingRepository would keep the class focused and avoid the suppression.

Performance

  • For issues, issue_comment and review events, the template is now rendered twice (once normally, once with markers), and getAuthorMappings does an HGETALL per delivery. Mustache templates are cached by DefaultMustacheFactory and hashes per conversation are small, so this is negligible. One cheap win: call getAuthorMappings before mentionRanges and skip the second render when there are no mappings (the common case).
  • The regex is rebuilt from all mapped logins on every message. That's fine at this scale.

Tests

Coverage is good. A few gaps worth filling:

  • A review request where the stored mapping's case differs from the payload login (this documents the behaviour in point 1, whichever way you decide).
  • /github map with trailing whitespace, and with a valid login plus a correctly placed mention but extra text after it.
  • An issue_comment where the body is identical to the issue title. The title is rendered twice in that template, so this checks that only the body range is used.
  • A webhook-level (ApplicationTest) test for a comment or issue event with a mapping, to cover the repositoryMentions wiring in Routing.kt end to end. Today only the review-request path is covered there.
  • The PR description says live Wire delivery hasn't been tested. Please verify on at least one client that UTF-16 offsets render correctly with emoji before the mention (the 🚀 cases).

Nice work overall. The main item I'd address before merging is the case-sensitivity on the review-request path.

@alexandreferris alexandreferris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition of mentions, but there are still somethings that needs adjustment

Comment on lines +118 to +124
)
const val HELP_COMMAND = "/github help"
const val WEBHOOK_HELP_COMMAND = "/github webhook help"
const val ACTIONS_HELP_COMMAND = "/github actions help"
const val HELP_COMMANDS =
"Available commands:\n" +
"- `/github map <github-login> @Wire user` - map a PR reviewer\n" +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the new /github map as a const:

Suggested change
)
const val HELP_COMMAND = "/github help"
const val WEBHOOK_HELP_COMMAND = "/github webhook help"
const val ACTIONS_HELP_COMMAND = "/github actions help"
const val HELP_COMMANDS =
"Available commands:\n" +
"- `/github map <github-login> @Wire user` - map a PR reviewer\n" +
)
const val HELP_COMMAND = "/github help"
const val WEBHOOK_HELP_COMMAND = "/github webhook help"
const val ACTIONS_HELP_COMMAND = "/github actions help"
const val MENTIONS_MAP_COMMAND = "/github map"
const val HELP_COMMANDS =
"Available commands:\n" +
"- `$MENTIONS_MAP_COMMAND <github-login> @Wire user` - map a PR reviewer\n" +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other places using the same command, so need to update them accordingly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e127cd1: added MENTIONS_MAP_COMMAND and reused it in command dispatch, parsing, usage, and help text. The help now describes mapping a GitHub user rather than only a PR reviewer.

WEBHOOK_HELP_COMMAND -> trackedHelp(webhookHelp(conversationId))
ACTIONS_HELP_COMMAND -> trackedHelp(actionsHelp(conversationId))
else -> null
else -> registerMapping(command, conversationId, mentions)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the exact check and continue returning else -> null for unknown commands:

Suggested change
else -> registerMapping(command, conversationId, mentions)
MENTIONS_MAP_COMMAND -> registerMapping(command, conversationId, mentions)
else -> null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e127cd1: dispatch now explicitly matches the /github map command tokens before calling registerMapping, with else -> null for unknown commands. Matching the tokens preserves support for the required arguments. Regression tests cover unrelated commands, trailing whitespace, and extra text after the selected mention.

),
text = messageTemplate
text = messageTemplate,
mentions = templateHandler.repositoryMentions(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mentions are built inside sendMessage, so if redis fails or a stored id wont parse, the webhook returns 500 and no notification goes out, can we fall back to no mentions instead?

val mentions = runCatching { templateHandler.repositoryMentions(...) }
    .getOrElse { application.log.warn("Failed to resolve mentions", it); emptyList() }

the same applies to actionsMentions at line 223.

If you'd rather put the comment where values get parsed, use RedisService.kt line 30 instead:

fromFullString throws on a malformed value, and the error ends up failing the whole delivery. Maybe parse with mapNotNull { runCatching { … }.getOrNull() }?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e127cd1: both repository and Actions notifications catch mention-resolution failures, log a warning, and send the original text without mentions. Cancellation still propagates. Endpoint regression tests verify successful delivery for unavailable Redis and malformed-ID errors. All 52 focused tests, lint, and CI checks pass.

null
}

fun mentionRanges(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mentionRanges is only used by repositoryMentions in AuthorMentions.kt

Can it be moved there as a private TemplateHandler extension? Then all the mention logic is in one file and TemplateHandler sticks to rendering

It only needs the public handleEvent, so nothing has to change visibility

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e127cd1: moved mentionRanges into AuthorMentions.kt as a private TemplateHandler extension. TemplateHandler now only handles rendering. Also skip the second render when no eligible mappings remain; repeated title/body tests pass.

@netbe
netbe requested a review from alexandreferris December 3, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants