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

Method generateEnvVarName

pkg/workflow/expression_extraction.go:389–407  ·  view source on GitHub ↗

generateEnvVarName generates a unique environment variable name for an expression For simple JavaScript property access chains (e.g., "github.event.issue.number"), it generates a pretty name like "GH_AW_GITHUB_EVENT_ISSUE_NUMBER". For complex expressions, it falls back to a hash-based name.

(content string)

Source from the content-addressed store, hash-verified

387// it generates a pretty name like "GH_AW_GITHUB_EVENT_ISSUE_NUMBER".
388// For complex expressions, it falls back to a hash-based name.
389func (e *ExpressionExtractor) generateEnvVarName(content string) string {
390 // Check if the expression is a simple JavaScript property access chain
391 if simpleIdentifierRegex.MatchString(content) {
392 // Convert dots to underscores and uppercase
393 prettyName := strings.ToUpper(strings.ReplaceAll(content, ".", "_"))
394 return "GH_AW_" + prettyName
395 }
396
397 // Fall back to hash-based name for complex expressions
398 // Use SHA256 hash to generate a unique identifier
399 hash := sha256.Sum256([]byte(content))
400 hashStr := hex.EncodeToString(hash[:])
401
402 // Use first 8 characters of hash for brevity
403 shortHash := hashStr[:8]
404
405 // Create environment variable name
406 return "GH_AW_EXPR_" + strings.ToUpper(shortHash)
407}
408
409// ReplaceExpressionsWithEnvVars replaces all ${{ ... }} expressions in the markdown
410// with references to their corresponding environment variables using placeholder format

Calls

no outgoing calls