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;
user: {
login: string;
type?: string;
};
};
repository: GitHubRepository;
@@ -239,31 +240,66 @@ async function main(): Promise<void> {
return;
}
await processRecheckComment(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
});
await 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
});
await 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
if (commentPayload.comment.user?.type === "Bot") {
logger.info(
{ issueNumber: commentPayload.issue.number, login: commentPayload.comment.user.login },
"Skipping bot-authored comment to prevent automation loops."
);
return;
}
// The three comment commands are independent features; one failing or
// not matching must not prevent the others from running.
const commentTasks: Array<[string, () => Promise<void>]> = [
[
"recheck",
() =>
processRecheckComment(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
})
],
[
"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;
}
+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);
});