From 7b18ac6f7a450029bb2cb9c8801bf067e1a3851d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:01:13 +0000 Subject: [PATCH 1/5] Initial plan From fff412c50fb2ffb979482f05bf589a2d04cc5c30 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:18:10 +0000 Subject: [PATCH 2/5] Update add_reaction job to always create new comments with repo output - Modified add_reaction_and_edit_comment.cjs to always create new comments instead of editing existing ones - Added comment-repo output to all comment creation scenarios - Updated compiler.go to include comment_repo in activation job outputs - Added comprehensive tests for the new behavior - All tests pass (JavaScript and Go) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/brave.lock.yml | 69 +++++----- .../workflows/changeset-generator.lock.yml | 69 +++++----- .github/workflows/dev.lock.yml | 69 +++++----- .github/workflows/issue-classifier.lock.yml | 69 +++++----- .github/workflows/pdf-summary.lock.yml | 69 +++++----- .github/workflows/plan.lock.yml | 69 +++++----- .github/workflows/poem-bot.lock.yml | 69 +++++----- .github/workflows/q.lock.yml | 69 +++++----- .github/workflows/scout.lock.yml | 69 +++++----- .github/workflows/tidy.lock.yml | 69 +++++----- .github/workflows/unbloat-docs.lock.yml | 69 +++++----- pkg/workflow/compiler.go | 1 + .../js/add_reaction_and_edit_comment.cjs | 88 +++++------- .../js/add_reaction_and_edit_comment.test.cjs | 126 +++++++++++++++++- pkg/workflow/reaction_outputs_test.go | 4 + 15 files changed, 529 insertions(+), 449 deletions(-) diff --git a/.github/workflows/brave.lock.yml b/.github/workflows/brave.lock.yml index b633ad3e67c..f359c84ab9f 100644 --- a/.github/workflows/brave.lock.yml +++ b/.github/workflows/brave.lock.yml @@ -140,6 +140,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -564,50 +565,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/changeset-generator.lock.yml b/.github/workflows/changeset-generator.lock.yml index d89e4fd609f..a31e110c02a 100644 --- a/.github/workflows/changeset-generator.lock.yml +++ b/.github/workflows/changeset-generator.lock.yml @@ -138,6 +138,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -561,50 +562,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/dev.lock.yml b/.github/workflows/dev.lock.yml index f620f1e4553..45af101147e 100644 --- a/.github/workflows/dev.lock.yml +++ b/.github/workflows/dev.lock.yml @@ -211,6 +211,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} steps: @@ -472,50 +473,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/issue-classifier.lock.yml b/.github/workflows/issue-classifier.lock.yml index d0c2688ba03..b709faedf3b 100644 --- a/.github/workflows/issue-classifier.lock.yml +++ b/.github/workflows/issue-classifier.lock.yml @@ -135,6 +135,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -558,50 +559,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/pdf-summary.lock.yml b/.github/workflows/pdf-summary.lock.yml index d8f7ffddeb5..ff473ce0056 100644 --- a/.github/workflows/pdf-summary.lock.yml +++ b/.github/workflows/pdf-summary.lock.yml @@ -161,6 +161,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -585,50 +586,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/plan.lock.yml b/.github/workflows/plan.lock.yml index f87ed035c50..6a08c361ab2 100644 --- a/.github/workflows/plan.lock.yml +++ b/.github/workflows/plan.lock.yml @@ -136,6 +136,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -560,50 +561,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/poem-bot.lock.yml b/.github/workflows/poem-bot.lock.yml index 3b61a46af0e..17c7b839737 100644 --- a/.github/workflows/poem-bot.lock.yml +++ b/.github/workflows/poem-bot.lock.yml @@ -165,6 +165,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -589,50 +590,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/q.lock.yml b/.github/workflows/q.lock.yml index 328fae1a71e..4e625efae55 100644 --- a/.github/workflows/q.lock.yml +++ b/.github/workflows/q.lock.yml @@ -182,6 +182,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -606,50 +607,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/scout.lock.yml b/.github/workflows/scout.lock.yml index b1d1e7b2051..3f46142c84f 100644 --- a/.github/workflows/scout.lock.yml +++ b/.github/workflows/scout.lock.yml @@ -195,6 +195,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} text: ${{ steps.compute-text.outputs.text }} @@ -619,50 +620,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/tidy.lock.yml b/.github/workflows/tidy.lock.yml index 0893df7f1c2..060962f6662 100644 --- a/.github/workflows/tidy.lock.yml +++ b/.github/workflows/tidy.lock.yml @@ -150,6 +150,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} steps: @@ -411,50 +412,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/.github/workflows/unbloat-docs.lock.yml b/.github/workflows/unbloat-docs.lock.yml index 5a949b9c565..a357fe6c96d 100644 --- a/.github/workflows/unbloat-docs.lock.yml +++ b/.github/workflows/unbloat-docs.lock.yml @@ -147,6 +147,7 @@ jobs: pull-requests: write outputs: comment_id: ${{ steps.react.outputs.comment-id }} + comment_repo: ${{ steps.react.outputs.comment-repo }} comment_url: ${{ steps.react.outputs.comment-url }} reaction_id: ${{ steps.react.outputs.reaction-id }} steps: @@ -408,50 +409,46 @@ jobs: core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); return; } - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - if (isCreateComment) { - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - const updatedBody = originalBody + workflowLinkText; - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.warning( diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go index 2ff1e7b7638..2ac2389d2a3 100644 --- a/pkg/workflow/compiler.go +++ b/pkg/workflow/compiler.go @@ -2165,6 +2165,7 @@ func (c *Compiler) buildActivationJob(data *WorkflowData, preActivationJobCreate outputs["reaction_id"] = "${{ steps.react.outputs.reaction-id }}" outputs["comment_id"] = "${{ steps.react.outputs.comment-id }}" outputs["comment_url"] = "${{ steps.react.outputs.comment-url }}" + outputs["comment_repo"] = "${{ steps.react.outputs.comment-repo }}" } // If no steps have been added, add a dummy step to make the job valid diff --git a/pkg/workflow/js/add_reaction_and_edit_comment.cjs b/pkg/workflow/js/add_reaction_and_edit_comment.cjs index 8ca7588d4cf..00a82e4e544 100644 --- a/pkg/workflow/js/add_reaction_and_edit_comment.cjs +++ b/pkg/workflow/js/add_reaction_and_edit_comment.cjs @@ -321,8 +321,10 @@ async function addOrEditCommentWithWorkflowLink(endpoint, runUrl, eventName) { core.info(`Successfully created discussion comment with workflow link`); core.info(`Comment ID: ${comment.id}`); core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); core.setOutput("comment-id", comment.id); core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { // For discussion comments, we would need to update the comment via GraphQL @@ -332,59 +334,41 @@ async function addOrEditCommentWithWorkflowLink(endpoint, runUrl, eventName) { return; } - // For issues and pull_request events, create a new comment - // For comment events (issue_comment, pull_request_review_comment), edit the existing comment - const isCreateComment = eventName === "issues" || eventName === "pull_request"; - - if (isCreateComment) { - // Create a new comment - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventName === "issues" ? "issue" : "pull request"}`; - - const createResponse = await github.request("POST " + endpoint, { - body: workflowLinkText, - headers: { - Accept: "application/vnd.github+json", - }, - }); - - core.info(`Successfully created comment with workflow link`); - core.info(`Comment ID: ${createResponse.data.id}`); - core.info(`Comment URL: ${createResponse.data.html_url}`); - core.setOutput("comment-id", createResponse.data.id.toString()); - core.setOutput("comment-url", createResponse.data.html_url); - } else { - // Edit existing comment - // First, get the current comment content - const getResponse = await github.request("GET " + endpoint, { - headers: { - Accept: "application/vnd.github+json", - }, - }); - - const originalBody = getResponse.data.body || ""; - const workflowLinkText = `\n\nAgentic [${workflowName}](${runUrl}) triggered by this comment`; - - // Check if we've already added a workflow link to avoid duplicates - // Look for the specific pattern "Agentic []() triggered by this comment" - const duplicatePattern = /Agentic \[.+?\]\(.+?\) triggered by this comment/; - if (duplicatePattern.test(originalBody)) { - core.info("Comment already contains a workflow run link, skipping edit"); - return; - } - - const updatedBody = originalBody + workflowLinkText; - - // Update the comment - const updateResponse = await github.request("PATCH " + endpoint, { - body: updatedBody, - headers: { - Accept: "application/vnd.github+json", - }, - }); - - core.info(`Successfully updated comment with workflow link`); - core.info(`Comment ID: ${updateResponse.data.id}`); + // Always create a new comment (never edit existing comments) + let eventTypeDescription; + switch (eventName) { + case "issues": + eventTypeDescription = "issue"; + break; + case "pull_request": + eventTypeDescription = "pull request"; + break; + case "issue_comment": + eventTypeDescription = "issue comment"; + break; + case "pull_request_review_comment": + eventTypeDescription = "pull request review comment"; + break; + default: + eventTypeDescription = "event"; } + + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + + const createResponse = await github.request("POST " + endpoint, { + body: workflowLinkText, + headers: { + Accept: "application/vnd.github+json", + }, + }); + + core.info(`Successfully created comment with workflow link`); + core.info(`Comment ID: ${createResponse.data.id}`); + core.info(`Comment URL: ${createResponse.data.html_url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", createResponse.data.id.toString()); + core.setOutput("comment-url", createResponse.data.html_url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); } catch (error) { // Don't fail the entire job if comment editing/creation fails - just log it const errorMessage = error instanceof Error ? error.message : String(error); diff --git a/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs b/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs index 63ea61895f6..40e68d4d614 100644 --- a/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs +++ b/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs @@ -330,7 +330,126 @@ describe("add_reaction_and_edit_comment.cjs", () => { }); }); - describe("Comment creation for discussions", () => { + describe("Comment creation (always creates new comments)", () => { + it("should create new comment for issue event", async () => { + process.env.GITHUB_AW_REACTION = "eyes"; + process.env.GITHUB_AW_WORKFLOW_NAME = "Test Workflow"; + global.context.eventName = "issues"; + global.context.payload = { + issue: { number: 123 }, + repository: { html_url: "https://github.com/testowner/testrepo" }, + }; + + // Mock reaction call + mockGithub.request + .mockResolvedValueOnce({ + data: { id: 456 }, + }) + // Mock comment creation + .mockResolvedValueOnce({ + data: { id: 789, html_url: "https://github.com/testowner/testrepo/issues/123#issuecomment-789" }, + }); + + // Execute the script + await eval(`(async () => { ${reactionScript} })()`); + + // Verify comment was created (not edited) + expect(mockGithub.request).toHaveBeenCalledWith( + "POST /repos/testowner/testrepo/issues/123/comments", + expect.objectContaining({ + body: expect.stringContaining("Agentic [Test Workflow]"), + }) + ); + + // Verify outputs + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "789"); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/testowner/testrepo/issues/123#issuecomment-789"); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "testowner/testrepo"); + }); + + it("should create new comment for issue_comment event (not edit)", async () => { + process.env.GITHUB_AW_REACTION = "eyes"; + process.env.GITHUB_AW_WORKFLOW_NAME = "Test Workflow"; + process.env.GITHUB_AW_COMMAND = "test-bot"; // Command workflow + global.context.eventName = "issue_comment"; + global.context.payload = { + issue: { number: 123 }, + comment: { id: 456 }, + repository: { html_url: "https://github.com/testowner/testrepo" }, + }; + + // Mock reaction call + mockGithub.request + .mockResolvedValueOnce({ + data: { id: 111 }, + }) + // Mock comment creation (not GET for edit) + .mockResolvedValueOnce({ + data: { id: 789, html_url: "https://github.com/testowner/testrepo/issues/123#issuecomment-789" }, + }); + + // Execute the script + await eval(`(async () => { ${reactionScript} })()`); + + // Verify new comment was created, NOT edited + // Should be POST to comments endpoint, not GET then PATCH to specific comment + expect(mockGithub.request).toHaveBeenCalledWith( + "POST /repos/testowner/testrepo/issues/comments/456", + expect.objectContaining({ + body: expect.stringContaining("Agentic [Test Workflow]"), + }) + ); + + // Verify GET (for editing) was NOT called + expect(mockGithub.request).not.toHaveBeenCalledWith("GET /repos/testowner/testrepo/issues/comments/456", expect.anything()); + + // Verify outputs + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "789"); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/testowner/testrepo/issues/123#issuecomment-789"); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "testowner/testrepo"); + }); + + it("should create new comment for pull_request_review_comment event (not edit)", async () => { + process.env.GITHUB_AW_REACTION = "rocket"; + process.env.GITHUB_AW_WORKFLOW_NAME = "PR Review Bot"; + process.env.GITHUB_AW_COMMAND = "review-bot"; // Command workflow + global.context.eventName = "pull_request_review_comment"; + global.context.payload = { + pull_request: { number: 456 }, + comment: { id: 789 }, + repository: { html_url: "https://github.com/testowner/testrepo" }, + }; + + // Mock reaction call + mockGithub.request + .mockResolvedValueOnce({ + data: { id: 222 }, + }) + // Mock comment creation + .mockResolvedValueOnce({ + data: { id: 999, html_url: "https://github.com/testowner/testrepo/pull/456#discussion_r999" }, + }); + + // Execute the script + await eval(`(async () => { ${reactionScript} })()`); + + // Verify new comment was created + expect(mockGithub.request).toHaveBeenCalledWith( + "POST /repos/testowner/testrepo/pulls/comments/789", + expect.objectContaining({ + body: expect.stringContaining("Agentic [PR Review Bot]"), + }) + ); + + // Verify GET (for editing) was NOT called + expect(mockGithub.request).not.toHaveBeenCalledWith("GET /repos/testowner/testrepo/pulls/comments/789", expect.anything()); + + // Verify outputs + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "999"); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/testowner/testrepo/pull/456#discussion_r999"); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "testowner/testrepo"); + }); + it("should create comment on discussion when shouldEditComment is true", async () => { process.env.GITHUB_AW_REACTION = "eyes"; process.env.GITHUB_AW_WORKFLOW_NAME = "Test Workflow"; @@ -390,6 +509,11 @@ describe("add_reaction_and_edit_comment.cjs", () => { ); expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "DC_kwDOABcD1M4AaBbD"); + expect(mockCore.setOutput).toHaveBeenCalledWith( + "comment-url", + "https://github.com/testowner/testrepo/discussions/10#discussioncomment-456" + ); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "testowner/testrepo"); }); it("should skip comment update for discussion_comment events", async () => { diff --git a/pkg/workflow/reaction_outputs_test.go b/pkg/workflow/reaction_outputs_test.go index 5c822bb7635..c00bf6473f4 100644 --- a/pkg/workflow/reaction_outputs_test.go +++ b/pkg/workflow/reaction_outputs_test.go @@ -62,6 +62,7 @@ This workflow should generate add_reaction job with comment outputs. "reaction_id:", "comment_id:", "comment_url:", + "comment_repo:", } for _, expected := range expectedOutputs { @@ -80,6 +81,9 @@ This workflow should generate add_reaction job with comment outputs. if !strings.Contains(yamlContent, "steps.react.outputs.comment-url") { t.Error("Generated YAML should contain comment-url output reference") } + if !strings.Contains(yamlContent, "steps.react.outputs.comment-repo") { + t.Error("Generated YAML should contain comment-repo output reference") + } // Verify reaction step is in activation job, not a separate add_reaction job if strings.Contains(yamlContent, "add_reaction:") { From e1e9ce16f2ad90eb860ec342746b6c830f163b1e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Oct 2025 16:00:57 +0000 Subject: [PATCH 3/5] Add periods at end of workflow link text sentences Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/workflow/js/add_reaction_and_edit_comment.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/workflow/js/add_reaction_and_edit_comment.cjs b/pkg/workflow/js/add_reaction_and_edit_comment.cjs index 00a82e4e544..63ad00492e9 100644 --- a/pkg/workflow/js/add_reaction_and_edit_comment.cjs +++ b/pkg/workflow/js/add_reaction_and_edit_comment.cjs @@ -287,7 +287,7 @@ async function addOrEditCommentWithWorkflowLink(endpoint, runUrl, eventName) { if (eventName === "discussion") { // Parse discussion number from special format: "discussion:NUMBER" const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; // Create a new comment on the discussion using GraphQL const { repository } = await github.graphql( @@ -353,7 +353,7 @@ async function addOrEditCommentWithWorkflowLink(endpoint, runUrl, eventName) { eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, From 2a991854d356ac3ad57a60a98f9ee20f4d8a7c33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Oct 2025 17:44:27 +0000 Subject: [PATCH 4/5] Add GraphQL comment creation for discussion_comment events - Now creates new comments on discussion threads for discussion_comment events - Uses GraphQL API to add discussion comments (same as discussion events) - Updated test to verify new comment creation behavior - All 534 JavaScript tests pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/brave.lock.yml | 4 +- .../workflows/changeset-generator.lock.yml | 4 +- .github/workflows/dev.lock.yml | 4 +- .github/workflows/issue-classifier.lock.yml | 4 +- .github/workflows/pdf-summary.lock.yml | 4 +- .github/workflows/plan.lock.yml | 4 +- .github/workflows/poem-bot.lock.yml | 4 +- .github/workflows/q.lock.yml | 4 +- .github/workflows/scout.lock.yml | 4 +- .github/workflows/tidy.lock.yml | 4 +- .github/workflows/unbloat-docs.lock.yml | 4 +- .../js/add_reaction_and_edit_comment.cjs | 44 ++++++++++++++-- .../js/add_reaction_and_edit_comment.test.cjs | 52 +++++++++++++++---- 13 files changed, 104 insertions(+), 36 deletions(-) diff --git a/.github/workflows/brave.lock.yml b/.github/workflows/brave.lock.yml index f359c84ab9f..b2c8b2f19d8 100644 --- a/.github/workflows/brave.lock.yml +++ b/.github/workflows/brave.lock.yml @@ -536,7 +536,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -591,7 +591,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/changeset-generator.lock.yml b/.github/workflows/changeset-generator.lock.yml index a31e110c02a..d2756802646 100644 --- a/.github/workflows/changeset-generator.lock.yml +++ b/.github/workflows/changeset-generator.lock.yml @@ -533,7 +533,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -588,7 +588,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/dev.lock.yml b/.github/workflows/dev.lock.yml index 45af101147e..187839ef79f 100644 --- a/.github/workflows/dev.lock.yml +++ b/.github/workflows/dev.lock.yml @@ -444,7 +444,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -499,7 +499,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/issue-classifier.lock.yml b/.github/workflows/issue-classifier.lock.yml index b709faedf3b..56e6c426331 100644 --- a/.github/workflows/issue-classifier.lock.yml +++ b/.github/workflows/issue-classifier.lock.yml @@ -530,7 +530,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -585,7 +585,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/pdf-summary.lock.yml b/.github/workflows/pdf-summary.lock.yml index ff473ce0056..ea6ed351878 100644 --- a/.github/workflows/pdf-summary.lock.yml +++ b/.github/workflows/pdf-summary.lock.yml @@ -557,7 +557,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -612,7 +612,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/plan.lock.yml b/.github/workflows/plan.lock.yml index 6a08c361ab2..f805c985ac8 100644 --- a/.github/workflows/plan.lock.yml +++ b/.github/workflows/plan.lock.yml @@ -532,7 +532,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -587,7 +587,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/poem-bot.lock.yml b/.github/workflows/poem-bot.lock.yml index 17c7b839737..38aaa44bb1f 100644 --- a/.github/workflows/poem-bot.lock.yml +++ b/.github/workflows/poem-bot.lock.yml @@ -561,7 +561,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -616,7 +616,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/q.lock.yml b/.github/workflows/q.lock.yml index 4e625efae55..5eafa383911 100644 --- a/.github/workflows/q.lock.yml +++ b/.github/workflows/q.lock.yml @@ -578,7 +578,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -633,7 +633,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/scout.lock.yml b/.github/workflows/scout.lock.yml index 3f46142c84f..9466c032c74 100644 --- a/.github/workflows/scout.lock.yml +++ b/.github/workflows/scout.lock.yml @@ -591,7 +591,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -646,7 +646,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/tidy.lock.yml b/.github/workflows/tidy.lock.yml index 060962f6662..ece041bd604 100644 --- a/.github/workflows/tidy.lock.yml +++ b/.github/workflows/tidy.lock.yml @@ -383,7 +383,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -438,7 +438,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/.github/workflows/unbloat-docs.lock.yml b/.github/workflows/unbloat-docs.lock.yml index a357fe6c96d..80e6cf796b9 100644 --- a/.github/workflows/unbloat-docs.lock.yml +++ b/.github/workflows/unbloat-docs.lock.yml @@ -380,7 +380,7 @@ jobs: const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; if (eventName === "discussion") { const discussionNumber = parseInt(endpoint.split(":")[1], 10); - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion.`; const { repository } = await github.graphql( ` query($owner: String!, $repo: String!, $num: Int!) { @@ -435,7 +435,7 @@ jobs: default: eventTypeDescription = "event"; } - const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}`; + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this ${eventTypeDescription}.`; const createResponse = await github.request("POST " + endpoint, { body: workflowLinkText, headers: { diff --git a/pkg/workflow/js/add_reaction_and_edit_comment.cjs b/pkg/workflow/js/add_reaction_and_edit_comment.cjs index 63ad00492e9..0fd124df012 100644 --- a/pkg/workflow/js/add_reaction_and_edit_comment.cjs +++ b/pkg/workflow/js/add_reaction_and_edit_comment.cjs @@ -327,10 +327,46 @@ async function addOrEditCommentWithWorkflowLink(endpoint, runUrl, eventName) { core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } else if (eventName === "discussion_comment") { - // For discussion comments, we would need to update the comment via GraphQL - // However, GitHub's GraphQL API doesn't support updating discussion comments - // So we skip this for now - core.info("Updating discussion comments is not supported by GitHub's GraphQL API"); + // Parse discussion number from special format: "discussion_comment:NUMBER:COMMENT_ID" + const discussionNumber = parseInt(endpoint.split(":")[1], 10); + const workflowLinkText = `Agentic [${workflowName}](${runUrl}) triggered by this discussion comment.`; + + // Create a new comment on the discussion using GraphQL + const { repository } = await github.graphql( + ` + query($owner: String!, $repo: String!, $num: Int!) { + repository(owner: $owner, name: $repo) { + discussion(number: $num) { + id + } + } + }`, + { owner: context.repo.owner, repo: context.repo.repo, num: discussionNumber } + ); + + const discussionId = repository.discussion.id; + + const result = await github.graphql( + ` + mutation($dId: ID!, $body: String!) { + addDiscussionComment(input: { discussionId: $dId, body: $body }) { + comment { + id + url + } + } + }`, + { dId: discussionId, body: workflowLinkText } + ); + + const comment = result.addDiscussionComment.comment; + core.info(`Successfully created discussion comment with workflow link`); + core.info(`Comment ID: ${comment.id}`); + core.info(`Comment URL: ${comment.url}`); + core.info(`Comment Repo: ${context.repo.owner}/${context.repo.repo}`); + core.setOutput("comment-id", comment.id); + core.setOutput("comment-url", comment.url); + core.setOutput("comment-repo", `${context.repo.owner}/${context.repo.repo}`); return; } diff --git a/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs b/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs index 40e68d4d614..50d19f0ef96 100644 --- a/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs +++ b/pkg/workflow/js/add_reaction_and_edit_comment.test.cjs @@ -516,9 +516,10 @@ describe("add_reaction_and_edit_comment.cjs", () => { expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "testowner/testrepo"); }); - it("should skip comment update for discussion_comment events", async () => { + it("should create new comment for discussion_comment events", async () => { process.env.GITHUB_AW_REACTION = "eyes"; process.env.GITHUB_AW_COMMAND = "test-bot"; // Command workflow + process.env.GITHUB_AW_WORKFLOW_NAME = "Discussion Bot"; global.context.eventName = "discussion_comment"; global.context.payload = { discussion: { number: 10 }, @@ -530,20 +531,51 @@ describe("add_reaction_and_edit_comment.cjs", () => { }; // Mock GraphQL mutation to add reaction - mockGithub.graphql.mockResolvedValueOnce({ - addReaction: { - reaction: { - id: "MDg6UmVhY3Rpb24xMjM0NTY3ODk=", - content: "EYES", + mockGithub.graphql + .mockResolvedValueOnce({ + addReaction: { + reaction: { + id: "MDg6UmVhY3Rpb24xMjM0NTY3ODk=", + content: "EYES", + }, }, - }, - }); + }) + // Mock GraphQL query to get discussion ID for comment creation + .mockResolvedValueOnce({ + repository: { + discussion: { + id: "D_kwDOABcD1M4AaBbC", + }, + }, + }) + // Mock GraphQL mutation to add comment + .mockResolvedValueOnce({ + addDiscussionComment: { + comment: { + id: "DC_kwDOABcD1M4AaBbE", + url: "https://github.com/testowner/testrepo/discussions/10#discussioncomment-789", + }, + }, + }); // Execute the script await eval(`(async () => { ${reactionScript} })()`); - // Verify that comment update was skipped with appropriate message - expect(mockCore.info).toHaveBeenCalledWith("Updating discussion comments is not supported by GitHub's GraphQL API"); + // Verify comment was created + expect(mockGithub.graphql).toHaveBeenCalledWith( + expect.stringContaining("addDiscussionComment"), + expect.objectContaining({ + dId: "D_kwDOABcD1M4AaBbC", + body: expect.stringContaining("Agentic [Discussion Bot]"), + }) + ); + + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "DC_kwDOABcD1M4AaBbE"); + expect(mockCore.setOutput).toHaveBeenCalledWith( + "comment-url", + "https://github.com/testowner/testrepo/discussions/10#discussioncomment-789" + ); + expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "testowner/testrepo"); }); }); From 0aa083db85c2af1d34fa1a992c7b02620049ca48 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 16 Oct 2025 19:25:35 +0000 Subject: [PATCH 5/5] Add changeset for add_reaction job updates --- .changeset/patch-add-reaction-always-create-comments.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/patch-add-reaction-always-create-comments.md diff --git a/.changeset/patch-add-reaction-always-create-comments.md b/.changeset/patch-add-reaction-always-create-comments.md new file mode 100644 index 00000000000..b0aec2db7e9 --- /dev/null +++ b/.changeset/patch-add-reaction-always-create-comments.md @@ -0,0 +1,5 @@ +--- +"gh-aw": patch +--- + +Update add_reaction job to always create new comments and add comment-repo output