Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/github/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export type MaintainerQueueDigest = {

export function parseGittensoryMentionCommand(body: string | null | undefined): GittensoryMentionCommand | null {
if (!body) return null;
const match = body.match(/(?:^|\s)@gittensory(?:\s+([a-z-]+))?([^\n\r]*)/i);
// `(?![\w-])` keeps the handle from matching as a PREFIX of a longer GitHub username: a comment that
// mentions a different account like `@gittensory-bot` / `@gittensory2` must NOT be parsed as a bare
// `@gittensory help`. GitHub usernames are word chars + hyphen, so the boundary excludes both.
const match = body.match(/(?:^|\s)@gittensory(?![\w-])(?:\s+([a-z-]+))?([^\n\r]*)/i);
if (!match) return null;
const requested = (match[1]?.toLowerCase() || "help") as GittensoryMentionCommandName | GittensoryActionCommandName;
if (ACTION_COMMANDS.has(requested as GittensoryActionCommandName)) {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/github-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ describe("GitHub mention commands", () => {
reason: "known false positive, shipping",
});
expect(parseGittensoryMentionCommand("gittensory preflight")).toBeNull();
// A mention of a DIFFERENT account whose handle merely starts with "gittensory" must not be parsed as a
// bare @gittensory command (GitHub never resolves @gittensory-bot to @gittensory).
expect(parseGittensoryMentionCommand("@gittensory-bot please take a look")).toBeNull();
expect(parseGittensoryMentionCommand("@gittensory2 ping")).toBeNull();
expect(parseGittensoryMentionCommand("@gittensorybot ask q")).toBeNull();
// ...but real punctuation/whitespace boundaries after the handle still parse.
expect(parseGittensoryMentionCommand("@gittensory, preflight please")?.name).toBe("help");
expect(isMaintainerOnlyCommand("queue-summary")).toBe(true);
expect(isMaintainerOnlyCommand("preflight")).toBe(false);
});
Expand Down
Loading