-
Notifications
You must be signed in to change notification settings - Fork 434
Centralized slash-command status comments now update to dispatched workflow run #40928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,12 @@ describe("add_workflow_run_comment", () => { | |
| }); | ||
|
|
||
| it("reuses an existing status comment from client_payload aw_context", async () => { | ||
| mockGithub.request.mockResolvedValueOnce({ | ||
| data: { | ||
| id: 67890, | ||
| html_url: "https://github.com/statusowner/statusrepo/issues/789#issuecomment-67890", | ||
| }, | ||
| }); | ||
| global.context = { | ||
| eventName: "repository_dispatch", | ||
| runId: 12345, | ||
|
|
@@ -233,16 +239,30 @@ describe("add_workflow_run_comment", () => { | |
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockGithub.request).not.toHaveBeenCalled(); | ||
| expect(mockGithub.request).toHaveBeenCalledWith( | ||
| "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", | ||
| expect.objectContaining({ | ||
| owner: "statusowner", | ||
| repo: "statusrepo", | ||
| comment_id: 67890, | ||
| body: expect.stringContaining("https://github.com/workflowowner/workflowrepo/actions/runs/12345"), | ||
| }) | ||
| ); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/statusowner/statusrepo/issues/789#issuecomment-67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "statusowner/statusrepo"); | ||
| expect(mockCore.info).toHaveBeenCalledWith("Reusing existing status comment outputs"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("main() - workflow_dispatch aw_context reuse", () => { | ||
| it("reuses an existing status comment from aw_context", async () => { | ||
| mockGithub.request.mockResolvedValueOnce({ | ||
| data: { | ||
| id: 67890, | ||
| html_url: "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890", | ||
| }, | ||
| }); | ||
| global.context = { | ||
| eventName: "workflow_dispatch", | ||
| runId: 12345, | ||
|
|
@@ -263,14 +283,28 @@ describe("add_workflow_run_comment", () => { | |
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockGithub.request).not.toHaveBeenCalled(); | ||
| expect(mockGithub.request).toHaveBeenCalledWith( | ||
| "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", | ||
| expect.objectContaining({ | ||
| owner: "targetowner", | ||
| repo: "targetrepo", | ||
| comment_id: 67890, | ||
| body: expect.stringContaining("https://github.com/workflowowner/workflowrepo/actions/runs/12345"), | ||
| }) | ||
| ); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "targetowner/targetrepo"); | ||
| expect(mockCore.setFailed).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("reuses an existing status comment from camelCase awContext", async () => { | ||
| mockGithub.request.mockResolvedValueOnce({ | ||
| data: { | ||
| id: 67890, | ||
| html_url: "https://github.com/statusowner/statusrepo/issues/789#issuecomment-67890", | ||
| }, | ||
| }); | ||
| global.context = { | ||
| eventName: "workflow_dispatch", | ||
| runId: 12345, | ||
|
|
@@ -292,8 +326,113 @@ describe("add_workflow_run_comment", () => { | |
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockGithub.request).not.toHaveBeenCalled(); | ||
| expect(mockGithub.request).toHaveBeenCalledWith( | ||
| "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", | ||
| expect.objectContaining({ | ||
| owner: "statusowner", | ||
| repo: "statusrepo", | ||
| comment_id: 67890, | ||
| body: expect.stringContaining("https://github.com/workflowowner/workflowrepo/actions/runs/12345"), | ||
| }) | ||
| ); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/statusowner/statusrepo/issues/789#issuecomment-67890"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-repo", "statusowner/statusrepo"); | ||
| expect(mockCore.info).toHaveBeenCalledWith("Reusing existing status comment outputs"); | ||
| expect(mockCore.setFailed).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("updates reusable discussion comments via GraphQL", async () => { | ||
| mockGithub.graphql.mockResolvedValue({ | ||
| updateDiscussionComment: { | ||
| comment: { | ||
| id: "DC_kwDOReusable123", | ||
| url: "https://github.com/targetowner/targetrepo/discussions/789#discussioncomment-67890", | ||
| }, | ||
| }, | ||
| }); | ||
| global.context = { | ||
| eventName: "workflow_dispatch", | ||
| runId: 12345, | ||
| repo: { owner: "workflowowner", repo: "workflowrepo" }, | ||
| payload: { | ||
| inputs: { | ||
| aw_context: JSON.stringify({ | ||
| repo: "targetowner/targetrepo", | ||
| event_type: "discussion_comment", | ||
| item_type: "discussion", | ||
| item_number: 789, | ||
| status_comment_id: "DC_kwDOReusable123", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnose] Consider either adding a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handled in |
||
| }), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockGithub.graphql).toHaveBeenCalledWith( | ||
| expect.stringContaining("updateDiscussionComment"), | ||
| expect.objectContaining({ | ||
| commentId: "DC_kwDOReusable123", | ||
| body: expect.stringContaining("https://github.com/workflowowner/workflowrepo/actions/runs/12345"), | ||
| }) | ||
| ); | ||
| expect(mockGithub.request).not.toHaveBeenCalled(); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-id", "DC_kwDOReusable123"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/targetowner/targetrepo/discussions/789#discussioncomment-67890"); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] The non-fatal fallback path in This is the core safety net of the non-fatal design: if 💡 Suggested sibling testit('falls back to stale URL and warns when PATCH throws', async () => {
mockGithub.request.mockRejectedValueOnce(new Error('network timeout'));
global.context = {
eventName: 'workflow_dispatch',
runId: 12345,
repo: { owner: 'workflowowner', repo: 'workflowrepo' },
payload: {
inputs: {
aw_context: JSON.stringify({
repo: 'targetowner/targetrepo',
event_type: 'issue_comment',
item_type: 'issue',
item_number: 789,
status_comment_id: 67890,
status_comment_url: 'https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890',
}),
},
},
};
await runScript();
expect(mockCore.warning).toHaveBeenCalledWith(
expect.stringContaining('Failed to update reusable status comment body')
);
expect(mockCore.setOutput).toHaveBeenCalledWith(
'comment-url',
'https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890'
);
expect(mockCore.setFailed).not.toHaveBeenCalled();
});This makes the non-fatal contract explicit and regression-proof.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in |
||
|
|
||
| it("warns and falls back to stale URL when reusable issue-comment update fails", async () => { | ||
| mockGithub.request.mockRejectedValueOnce(new Error("network timeout")); | ||
| global.context = { | ||
| eventName: "workflow_dispatch", | ||
| runId: 12345, | ||
| repo: { owner: "workflowowner", repo: "workflowrepo" }, | ||
| payload: { | ||
| inputs: { | ||
| aw_context: JSON.stringify({ | ||
| repo: "targetowner/targetrepo", | ||
| event_type: "issue_comment", | ||
| item_type: "issue", | ||
| item_number: 789, | ||
| status_comment_id: 67890, | ||
| status_comment_url: "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890", | ||
| }), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("Failed to update reusable status comment body")); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890"); | ||
| expect(mockCore.setFailed).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("warns when reusable comment ID is not a positive integer", async () => { | ||
| global.context = { | ||
| eventName: "workflow_dispatch", | ||
| runId: 12345, | ||
| repo: { owner: "workflowowner", repo: "workflowrepo" }, | ||
| payload: { | ||
| inputs: { | ||
| aw_context: JSON.stringify({ | ||
| repo: "targetowner/targetrepo", | ||
| event_type: "issue_comment", | ||
| item_type: "issue", | ||
| item_number: 789, | ||
| status_comment_id: "67890abc", | ||
| status_comment_url: "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890", | ||
| }), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining(`${ERR_VALIDATION}: Reusable status comment ID must be a positive integer (received "67890abc")`)); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("comment-url", "https://github.com/targetowner/targetrepo/issues/789#issuecomment-67890"); | ||
| expect(mockCore.setFailed).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.