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

Function buildCommentBody

actions/setup/js/add_workflow_run_comment.cjs:351–381  ·  view source on GitHub ↗

* Build the comment body text for a workflow run link. * Sanitizes the content and appends all required markers. * @param {string} eventName - The event type * @param {string} runUrl - The URL of the workflow run * @param {string} [workflowNameOverride] - Optional dispatched workflow name overri

(eventName, runUrl, workflowNameOverride)

Source from the content-addressed store, hash-verified

349 * @returns {string} The assembled comment body
350 */
351function buildCommentBody(eventName, runUrl, workflowNameOverride) {
352 // Whitespace-only overrides are treated as absent and fall back to env defaults.
353 const normalizedWorkflowNameOverride = workflowNameOverride?.trim();
354 const workflowName = normalizedWorkflowNameOverride || process.env.GH_AW_WORKFLOW_NAME || process.env.GITHUB_WORKFLOW || "Workflow";
355 const eventTypeDescription = EVENT_TYPE_DESCRIPTIONS[eventName] ?? "event";
356
357 // Sanitize before adding markers (defense in depth for custom message templates)
358 let body = sanitizeContent(getRunStartedMessage({ workflowName, runUrl, eventType: eventTypeDescription }));
359
360 // Add lock notice if lock-for-agent is enabled for issues or issue_comment
361 if (process.env.GH_AW_LOCK_FOR_AGENT === "true" && (eventName === "issues" || eventName === "issue_comment")) {
362 body += "\n\n🔒 This issue has been locked while the workflow is running to prevent concurrent modifications.";
363 }
364
365 // Add workflow-id marker for hide-older-comments feature
366 const workflowId = process.env.GITHUB_WORKFLOW || "";
367 if (workflowId) {
368 body += `\n\n${generateWorkflowIdMarker(workflowId)}`;
369 }
370
371 // Add tracker-id marker for backwards compatibility
372 const trackerId = process.env.GH_AW_TRACKER_ID || "";
373 if (trackerId) {
374 body += `\n\n<!-- gh-aw-tracker-id: ${trackerId} -->`;
375 }
376
377 // Identify this as a reaction comment (prevents it from being hidden by hide-older-comments)
378 body += `\n\n<!-- gh-aw-comment-type: reaction -->`;
379
380 return body;
381}
382
383/**
384 * Post a GraphQL comment to a discussion, optionally as a threaded reply.

Callers 2

Calls 3

sanitizeContentFunction · 0.85
getRunStartedMessageFunction · 0.85
generateWorkflowIdMarkerFunction · 0.85

Tested by

no test coverage detected