feat: add sticky_comment input to reduce GitHub comment spam (#211)

* feat: no claude spam

* feat: add silent property

* feat: add silent property

* feat: add silent property

* chore: call me a sticky comment

* chore: applying review comments

* chore: apply review comments

* format

* reword

---------

Co-authored-by: Ashwin Bhat <ashwin@anthropic.com>
This commit is contained in:
Dmitriy Shekhovtsov
2025-07-01 19:37:39 +02:00
committed by GitHub
parent bcb072b63f
commit 79f2086fce
7 changed files with 50 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ export type ParsedGitHubContext = {
directPrompt: string;
baseBranch?: string;
branchPrefix: string;
useStickyComment: boolean;
};
};
@@ -62,6 +63,7 @@ export function parseGitHubContext(): ParsedGitHubContext {
directPrompt: process.env.DIRECT_PROMPT ?? "",
baseBranch: process.env.BASE_BRANCH,
branchPrefix: process.env.BRANCH_PREFIX ?? "claude/",
useStickyComment: process.env.STICKY_COMMENT === "true",
},
};

View File

@@ -9,6 +9,7 @@ import { appendFileSync } from "fs";
import { createJobRunLink, createCommentBody } from "./common";
import {
isPullRequestReviewCommentEvent,
isPullRequestEvent,
type ParsedGitHubContext,
} from "../../context";
import type { Octokit } from "@octokit/rest";
@@ -25,8 +26,39 @@ export async function createInitialComment(
try {
let response;
// Only use createReplyForReviewComment if it's a PR review comment AND we have a comment_id
if (isPullRequestReviewCommentEvent(context)) {
if (
context.inputs.useStickyComment &&
context.isPR &&
!isPullRequestEvent(context)
) {
const comments = await octokit.rest.issues.listComments({
owner,
repo,
issue_number: context.entityNumber,
});
const existingComment = comments.data.find(
(comment) =>
comment.user?.login.indexOf("claude[bot]") !== -1 ||
comment.body === initialBody,
);
if (existingComment) {
response = await octokit.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: initialBody,
});
} else {
// Create new comment if no existing one found
response = await octokit.rest.issues.createComment({
owner,
repo,
issue_number: context.entityNumber,
body: initialBody,
});
}
} else if (isPullRequestReviewCommentEvent(context)) {
// Only use createReplyForReviewComment if it's a PR review comment AND we have a comment_id
response = await octokit.rest.pulls.createReplyForReviewComment({
owner,
repo,