Skip to content

Commit 820d464

Browse files
Copilotpelikhan
andauthored
feat: add TemplatableInt32.ToValue() helper and use it in ToMap()
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/eb163ff9-7e13-4960-a275-ac6ca9961fa8 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 188e956 commit 820d464

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

pkg/workflow/frontmatter_types.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,7 @@ func (fc *FrontmatterConfig) ToMap() map[string]any {
538538
result["version"] = fc.Version
539539
}
540540
if fc.TimeoutMinutes != nil {
541-
// Return as integer for numeric literals, string for expressions
542-
if fc.TimeoutMinutes.IsExpression() {
543-
result["timeout-minutes"] = fc.TimeoutMinutes.String()
544-
} else {
545-
result["timeout-minutes"] = fc.TimeoutMinutes.IntValue()
546-
}
541+
result["timeout-minutes"] = fc.TimeoutMinutes.ToValue()
547542
}
548543
if fc.Strict != nil {
549544
result["strict"] = *fc.Strict

pkg/workflow/templatables.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ func (t *TemplatableInt32) IntValue() int {
112112
return 0 // expression strings are not evaluable at compile time
113113
}
114114

115+
// ToValue returns the native Go value for use in map literals and JSON output:
116+
// - an int for numeric literals (e.g. 30)
117+
// - a string for GitHub Actions expressions (e.g. "${{ inputs.timeout }}")
118+
//
119+
// This is the canonical helper for producing a map[string]any entry;
120+
// callers should prefer it over calling IsExpression + IntValue/String manually.
121+
func (t *TemplatableInt32) ToValue() any {
122+
if t.IsExpression() {
123+
return string(*t)
124+
}
125+
if n, err := strconv.Atoi(string(*t)); err == nil {
126+
return n
127+
}
128+
return string(*t)
129+
}
130+
115131
// Ptr returns a pointer to a copy of t, convenient for constructing
116132
// *TemplatableInt32 values inline.
117133
func (t *TemplatableInt32) Ptr() *TemplatableInt32 {

0 commit comments

Comments
 (0)