fix: don't require bot ID match when header is present

The bot_id default (41898282 = github-actions[bot]) doesn't match
claude[bot] (209825114) when using OIDC auth. This caused the sticky
comment matching to always fail, creating new comments each run.

Header-based matching is authoritative — if a comment has our specific
<!-- bot: {id} --> header, that's sufficient for identification. Bot ID
check is now only used for legacy comments without headers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Tosin Afolabi 2026-02-13 10:15:19 -05:00
parent 600162b09b
commit 3128a645ab

View File

@ -50,10 +50,6 @@ export async function createInitialComment(
);
const existingComment = comments.find((comment) => {
// Must be from the correct bot user
const idMatch = comment.user?.id === Number(context.inputs.botId);
if (!idMatch) return false;
if (botIdentifier) {
// Check for our hidden header (case-insensitive, whitespace-tolerant)
const headerPattern = new RegExp(
@ -67,12 +63,15 @@ export async function createInitialComment(
comment.body || "",
);
// If comment has a header, ONLY match if it's ours
// Header match is authoritative — no bot ID check needed
if (hasAnyHeader) {
return hasOurHeader;
}
// Legacy comments (no header): match if it looks like a Claude comment
// Legacy comments (no header): require bot ID + Claude content
const idMatch = comment.user?.id === Number(context.inputs.botId);
if (!idMatch) return false;
const isClaudeComment =
comment.body?.includes("Claude Code is working") ||
comment.body?.includes("View job run");
@ -80,11 +79,12 @@ export async function createInitialComment(
return isClaudeComment;
}
// Fallback when no botIdentifier: match any Claude-looking comment
// Fallback when no botIdentifier: match by bot user
const idMatch = comment.user?.id === Number(context.inputs.botId);
const botNameMatch =
comment.user?.type === "Bot" &&
comment.user?.login.toLowerCase().includes("claude");
return botNameMatch;
return idMatch || botNameMatch;
});
if (existingComment) {