UnmarshalJSON allows TemplatableBool to accept both JSON booleans and JSON strings that are GitHub Actions expressions.
(data []byte)
| 145 | // UnmarshalJSON allows TemplatableBool to accept both JSON booleans and JSON |
| 146 | // strings that are GitHub Actions expressions. |
| 147 | func (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. |
nothing calls this directly
no test coverage detected