feat: isolate comment command handlers and skip bot authors (4.2, 8.1)

- /recheck, /conflict, and @bot now run independently via allSettled
- bot-authored comments are skipped before dispatch to prevent loops
This commit is contained in:
wdawdwa committed 2026-08-22 17:51:45 +08:00
1 parent 84276bcd1e
commit 70f964070d
2 files changed
+82 -25

No files matched your search

+61 -25
View File
@@ -50,6 +50,7 @@ type IssueCommentPayload = {
body: string; body: string;
user: { user: {
login: string; login: string;
type?: string;
}; };
}; };
repository: GitHubRepository; repository: GitHubRepository;
@@ -239,31 +240,66 @@ async function main(): Promise<void> {
return; return;
} }
await processRecheckComment(octokit, { if (commentPayload.comment.user?.type === "Bot") {
owner: commentPayload.repository.owner.login, logger.info(
repo: commentPayload.repository.name, { issueNumber: commentPayload.issue.number, login: commentPayload.comment.user.login },
pullNumber: commentPayload.issue.number, "Skipping bot-authored comment to prevent automation loops."
commentId: commentPayload.comment.id, );
commenterLogin: commentPayload.comment.user.login, return;
commentBody: commentPayload.comment.body, }
gitToken: github.token
}); // The three comment commands are independent features; one failing or
await processConflictComment(octokit, { // not matching must not prevent the others from running.
owner: commentPayload.repository.owner.login, const commentTasks: Array<[string, () => Promise<void>]> = [
repo: commentPayload.repository.name, [
pullNumber: commentPayload.issue.number, "recheck",
commentId: commentPayload.comment.id, () =>
commenterLogin: commentPayload.comment.user.login, processRecheckComment(octokit, {
commentBody: commentPayload.comment.body, owner: commentPayload.repository.owner.login,
gitToken: github.token repo: commentPayload.repository.name,
}); pullNumber: commentPayload.issue.number,
await processPullRequestChat(octokit, { commentId: commentPayload.comment.id,
owner: commentPayload.repository.owner.login, commenterLogin: commentPayload.comment.user.login,
repo: commentPayload.repository.name, commentBody: commentPayload.comment.body,
pullNumber: commentPayload.issue.number, gitToken: github.token
commentId: commentPayload.comment.id, })
commenterLogin: commentPayload.comment.user.login, ],
commentBody: commentPayload.comment.body [
"conflict",
() =>
processConflictComment(octokit, {
owner: commentPayload.repository.owner.login,
repo: commentPayload.repository.name,
pullNumber: commentPayload.issue.number,
commentId: commentPayload.comment.id,
commenterLogin: commentPayload.comment.user.login,
commentBody: commentPayload.comment.body,
gitToken: github.token
})
],
[
"chat",
() =>
processPullRequestChat(octokit, {
owner: commentPayload.repository.owner.login,
repo: commentPayload.repository.name,
pullNumber: commentPayload.issue.number,
commentId: commentPayload.comment.id,
commenterLogin: commentPayload.comment.user.login,
commentBody: commentPayload.comment.body
})
]
];
const results = await Promise.allSettled(commentTasks.map(([, run]) => run()));
results.forEach((result, index) => {
if (result.status === "rejected") {
const [label] = commentTasks[index]!;
logger.error(
{ error: result.reason, task: label, issueNumber: commentPayload.issue.number },
"Comment command handler failed; other handlers still ran."
);
}
}); });
return; return;
} }
+21
View File
@@ -0,0 +1,21 @@
import assert from "node:assert/strict";
import test from "node:test";
import { containsBotMention } from "../src/chat/processor.js";
test("bot mention detection accepts configured aliases", () => {
assert.equal(containsBotMention("@bot help me", "ghbot"), true);
assert.equal(containsBotMention("@ghbot please review", "ghbot"), true);
assert.equal(containsBotMention("@ghbot[bot] ping", "ghbot[bot]"), true);
});
test("partial usernames and ordinary text never trigger the bot", () => {
assert.equal(containsBotMention("email me at user@botmail.com", "ghbot"), false);
assert.equal(containsBotMention("the @botanist knows", "ghbot"), false);
assert.equal(containsBotMention("no mention here", "ghbot"), false);
assert.equal(containsBotMention("@anotherbot hi", "ghbot"), false);
});
test("mention detection is case-insensitive", () => {
assert.equal(containsBotMention("@BOT hello", "ghbot"), true);
assert.equal(containsBotMention("@GHBOT[BOT] hello", "ghbot[bot]"), true);
});