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

Method UnmarshalJSON

pkg/workflow/templatables.go:147–167  ·  view source on GitHub ↗

UnmarshalJSON allows TemplatableBool to accept both JSON booleans and JSON strings that are GitHub Actions expressions.

(data []byte)

Source from the content-addressed store, hash-verified

145// UnmarshalJSON allows TemplatableBool to accept both JSON booleans and JSON
146// strings that are GitHub Actions expressions.
147func (t *TemplatableBool) UnmarshalJSON(data []byte) error {
148 var b bool
149 if err := json.Unmarshal(data, &b); err == nil {
150 if b {
151 *t = TemplatableBool("true")
152 } else {
153 *t = TemplatableBool("false")
154 }
155 return nil
156 }
157
158 var s string
159 if err := json.Unmarshal(data, &s); err != nil {
160 return fmt.Errorf("%s, got %s", templatableBoolErrorExample, data)
161 }
162 if !isExpression(s) {
163 return fmt.Errorf("%s, got string %q", templatableBoolErrorExample, s)
164 }
165 *t = TemplatableBool(s)
166 return nil
167}
168
169// UnmarshalYAML allows TemplatableBool to accept both YAML booleans and GitHub
170// Actions expression strings.

Callers

nothing calls this directly

Calls 3

TemplatableBoolTypeAlias · 0.85
isExpressionFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected