getTimeoutMinutesCodemod creates a codemod for migrating timeout_minutes to timeout-minutes
()
| 8 | |
| 9 | // getTimeoutMinutesCodemod creates a codemod for migrating timeout_minutes to timeout-minutes |
| 10 | func getTimeoutMinutesCodemod() Codemod { |
| 11 | return Codemod{ |
| 12 | ID: "timeout-minutes-migration", |
| 13 | Name: "Migrate timeout_minutes to timeout-minutes", |
| 14 | Description: "Replaces deprecated 'timeout_minutes' field with 'timeout-minutes'", |
| 15 | IntroducedIn: "0.1.0", |
| 16 | Apply: func(content string, frontmatter map[string]any) (string, bool, error) { |
| 17 | // Check if the deprecated field exists |
| 18 | value, exists := frontmatter["timeout_minutes"] |
| 19 | if !exists { |
| 20 | return content, false, nil |
| 21 | } |
| 22 | |
| 23 | newContent, applied, err := applyFrontmatterLineTransform(content, func(lines []string) ([]string, bool) { |
| 24 | result := make([]string, len(lines)) |
| 25 | var modified bool |
| 26 | for i, line := range lines { |
| 27 | replacedLine, didReplace := findAndReplaceInLine(line, "timeout_minutes", "timeout-minutes") |
| 28 | if didReplace { |
| 29 | result[i] = replacedLine |
| 30 | modified = true |
| 31 | timeoutMinutesCodemodLog.Printf("Replaced timeout_minutes with timeout-minutes on line %d", i+1) |
| 32 | } else { |
| 33 | result[i] = line |
| 34 | } |
| 35 | } |
| 36 | return result, modified |
| 37 | }) |
| 38 | if applied { |
| 39 | timeoutMinutesCodemodLog.Printf("Applied timeout_minutes migration (value: %v)", value) |
| 40 | } |
| 41 | return newContent, applied, err |
| 42 | }, |
| 43 | } |
| 44 | } |