Skip to content
Merged
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
22 changes: 19 additions & 3 deletions actions/setup/js/add_comment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,18 @@ async function findCommentsWithTrackerId(github, owner, repo, issueNumber, workf
break;
}

// Filter comments that contain the workflow-id and are NOT reaction comments
// Filter comments that contain the workflow-id and are NOT reaction comments.
// Supports both the standalone marker format (<!-- gh-aw-workflow-id: value -->)
// and the combined XML marker format (<!-- gh-aw-agentic-workflow: ..., workflow_id: value, ... -->).
const filteredComments = data
.filter(comment => comment.body?.includes(`<!-- gh-aw-workflow-id: ${workflowId} -->`) && !comment.body.includes(`<!-- gh-aw-comment-type: reaction -->`))
.filter(comment => {
if (!comment.body || comment.body.includes(`<!-- gh-aw-comment-type: reaction -->`)) return false;
// Standalone marker: <!-- gh-aw-workflow-id: value -->
if (comment.body.includes(`<!-- gh-aw-workflow-id: ${workflowId} -->`)) return true;
// Combined XML marker: <!-- gh-aw-agentic-workflow: ..., workflow_id: value, ... -->
if (comment.body.includes(`<!-- gh-aw-agentic-workflow:`) && (comment.body.includes(`workflow_id: ${workflowId},`) || comment.body.includes(`workflow_id: ${workflowId} -->`))) return true;
return false;
})
.map(({ id, node_id, body }) => ({ id, node_id, body }));

comments.push(...filteredComments);
Expand Down Expand Up @@ -129,7 +138,14 @@ async function findDiscussionCommentsWithTrackerId(github, owner, repo, discussi
}

const filteredComments = result.repository.discussion.comments.nodes
.filter(comment => comment.body?.includes(`<!-- gh-aw-workflow-id: ${workflowId} -->`) && !comment.body.includes(`<!-- gh-aw-comment-type: reaction -->`))
.filter(comment => {
if (!comment.body || comment.body.includes(`<!-- gh-aw-comment-type: reaction -->`)) return false;
// Standalone marker: <!-- gh-aw-workflow-id: value -->
if (comment.body.includes(`<!-- gh-aw-workflow-id: ${workflowId} -->`)) return true;
// Combined XML marker: <!-- gh-aw-agentic-workflow: ..., workflow_id: value, ... -->
if (comment.body.includes(`<!-- gh-aw-agentic-workflow:`) && (comment.body.includes(`workflow_id: ${workflowId},`) || comment.body.includes(`workflow_id: ${workflowId} -->`))) return true;
return false;
})
.map(({ id, body }) => ({ id, body }));

comments.push(...filteredComments);
Expand Down
65 changes: 65 additions & 0 deletions actions/setup/js/add_comment.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,71 @@ describe("add_comment", () => {
// Clean up
delete process.env.GH_AW_WORKFLOW_ID;
});

it("should hide older comments with combined XML marker format (workflow_id inside gh-aw-agentic-workflow)", async () => {
const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8");

delete process.env.GH_AW_SAFE_OUTPUT_MESSAGES;
process.env.GH_AW_WORKFLOW_ID = "test-workflow";

let hideCommentsWasCalled = false;
let listCommentsCalls = 0;

mockGithub.rest.issues.listComments = async () => {
listCommentsCalls++;
return {
data: [
{
id: 999,
node_id: "IC_kwDOTest999",
body: "Old comment\n\n<!-- gh-aw-agentic-workflow: Test Workflow, engine: copilot, id: 12345, workflow_id: test-workflow, run: https://github.com/owner/repo/actions/runs/12345 -->",
},
],
};
};

mockGithub.graphql = async (query, variables) => {
if (query.includes("minimizeComment")) {
hideCommentsWasCalled = true;
}
return {
minimizeComment: {
minimizedComment: {
isMinimized: true,
},
},
};
};

let capturedComment = null;
mockGithub.rest.issues.createComment = async params => {
capturedComment = params;
return {
data: {
id: 12346,
html_url: `https://github.com/owner/repo/issues/${params.issue_number}#issuecomment-12346`,
},
};
};

const handler = await eval(`(async () => { ${addCommentScript}; return await main({ hide_older_comments: true }); })()`);

const message = {
type: "add_comment",
body: "New comment - should hide combined-marker old ones",
};

const result = await handler(message, {});

expect(result.success).toBe(true);
expect(hideCommentsWasCalled).toBe(true);
expect(listCommentsCalls).toBeGreaterThan(0);
expect(capturedComment).toBeTruthy();
expect(capturedComment.body).toContain("New comment - should hide combined-marker old ones");

// Clean up
delete process.env.GH_AW_WORKFLOW_ID;
});
});

describe("404 error handling", () => {
Expand Down
Loading