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

Function addCommentWithWorkflowLink

actions/setup/js/add_workflow_run_comment.cjs:421–448  ·  view source on GitHub ↗

* Add a comment with a workflow run link * @param {string} endpoint - The GitHub API endpoint to create the comment (or special format for discussions) * @param {string} runUrl - The URL of the workflow run * @param {string} eventName - The event type (to determine the comment text) * @param {{

(endpoint, runUrl, eventName, invocationContext = null)

Source from the content-addressed store, hash-verified

419 * }|null} [invocationContext=null] - Invocation context overrides for event payload and repo
420 */
421async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocationContext = null) {
422 const eventPayload = invocationContext?.eventPayload || context.payload;
423 const eventRepo = invocationContext?.eventRepo || context.repo;
424 const commentBody = buildCommentBody(eventName, runUrl);
425
426 if (eventName === "discussion") {
427 // Parse discussion number from special format: "discussion:NUMBER"
428 const discussionNumber = parseInt(endpoint.split(":")[1], 10);
429 return postDiscussionComment(discussionNumber, commentBody, null, eventRepo);
430 }
431
432 if (eventName === "discussion_comment") {
433 // Parse discussion number from special format: "discussion_comment:NUMBER:COMMENT_ID"
434 const discussionNumber = parseInt(endpoint.split(":")[1], 10);
435
436 // GitHub Discussions only supports two nesting levels, so resolve the top-level parent's node ID
437 const commentNodeId = await resolveTopLevelDiscussionCommentId(github, eventPayload?.comment?.node_id);
438 return postDiscussionComment(discussionNumber, commentBody, commentNodeId, eventRepo);
439 }
440
441 // Create a new comment for non-discussion events
442 const createResponse = await github.request("POST " + endpoint, {
443 body: commentBody,
444 headers: { Accept: "application/vnd.github+json" },
445 });
446
447 return setCommentOutputs(createResponse.data.id, createResponse.data.html_url, eventRepo);
448}
449
450module.exports = { main, addCommentWithWorkflowLink, buildCommentBody, postDiscussionComment, createOrReuseStatusComment };

Calls 4

postDiscussionCommentFunction · 0.85
buildCommentBodyFunction · 0.70
setCommentOutputsFunction · 0.70

Tested by 1