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

Function ExtractGitHubContextExpressionsFromValue

pkg/workflow/secret_extraction.go:254–272  ·  view source on GitHub ↗

ExtractGitHubContextExpressionsFromValue extracts all simple ${{ github.X }} expressions from a string value and maps them to their corresponding GitHub Actions runner environment variable names. Only well-known context properties present in gitHubContextEnvVarMap are extracted; nested properties li

(value string)

Source from the content-addressed store, hash-verified

252// - "${{ github.ref_name }}" -> {"GITHUB_REF_NAME": "${{ github.ref_name }}"}
253// - "${{ github.event.issue.title }}" -> {} (not in gitHubContextEnvVarMap, skipped)
254func ExtractGitHubContextExpressionsFromValue(value string) map[string]string {
255 result := make(map[string]string)
256
257 matches := gitHubContextExprPattern.FindAllStringSubmatch(value, -1)
258 for _, match := range matches {
259 if len(match) < 2 {
260 continue
261 }
262 property := match[1]
263 fullExpr := match[0]
264
265 if envVar, known := gitHubContextEnvVarMap[property]; known {
266 result[envVar] = fullExpr
267 secretLog.Printf("Extracted GitHub context expression: %s -> %s", fullExpr, envVar)
268 }
269 }
270
271 return result
272}
273
274// ExtractWorkflowInputExpressionsFromValue extracts simple workflow input expressions from a
275// string value and maps them to deterministic environment variable names.

Calls 1

PrintfMethod · 0.45