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

Function preprocessIntFieldAsString

pkg/workflow/config_preprocessing.go:54–87  ·  view source on GitHub ↗

preprocessIntFieldAsString converts the value of an integer config field to a string before YAML unmarshaling. This lets struct fields typed as *string accept both literal integer values and GitHub Actions expression strings (e.g. "${{ inputs.max-issues }}"). If the value is an int, int64, float64,

(configData map[string]any, fieldName string, debugLog *logger.Logger)

Source from the content-addressed store, hash-verified

52// with "${{" and ends with "}}"); any other free-form string is rejected
53// and an error is returned.
54func preprocessIntFieldAsString(configData map[string]any, fieldName string, debugLog *logger.Logger) error {
55 if configData == nil {
56 return nil
57 }
58 if val, exists := configData[fieldName]; exists {
59 switch v := val.(type) {
60 case int:
61 configData[fieldName] = strconv.Itoa(v)
62 if debugLog != nil {
63 debugLog.Printf("Converted %s int to string before unmarshaling", fieldName)
64 }
65 case int64:
66 configData[fieldName] = strconv.FormatInt(v, 10)
67 if debugLog != nil {
68 debugLog.Printf("Converted %s int64 to string before unmarshaling", fieldName)
69 }
70 case float64:
71 configData[fieldName] = strconv.Itoa(int(v))
72 if debugLog != nil {
73 debugLog.Printf("Converted %s float64 to string before unmarshaling", fieldName)
74 }
75 case uint64:
76 configData[fieldName] = strconv.FormatUint(v, 10)
77 if debugLog != nil {
78 debugLog.Printf("Converted %s uint64 to string before unmarshaling", fieldName)
79 }
80 case string:
81 if !isExpression(v) {
82 return fmt.Errorf("field %q must be an integer or a GitHub Actions expression (e.g. '${{ inputs.max }}'), got string %q", fieldName, v)
83 }
84 }
85 }
86 return nil
87}
88
89// preprocessStringArrayFieldAsTemplatable handles a string-array config field that also
90// accepts a GitHub Actions expression string (e.g. "${{ inputs.labels }}").

Calls 3

isExpressionFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected