From 8a4b39672bd25aced3d7a66488df9440b31959ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:57:53 +0000 Subject: [PATCH 1/2] Initial plan From 6329d3cd2e10ad421499dbaa95aef94004eca813 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 16:08:46 +0000 Subject: [PATCH 2/2] test: update error message test for add_reaction_and_edit_comment.cjs Update test to match the refactored error message. The code now uses a more comprehensive check that validates discussionNumber, commentId, and commentNodeId together, resulting in a more general error message: "Discussion or comment information not found in event payload" Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .../setup/js/add_reaction_and_edit_comment.cjs | 17 +++++++---------- .../js/add_reaction_and_edit_comment.test.cjs | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/actions/setup/js/add_reaction_and_edit_comment.cjs b/actions/setup/js/add_reaction_and_edit_comment.cjs index 97b3286145..23d53d8dd8 100644 --- a/actions/setup/js/add_reaction_and_edit_comment.cjs +++ b/actions/setup/js/add_reaction_and_edit_comment.cjs @@ -10,9 +10,7 @@ async function main() { const command = process.env.GH_AW_COMMAND; // Only present for command workflows const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; - const runUrl = context.payload.repository - ? `${context.payload.repository.html_url}/actions/runs/${runId}` - : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; + const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; core.info(`Reaction type: ${reaction}`); core.info(`Command name: ${command || "none"}`); @@ -26,7 +24,10 @@ async function main() { return; } - const { eventName, repo: { owner, repo } } = context; + const { + eventName, + repo: { owner, repo }, + } = context; let reactionEndpoint; let commentUpdateEndpoint; const shouldCreateComment = true; // Always create comments for all events @@ -122,9 +123,7 @@ async function main() { // Add reaction first (use GraphQL for discussions, REST for others) const isDiscussionEvent = eventName === "discussion" || eventName === "discussion_comment"; - await (isDiscussionEvent - ? addDiscussionReaction(reactionEndpoint, reaction) - : addReaction(reactionEndpoint, reaction)); + await (isDiscussionEvent ? addDiscussionReaction(reactionEndpoint, reaction) : addReaction(reactionEndpoint, reaction)); // Then add comment core.info(`Comment endpoint: ${commentUpdateEndpoint}`); @@ -217,8 +216,6 @@ async function getDiscussionId(owner, repo, discussionNumber) { return repository.discussion; } - - /** * Add a comment with a workflow run link * @param {string} endpoint - The GitHub API endpoint to create the comment (or special format for discussions) @@ -286,7 +283,7 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName) { const discussionId = repository.discussion.id; const mutationParams = { dId: discussionId, body: commentBody }; - + // Add replyToId for comment threads if (eventName === "discussion_comment") { mutationParams.replyToId = context.payload?.comment?.node_id; diff --git a/actions/setup/js/add_reaction_and_edit_comment.test.cjs b/actions/setup/js/add_reaction_and_edit_comment.test.cjs index 650bd1e48a..4b208cbb18 100644 --- a/actions/setup/js/add_reaction_and_edit_comment.test.cjs +++ b/actions/setup/js/add_reaction_and_edit_comment.test.cjs @@ -134,7 +134,7 @@ const mockCore = { (global.context.eventName = "discussion_comment"), (global.context.payload = { discussion: { number: 10 }, comment: { id: 123 }, repository: { html_url: "https://github.com/testowner/testrepo" } }), await eval(`(async () => { ${reactionScript}; await main(); })()`), - expect(mockCore.setFailed).toHaveBeenCalledWith("Discussion comment node ID not found in event payload"), + expect(mockCore.setFailed).toHaveBeenCalledWith("Discussion or comment information not found in event payload"), expect(mockGithub.graphql).not.toHaveBeenCalled()); })); }),