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

Method buildHandlerManagerStep

pkg/workflow/compiler_safe_outputs_steps.go:87–301  ·  view source on GitHub ↗

buildHandlerManagerStep builds a single step that uses the safe output handler manager to dispatch messages to appropriate handlers. This replaces multiple individual steps with a single dispatcher step that processes all safe output types.

(data *WorkflowData)

Source from the content-addressed store, hash-verified

85// to dispatch messages to appropriate handlers. This replaces multiple individual steps
86// with a single dispatcher step that processes all safe output types.
87func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) ([]string, error) {
88 consolidatedSafeOutputsStepsLog.Print("Building handler manager step")
89
90 var steps []string
91
92 // Add per-handler GitHub App token minting steps before the handler manager step.
93 // These run before the main handler step so the minted token expressions (e.g.
94 // ${{ steps.create-check-run-app-token.outputs.token }}) are resolved at runtime.
95 if data.SafeOutputs != nil && data.SafeOutputs.CreateCheckRun != nil && data.SafeOutputs.CreateCheckRun.GitHubApp != nil {
96 consolidatedSafeOutputsStepsLog.Print("Adding per-handler GitHub App token minting step for create-check-run")
97 permissions := NewPermissionsContentsReadChecksWrite()
98 for _, step := range c.buildGitHubAppTokenMintStep(data.SafeOutputs.CreateCheckRun.GitHubApp, permissions, "") {
99 steps = append(steps, replaceStepID(step, "safe-outputs-app-token", "create-check-run-app-token"))
100 }
101 }
102
103 // Step name and metadata
104 steps = append(steps, " - name: Process Safe Outputs\n")
105 steps = append(steps, " id: process_safe_outputs\n")
106 steps = append(steps, fmt.Sprintf(" uses: %s\n", getCachedActionPin("actions/github-script", data)))
107
108 // Environment variables
109 steps = append(steps, " env:\n")
110 steps = append(steps, " GH_AW_AGENT_OUTPUT: ${{ steps.setup-agent-output-env.outputs.GH_AW_AGENT_OUTPUT }}\n")
111 steps = append(steps, " GH_AW_COMMENT_ID: ${{ needs.activation.outputs.comment_id }}\n")
112
113 // Add allowed domains configuration for URL sanitization in safe output handlers.
114 // Without this, sanitizeContent() in safe_output_handler_manager.cjs only allows
115 // default GitHub domains, causing user-configured allowed domains to be redacted.
116 var domainsStr string
117 if data.SafeOutputs != nil && len(data.SafeOutputs.AllowedDomains) > 0 {
118 // allowed-domains: additional domains unioned with engine/network base set; supports ecosystem identifiers
119 expanded, err := c.computeExpandedAllowedDomainsForSanitization(data)
120 if err != nil {
121 return nil, err
122 }
123 domainsStr = expanded
124 } else {
125 computed, err := c.computeAllowedDomainsForSanitization(data)
126 if err != nil {
127 return nil, err
128 }
129 domainsStr = computed
130 }
131 if domainsStr != "" {
132 steps = append(steps, fmt.Sprintf(" GH_AW_ALLOWED_DOMAINS: %q\n", domainsStr))
133 }
134 if data.SafeOutputs != nil && data.SafeOutputs.URLs != "" {
135 steps = append(steps, fmt.Sprintf(" GH_AW_SAFE_OUTPUTS_URLS: %q\n", data.SafeOutputs.URLs))
136 }
137 // Pass GitHub server/API URLs so buildAllowedDomains() can add GHES domains dynamically
138 steps = append(steps, " GITHUB_SERVER_URL: ${{ github.server_url }}\n")
139 steps = append(steps, " GITHUB_API_URL: ${{ github.api_url }}\n")
140
141 // Note: The project handler manager has been removed.
142 // All project-related operations are now handled by the unified handler.
143
144 // Add GH_AW_SAFE_OUTPUT_JOBS so the handler manager knows which message types are