Skip to content

Commit 5604be3

Browse files
authored
Fix append-only-comments for activation comment updates (#11189)
1 parent 7758ad3 commit 5604be3

4 files changed

Lines changed: 266 additions & 22 deletions

File tree

.github/workflows/agentic-campaign-generator.lock.yml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/agentic-campaign-generator.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,35 @@ safe-outputs:
7272
7373
Creating a tracking Project and generating campaign files + orchestrator workflow.
7474
75-
No action needed right now — the [{workflow_name}]({run_url}) will open a pull request and post the link + checklist back on this issue when ready.
75+
No action needed — the [{workflow_name}]({run_url}) will open a pull request and post the link + checklist back on this issue when ready.
7676
7777
> To stop this run: remove the label that started it.
78-
> Docs: https://githubnext.github.io/gh-aw/guides/campaigns/getting-started/"
78+
79+
> **Docs**: https://githubnext.github.io/gh-aw/guides/campaigns/getting-started/"
7980
run-success: "### :white_check_mark: Campaign setup complete
8081
8182
Tracking Project created and pull request with generated campaign files is ready.
8283
83-
Next steps:
84-
- Review + merge the PR
85-
- Run the campaign from the Actions tab
84+
**Next steps**: Review + merge the PR, then run the campaign from the Actions tab.
8685
87-
> Docs: https://githubnext.github.io/gh-aw/guides/campaigns/getting-started/"
86+
> **Docs**: https://githubnext.github.io/gh-aw/guides/campaigns/getting-started/"
8887
run-failure: "### :x: Campaign setup {status}
8988
90-
Common causes:
89+
**Common causes**:
90+
9191
- `GH_AW_PROJECT_GITHUB_TOKEN` is missing or invalid
92+
9293
- Token lacks access to GitHub Projects
9394
94-
Action required:
95+
**Action required**:
96+
9597
- Fix the first error in the logs
98+
9699
- Re-apply the label to re-run
97100
98-
> Troubleshooting: https://githubnext.github.io/gh-aw/guides/campaigns/flow/#when-something-goes-wrong
99-
> Docs: https://githubnext.github.io/gh-aw/guides/campaigns/getting-started/"
101+
> **Troubleshooting**: https://githubnext.github.io/gh-aw/guides/campaigns/flow/#when-something-goes-wrong
102+
103+
> **Docs**: https://githubnext.github.io/gh-aw/guides/campaigns/getting-started/"
100104
timeout-minutes: 10
101105
---
102106

actions/setup/js/update_activation_comment.cjs

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// <reference types="@actions/github-script" />
33

44
const { getErrorMessage } = require("./error_helpers.cjs");
5+
const { getMessages } = require("./messages_core.cjs");
56

67
/**
78
* Update the activation comment with a link to the created pull request or issue
@@ -44,13 +45,9 @@ async function updateActivationCommentWithMessage(github, context, core, message
4445
const commentId = process.env.GH_AW_COMMENT_ID;
4546
const commentRepo = process.env.GH_AW_COMMENT_REPO;
4647

47-
// If no comment was created in activation, skip updating
48-
if (!commentId) {
49-
core.info("No activation comment to update (GH_AW_COMMENT_ID not set)");
50-
return;
51-
}
52-
53-
core.info(`Updating activation comment ${commentId}`);
48+
// Check if append-only-comments is enabled
49+
const messagesConfig = getMessages();
50+
const appendOnlyComments = messagesConfig?.appendOnlyComments === true;
5451

5552
// Parse comment repo (format: "owner/repo") with validation
5653
let repoOwner = context.repo.owner;
@@ -65,6 +62,98 @@ async function updateActivationCommentWithMessage(github, context, core, message
6562
}
6663
}
6764

65+
// Append-only mode: create a new comment instead of updating the activation comment
66+
if (appendOnlyComments) {
67+
core.info("Append-only-comments enabled: creating a new comment");
68+
try {
69+
const eventName = context.eventName;
70+
71+
// Discussions: create a new discussion comment (threaded reply for discussion_comment)
72+
if (eventName === "discussion" || eventName === "discussion_comment") {
73+
const discussionNumber = context.payload?.discussion?.number;
74+
if (!discussionNumber) {
75+
core.warning("Unable to determine discussion number for append-only comment; skipping");
76+
return;
77+
}
78+
79+
const { repository } = await github.graphql(
80+
`
81+
query($owner: String!, $repo: String!, $num: Int!) {
82+
repository(owner: $owner, name: $repo) {
83+
discussion(number: $num) {
84+
id
85+
}
86+
}
87+
}`,
88+
{ owner: repoOwner, repo: repoName, num: discussionNumber }
89+
);
90+
91+
const discussionId = repository?.discussion?.id;
92+
if (!discussionId) {
93+
core.warning("Unable to resolve discussion id for append-only comment; skipping");
94+
return;
95+
}
96+
97+
const replyToId = eventName === "discussion_comment" ? context.payload?.comment?.node_id : null;
98+
const mutation = replyToId
99+
? `mutation($dId: ID!, $body: String!, $replyToId: ID!) {
100+
addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
101+
comment { id url }
102+
}
103+
}`
104+
: `mutation($dId: ID!, $body: String!) {
105+
addDiscussionComment(input: { discussionId: $dId, body: $body }) {
106+
comment { id url }
107+
}
108+
}`;
109+
110+
const variables = replyToId ? { dId: discussionId, body: message, replyToId } : { dId: discussionId, body: message };
111+
const result = await github.graphql(mutation, variables);
112+
const created = result?.addDiscussionComment?.comment;
113+
const successMessage = label ? `Successfully created append-only discussion comment with ${label} link` : "Successfully created append-only discussion comment";
114+
core.info(successMessage);
115+
if (created?.id) core.info(`Comment ID: ${created.id}`);
116+
if (created?.url) core.info(`Comment URL: ${created.url}`);
117+
return;
118+
}
119+
120+
// Issues/PRs: determine issue number from event payload and create a new issue comment
121+
const issueNumber = context.payload?.issue?.number || context.payload?.pull_request?.number;
122+
if (!issueNumber) {
123+
core.warning("Unable to determine issue/PR number for append-only comment; skipping");
124+
return;
125+
}
126+
127+
const response = await github.request("POST /repos/{owner}/{repo}/issues/{issue_number}/comments", {
128+
owner: repoOwner,
129+
repo: repoName,
130+
issue_number: issueNumber,
131+
body: message,
132+
headers: {
133+
Accept: "application/vnd.github+json",
134+
},
135+
});
136+
137+
const successMessage = label ? `Successfully created append-only comment with ${label} link` : "Successfully created append-only comment";
138+
core.info(successMessage);
139+
if (response?.data?.id) core.info(`Comment ID: ${response.data.id}`);
140+
if (response?.data?.html_url) core.info(`Comment URL: ${response.data.html_url}`);
141+
return;
142+
} catch (error) {
143+
// Don't fail the workflow if we can't create the comment - just log a warning
144+
core.warning(`Failed to create append-only comment: ${getErrorMessage(error)}`);
145+
return;
146+
}
147+
}
148+
149+
// Standard mode: update the existing activation comment
150+
// If no comment was created in activation, skip updating
151+
if (!commentId) {
152+
core.info("No activation comment to update (GH_AW_COMMENT_ID not set)");
153+
return;
154+
}
155+
156+
core.info(`Updating activation comment ${commentId}`);
68157
core.info(`Updating comment in ${repoOwner}/${repoName}`);
69158

70159
// Check if this is a discussion comment (GraphQL node ID format)

0 commit comments

Comments
 (0)