Skip to content

Commit b9dd702

Browse files
authored
Do not post "PR created" status comment on the created PR itself (#18130)
1 parent 189d3e2 commit b9dd702

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

actions/setup/js/update_activation_comment.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function updateActivationComment(github, context, core, itemUrl, itemNumbe
3636
const body = itemType === "issue" ? getIssueCreatedMessage({ itemNumber, itemUrl }) : getPullRequestCreatedMessage({ itemNumber, itemUrl });
3737
const footerMessage = getFooterMessage({ workflowName, runUrl });
3838
const linkMessage = `\n\n${body}\n\n${footerMessage}\n\n${generateXMLMarker(workflowName, runUrl)}`;
39-
await updateActivationCommentWithMessage(github, context, core, linkMessage, itemLabel, { targetIssueNumber: itemNumber });
39+
await updateActivationCommentWithMessage(github, context, core, linkMessage, itemLabel, {});
4040
}
4141

4242
/**

actions/setup/js/update_activation_comment.test.cjs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,32 @@ describe("update_activation_comment.cjs", () => {
9090
((createFunctionFromScript = createTestableFunction(scriptContent)),
9191
(mockDependencies = { github: { graphql: vi.fn(), request: vi.fn() }, core: { info: vi.fn(), warning: vi.fn(), setFailed: vi.fn() }, context: { repo: { owner: "testowner", repo: "testrepo" } }, process: { env: {} } }));
9292
}),
93-
it("should create new comment on target PR when GH_AW_COMMENT_ID is not set", async () => {
93+
it("should skip comment when no activation comment ID or triggering context exists", async () => {
9494
mockDependencies.process.env.GH_AW_COMMENT_ID = "";
95+
const { updateActivationComment } = createFunctionFromScript(mockDependencies);
96+
await updateActivationComment(mockDependencies.github, mockDependencies.context, mockDependencies.core, "https://github.com/testowner/testrepo/pull/42", 42);
97+
expect(mockDependencies.core.info).toHaveBeenCalledWith("No activation comment to update (GH_AW_COMMENT_ID not set)");
98+
expect(mockDependencies.github.request).not.toHaveBeenCalled();
99+
}),
100+
it("should create new comment on triggering PR when GH_AW_COMMENT_ID is not set", async () => {
101+
mockDependencies.process.env.GH_AW_COMMENT_ID = "";
102+
mockDependencies.context.payload = { pull_request: { number: 10 } };
95103
mockDependencies.github.request.mockResolvedValue({
96-
data: { id: 789012, html_url: "https://github.com/testowner/testrepo/issues/42#issuecomment-789012" },
104+
data: { id: 789012, html_url: "https://github.com/testowner/testrepo/issues/10#issuecomment-789012" },
97105
});
98106
const { updateActivationComment } = createFunctionFromScript(mockDependencies);
99107
await updateActivationComment(mockDependencies.github, mockDependencies.context, mockDependencies.core, "https://github.com/testowner/testrepo/pull/42", 42);
100-
expect(mockDependencies.core.info).toHaveBeenCalledWith("No activation comment to update (GH_AW_COMMENT_ID not set), creating new comment on #42");
108+
expect(mockDependencies.core.info).toHaveBeenCalledWith("No activation comment to update (GH_AW_COMMENT_ID not set), creating new comment on #10");
101109
expect(mockDependencies.github.request).toHaveBeenCalledWith(
102110
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
103111
expect.objectContaining({
104112
owner: "testowner",
105113
repo: "testrepo",
106-
issue_number: 42,
114+
issue_number: 10,
107115
body: expect.stringContaining("Pull request created: [#42]"),
108116
})
109117
);
110-
expect(mockDependencies.core.info).toHaveBeenCalledWith("Successfully created comment with pull request link on #42");
118+
expect(mockDependencies.core.info).toHaveBeenCalledWith("Successfully created comment with pull request link on #10");
111119
}),
112120
it("should skip update when GH_AW_COMMENT_ID is not set and no target issue number", async () => {
113121
mockDependencies.process.env.GH_AW_COMMENT_ID = "";

0 commit comments

Comments
 (0)