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

Method preprocessScheduleFields

pkg/workflow/schedule_preprocessing.go:104–337  ·  view source on GitHub ↗

preprocessScheduleFields converts human-friendly schedule expressions to cron expressions in the frontmatter's "on" section. It modifies the frontmatter map in place.

(frontmatter map[string]any, markdownPath string, content string)

Source from the content-addressed store, hash-verified

102// preprocessScheduleFields converts human-friendly schedule expressions to cron expressions
103// in the frontmatter's "on" section. It modifies the frontmatter map in place.
104func (c *Compiler) preprocessScheduleFields(frontmatter map[string]any, markdownPath string, content string) error {
105 schedulePreprocessingLog.Print("Preprocessing schedule fields in frontmatter")
106
107 // Check if "on" field exists
108 onValue, exists := frontmatter["on"]
109 if !exists {
110 return nil
111 }
112
113 // Check if "on" is a string - might be a schedule expression, slash command shorthand, label trigger shorthand, or other trigger shorthand
114 if onStr, ok := onValue.(string); ok {
115 schedulePreprocessingLog.Printf("Processing on field as string: %s", onStr)
116
117 // Check if it's a slash command shorthand (starts with /)
118 commandName, isSlashCommand, err := parseSlashCommandShorthand(onStr)
119 if err != nil {
120 return err
121 }
122 if isSlashCommand {
123 schedulePreprocessingLog.Printf("Converting shorthand 'on: %s' to slash_command + workflow_dispatch", onStr)
124
125 // Create the expanded format
126 onMap := expandSlashCommandShorthand(commandName)
127 frontmatter["on"] = onMap
128
129 return nil
130 }
131
132 // Check if it's a label-command shorthand (starts with "label-command ")
133 if labelName, ok := strings.CutPrefix(onStr, "label-command "); ok {
134 labelName = strings.TrimSpace(labelName)
135 if labelName == "" {
136 return errors.New("label-command shorthand requires a label name after 'label-command'")
137 }
138 schedulePreprocessingLog.Printf("Converting shorthand 'on: %s' to label_command + workflow_dispatch", onStr)
139 onMap := expandLabelCommandShorthand(labelName)
140 frontmatter["on"] = onMap
141 return nil
142 }
143
144 // Check if it's a label trigger shorthand (labeled label1 label2...)
145 entityType, labelNames, isLabelTrigger, err := parseLabelTriggerShorthand(onStr)
146 if err != nil {
147 return err
148 }
149 if isLabelTrigger {
150 schedulePreprocessingLog.Printf("Converting shorthand 'on: %s' to %s labeled + workflow_dispatch", onStr, entityType)
151
152 // Create the expanded format
153 onMap := expandLabelTriggerShorthand(entityType, labelNames)
154 frontmatter["on"] = onMap
155
156 return nil
157 }
158
159 // Try the new unified trigger parser for other trigger shorthands
160 triggerIR, err := ParseTriggerShorthand(onStr)
161 if err != nil {

Calls 14

ParseTriggerShorthandFunction · 0.85
stripExpressionWrapperFunction · 0.85
PrintMethod · 0.80
ToYAMLMapMethod · 0.80
PrintfMethod · 0.45