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

Function getScheduleAtToAroundCodemod

pkg/cli/codemod_schedule.go:13–132  ·  view source on GitHub ↗

getScheduleAtToAroundCodemod creates a codemod for converting "daily at TIME" to "daily around TIME"

()

Source from the content-addressed store, hash-verified

11
12// getScheduleAtToAroundCodemod creates a codemod for converting "daily at TIME" to "daily around TIME"
13func getScheduleAtToAroundCodemod() Codemod {
14 return Codemod{
15 ID: "schedule-at-to-around-migration",
16 Name: "Migrate schedule 'at' syntax to 'around' syntax",
17 Description: "Converts deprecated 'daily at TIME', 'weekly on DAY at TIME', and 'monthly on N at TIME' to fuzzy schedules or standard cron",
18 IntroducedIn: "0.5.0",
19 Apply: func(content string, frontmatter map[string]any) (string, bool, error) {
20 return applyFrontmatterLineTransform(content, func(lines []string) ([]string, bool) {
21 var modified bool
22 result := make([]string, len(lines))
23
24 for i, line := range lines {
25 trimmedLine := strings.TrimSpace(line)
26 originalLine := line
27
28 // Skip if not a cron or schedule line
29 if !strings.Contains(trimmedLine, "cron:") && !strings.Contains(trimmedLine, "schedule:") {
30 result[i] = originalLine
31 continue
32 }
33
34 // Extract leading whitespace to preserve indentation
35 leadingSpace := getIndentation(line)
36
37 // Check if this is a list item (starts with - after whitespace)
38 restAfterSpace := strings.TrimLeft(line, " \t")
39 var listMarker string
40 if strings.HasPrefix(restAfterSpace, "-") {
41 // This is a list item, preserve the dash
42 listMarker = "- "
43 }
44
45 // Extract the schedule value (after "cron:" or "schedule:")
46 var scheduleValue string
47 var fieldName string
48
49 if strings.Contains(trimmedLine, "cron:") {
50 parts := strings.SplitN(trimmedLine, "cron:", 2)
51 if len(parts) == 2 {
52 fieldName = "cron"
53 scheduleValue = strings.TrimSpace(parts[1])
54 }
55 } else if strings.Contains(trimmedLine, "schedule:") {
56 parts := strings.SplitN(trimmedLine, "schedule:", 2)
57 if len(parts) == 2 {
58 fieldName = "schedule"
59 scheduleValue = strings.TrimSpace(parts[1])
60 }
61 }
62
63 if scheduleValue == "" {
64 result[i] = originalLine
65 continue
66 }
67
68 // Remove quotes if present
69 scheduleValue = strings.Trim(scheduleValue, "\"'")
70

Calls 4

getIndentationFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45