diff --git a/actions/setup/js/add_workflow_run_comment.cjs b/actions/setup/js/add_workflow_run_comment.cjs index f22cf860f0a..b1e46637e81 100644 --- a/actions/setup/js/add_workflow_run_comment.cjs +++ b/actions/setup/js/add_workflow_run_comment.cjs @@ -25,6 +25,7 @@ const EVENT_TYPE_DESCRIPTIONS = { issues: "issue", pull_request: "pull request", pull_request_comment: "pull request comment", + pull_request_review: "pull request review", issue_comment: "issue comment", pull_request_review_comment: "pull request review comment", discussion: "discussion", @@ -290,6 +291,7 @@ async function createOrReuseStatusComment(rawContext = context) { case "pull_request": case "pull_request_comment": + case "pull_request_review": case "pull_request_review_comment": { const number = payload?.pull_request?.number; if (!number) { diff --git a/actions/setup/js/add_workflow_run_comment.test.cjs b/actions/setup/js/add_workflow_run_comment.test.cjs index 245a584b410..de9f68cc070 100644 --- a/actions/setup/js/add_workflow_run_comment.test.cjs +++ b/actions/setup/js/add_workflow_run_comment.test.cjs @@ -657,6 +657,44 @@ describe("add_workflow_run_comment", () => { }); }); + describe("main() - pull_request_review event", () => { + it("should create comment on the pull request", async () => { + global.context = { + eventName: "pull_request_review", + runId: 12345, + repo: { owner: "testowner", repo: "testrepo" }, + payload: { + pull_request: { number: 303 }, + repository: { html_url: "https://github.com/testowner/testrepo" }, + }, + }; + + await runScript(); + + expect(mockGithub.request).toHaveBeenCalledWith( + expect.stringContaining("POST /repos/testowner/testrepo/issues/303/comments"), + expect.objectContaining({ + body: expect.any(String), + }) + ); + expect(mockCore.setFailed).not.toHaveBeenCalled(); + }); + + it("should fail when PR number is missing in pull_request_review event", async () => { + global.context = { + eventName: "pull_request_review", + runId: 12345, + repo: { owner: "testowner", repo: "testrepo" }, + payload: {}, + }; + + await runScript(); + + expect(mockCore.setFailed).toHaveBeenCalledWith(`${ERR_NOT_FOUND}: Pull request number not found in event payload`); + expect(mockGithub.request).not.toHaveBeenCalled(); + }); + }); + describe("main() - discussion event", () => { it("should create GraphQL comment on a discussion", async () => { global.context = {