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
2 changes: 2 additions & 0 deletions actions/setup/js/add_workflow_run_comment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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",
Expand Down Expand Up @@ -290,6 +291,7 @@

case "pull_request":
case "pull_request_comment":
case "pull_request_review":
case "pull_request_review_comment": {
const number = payload?.pull_request?.number;
if (!number) {
Expand Down Expand Up @@ -439,7 +441,7 @@
}

// Create a new comment for non-discussion events
const createResponse = await github.request("POST " + endpoint, {

Check warning on line 444 in actions/setup/js/add_workflow_run_comment.cjs

View workflow job for this annotation

GitHub Actions / lint-js

Avoid using a string concatenation expression as the route argument of github.request(). Use the typed placeholder form instead — e.g. github.request("GET /repos/{owner}/{repo}", { owner, repo }) — to preserve typed dispatch and prevent malformed paths

Check warning on line 444 in actions/setup/js/add_workflow_run_comment.cjs

View workflow job for this annotation

GitHub Actions / lint-js

Avoid using a string concatenation expression as the route argument of github.request(). Use the typed placeholder form instead — e.g. github.request("GET /repos/{owner}/{repo}", { owner, repo }) — to preserve typed dispatch and prevent malformed paths
body: commentBody,
headers: { Accept: "application/vnd.github+json" },
});
Expand Down
38 changes: 38 additions & 0 deletions actions/setup/js/add_workflow_run_comment.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading