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

Function buildAwContext

actions/setup/js/aw_context.cjs:248–358  ·  view source on GitHub ↗

* Builds the aw_context object that identifies the calling workflow run. * This metadata is injected into dispatched workflows that declare an * aw_context input, allowing them to trace back to their caller and * resolve the current item (issue, pull request, discussion, check, etc.) * that trig

()

Source from the content-addressed store, hash-verified

246 * `false` in all other cases.
247 */
248function buildAwContext() {
249 const { item_type, item_number, comment_id, comment_node_id } = resolveItemContext(context.payload);
250 const workflowRef = process.env.GITHUB_WORKFLOW_REF ?? "";
251 const currentRepo = `${context.repo.owner}/${context.repo.repo}`;
252 const currentRunId = String(process.env.GITHUB_RUN_ID ?? context.runId ?? "");
253 const currentRunAttempt = String(process.env.GITHUB_RUN_ATTEMPT ?? "1");
254 const currentHopId = buildWorkflowCallId(currentRunId, currentRunAttempt, workflowRef);
255 const inheritedContext = readInboundAwContext(context.payload);
256 const inheritedHopId = typeof inheritedContext?.hop_id === "string" ? inheritedContext.hop_id.trim() : typeof inheritedContext?.workflow_call_id === "string" ? inheritedContext.workflow_call_id.trim() : "";
257 const parentHopId = typeof inheritedContext?.parent_hop_id === "string" && inheritedContext.parent_hop_id.trim() ? inheritedContext.parent_hop_id.trim() : inheritedHopId;
258 const episodeId = typeof inheritedContext?.episode_id === "string" && inheritedContext.episode_id.trim() ? inheritedContext.episode_id.trim() : inheritedHopId || currentHopId;
259 const originEvent =
260 typeof inheritedContext?.origin_event === "string" && inheritedContext.origin_event.trim()
261 ? inheritedContext.origin_event.trim()
262 : typeof inheritedContext?.event_type === "string" && inheritedContext.event_type.trim()
263 ? inheritedContext.event_type.trim()
264 : (context.eventName ?? "");
265 const rootRepo =
266 typeof inheritedContext?.root_repo === "string" && inheritedContext.root_repo.trim()
267 ? inheritedContext.root_repo.trim()
268 : typeof inheritedContext?.repo === "string" && inheritedContext.repo.trim()
269 ? inheritedContext.repo.trim()
270 : currentRepo;
271 const rootWorkflowId =
272 typeof inheritedContext?.root_workflow_id === "string" && inheritedContext.root_workflow_id.trim()
273 ? inheritedContext.root_workflow_id.trim()
274 : typeof inheritedContext?.workflow_id === "string" && inheritedContext.workflow_id.trim()
275 ? inheritedContext.workflow_id.trim()
276 : workflowRef;
277 const rootRunId =
278 typeof inheritedContext?.root_run_id === "string" && inheritedContext.root_run_id.trim()
279 ? inheritedContext.root_run_id.trim()
280 : typeof inheritedContext?.run_id === "string" && inheritedContext.run_id.trim()
281 ? inheritedContext.run_id.trim()
282 : currentRunId;
283 const assignments = readExperimentAssignments();
284 const experimentAssignments = assignments ? JSON.stringify(assignments) : "";
285
286 // Compute allow_bot_authored_trigger_comment ahead of the object.
287 // True when the triggering event is issue_comment:edited, the comment was authored
288 // by a GitHub App bot (login ends with "[bot]"), and the editor (actor) differs from
289 // the comment author — the bot-posted-menu / user-checks-box pattern.
290 const isIssueCommentEdited = context.eventName === "issue_comment" && context.payload?.action === "edited";
291 const triggerCommentAuthor = context.payload?.comment?.user?.login;
292 const triggerCommentByBot = typeof triggerCommentAuthor === "string" && triggerCommentAuthor.endsWith("[bot]");
293 const allowBotAuthoredTriggerComment = isIssueCommentEdited && triggerCommentByBot && triggerCommentAuthor !== (context.actor ?? "");
294
295 return {
296 repo: currentRepo,
297 run_id: String(context.runId ?? ""),
298 run_attempt: currentRunAttempt,
299 // GITHUB_WORKFLOW_REF provides the full workflow file path including the ref,
300 // e.g. "owner/repo/.github/workflows/dispatcher.yml@refs/heads/main"
301 workflow_id: workflowRef,
302 // episode_id identifies the full automation session across workflow hops.
303 episode_id: episodeId,
304 // hop_id uniquely identifies this specific workflow invocation.
305 hop_id: currentHopId,

Callers 5

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 4

resolveItemContextFunction · 0.85
buildWorkflowCallIdFunction · 0.85
readInboundAwContextFunction · 0.85

Tested by

no test coverage detected