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

Function QuoteCronExpressions

pkg/parser/workflow_update.go:116–138  ·  view source on GitHub ↗

QuoteCronExpressions ensures cron expressions in schedule sections are properly quoted. The YAML library may drop quotes from cron expressions like "0 14 * * 1-5" which causes validation errors since they start with numbers but contain spaces and special chars.

(yamlContent string)

Source from the content-addressed store, hash-verified

114// The YAML library may drop quotes from cron expressions like "0 14 * * 1-5" which
115// causes validation errors since they start with numbers but contain spaces and special chars.
116func QuoteCronExpressions(yamlContent string) string {
117 workflowUpdateLog.Print("Quoting cron expressions in YAML content")
118
119 // Replace unquoted cron expressions with quoted versions
120 return cronPattern.ReplaceAllStringFunc(yamlContent, func(match string) string {
121 // Extract the cron prefix and value
122 submatches := cronPattern.FindStringSubmatch(match)
123 if len(submatches) < 3 {
124 return match
125 }
126 prefix := submatches[1]
127 cronValue := strings.TrimSpace(submatches[2])
128
129 // Remove any trailing comments
130 if idx := strings.Index(cronValue, "#"); idx != -1 {
131 comment := cronValue[idx:]
132 cronValue = strings.TrimSpace(cronValue[:idx])
133 return prefix + `"` + cronValue + `" ` + comment
134 }
135
136 return prefix + `"` + cronValue + `"`
137 })
138}

Callers 5

applyDefaultsMethod · 0.92
parseOnSectionMethod · 0.92
TestQuoteCronExpressionsFunction · 0.85

Calls 1

PrintMethod · 0.80

Tested by 1

TestQuoteCronExpressionsFunction · 0.68