MCPcopy Create free account
hub / github.com/github/gh-aw / updateReusableStatusComment

Function updateReusableStatusComment

actions/setup/js/add_workflow_run_comment.cjs:191–228  ·  view source on GitHub ↗

* @param {ReusableStatusComment} reusableComment * @param {{ * source: "native" | "workflow_dispatch" | "repository_dispatch"; * eventName: string; * eventPayload: any; * workflowRepo: { owner: string, repo: string }; * eventRepo: { owner: string, repo: string }; * }} invocationCont

(reusableComment, invocationContext, rawContext)

Source from the content-addressed store, hash-verified

189 * @returns {Promise<string>}
190 */
191async function updateReusableStatusComment(reusableComment, invocationContext, rawContext) {
192 const awContext = extractAwContextFromPayload(rawContext?.payload);
193 const dispatchedRunUrl = readAwContextString(awContext, "dispatched_run_url");
194 const dispatchedWorkflowName = readAwContextString(awContext, "dispatched_workflow_name");
195 const runUrl = dispatchedRunUrl || buildWorkflowRunUrl(rawContext, invocationContext.workflowRepo);
196 const commentBody = buildCommentBody(invocationContext.eventName, runUrl, dispatchedWorkflowName || undefined);
197
198 // Discussion comments use GraphQL node IDs and a dedicated update mutation.
199 if (reusableComment.id.startsWith("DC_")) {
200 const result = await github.graphql(
201 `
202 mutation($commentId: ID!, $body: String!) {
203 updateDiscussionComment(input: { commentId: $commentId, body: $body }) {
204 comment { id url }
205 }
206 }`,
207 { commentId: reusableComment.id, body: commentBody }
208 );
209 const updatedUrl = result?.updateDiscussionComment?.comment?.url;
210 return typeof updatedUrl === "string" && updatedUrl.trim() ? updatedUrl : reusableComment.url;
211 }
212
213 const commentRepo = reusableComment.repo || invocationContext.eventRepo;
214 const numericCommentId = Number(reusableComment.id);
215 if (!Number.isInteger(numericCommentId) || numericCommentId <= 0) {
216 throw new Error(`${ERR_VALIDATION}: Reusable status comment ID must be a positive integer (received "${reusableComment.id}")`);
217 }
218
219 const response = await github.request("PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", {
220 owner: commentRepo.owner,
221 repo: commentRepo.repo,
222 comment_id: numericCommentId,
223 body: commentBody,
224 headers: { Accept: "application/vnd.github+json" },
225 });
226 const updatedUrl = response?.data?.html_url;
227 return typeof updatedUrl === "string" && updatedUrl.trim() ? updatedUrl : reusableComment.url;
228}
229
230/**
231 * Add a comment with a workflow run link to the triggering item.

Callers 1

Calls 4

readAwContextStringFunction · 0.85
buildWorkflowRunUrlFunction · 0.85
buildCommentBodyFunction · 0.70

Tested by

no test coverage detected