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

Method UnmarshalJSON

pkg/workflow/templatables.go:64–83  ·  view source on GitHub ↗

UnmarshalJSON allows TemplatableInt32 to accept both JSON numbers (integer literals) and JSON strings that are GitHub Actions expressions. Free-form string literals that are not expressions are rejected with an error.

(data []byte)

Source from the content-addressed store, hash-verified

62// literals) and JSON strings that are GitHub Actions expressions.
63// Free-form string literals that are not expressions are rejected with an error.
64func (t *TemplatableInt32) UnmarshalJSON(data []byte) error {
65 // Try a JSON number first (e.g. 30)
66 var n int32
67 if err := json.Unmarshal(data, &n); err == nil {
68 *t = TemplatableInt32(strconv.FormatInt(int64(n), 10))
69 return nil
70 }
71 // Try a JSON string (e.g. "${{ inputs.timeout }}")
72 var s string
73 if err := json.Unmarshal(data, &s); err != nil {
74 templatablesLog.Printf("TemplatableInt32 rejected: not number or string: %s", data)
75 return fmt.Errorf("timeout-minutes must be an integer or a GitHub Actions expression (e.g. '${{ inputs.timeout }}'), got %s", data)
76 }
77 if !isExpression(s) {
78 templatablesLog.Printf("TemplatableInt32 rejected non-expression string: %q", s)
79 return fmt.Errorf("timeout-minutes must be an integer or a GitHub Actions expression (e.g. '${{ inputs.timeout }}'), got string %q", s)
80 }
81 *t = TemplatableInt32(s)
82 return nil
83}
84
85// MarshalJSON emits a JSON number for numeric literals and a JSON string for
86// GitHub Actions expressions.

Callers

nothing calls this directly

Calls 4

TemplatableInt32TypeAlias · 0.85
isExpressionFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected