getCliProxyFeatureToGitHubModeCodemod migrates features.cli-proxy: true to tools.github.mode: gh-proxy.
()
| 10 | |
| 11 | // getCliProxyFeatureToGitHubModeCodemod migrates features.cli-proxy: true to tools.github.mode: gh-proxy. |
| 12 | func getCliProxyFeatureToGitHubModeCodemod() Codemod { |
| 13 | return Codemod{ |
| 14 | ID: "features-cli-proxy-to-tools-github-mode", |
| 15 | Name: "Migrate 'features.cli-proxy: true' to 'tools.github.mode: gh-proxy'", |
| 16 | Description: "Removes deprecated features.cli-proxy: true and sets tools.github.mode: gh-proxy (equivalent behavior).", |
| 17 | IntroducedIn: "1.0.0", |
| 18 | Apply: func(content string, frontmatter map[string]any) (string, bool, error) { |
| 19 | if !hasLegacyCliProxyFeatureEnabled(frontmatter) { |
| 20 | return content, false, nil |
| 21 | } |
| 22 | hasMode := hasToolsGitHubMode(frontmatter) |
| 23 | |
| 24 | newContent, applied, err := applyFrontmatterLineTransform(content, func(lines []string) ([]string, bool) { |
| 25 | result, modified := removeFieldFromBlock(lines, "cli-proxy", "features") |
| 26 | if !modified { |
| 27 | return lines, false |
| 28 | } |
| 29 | if !hasMode { |
| 30 | result = addGitHubModeGhProxyToTools(result) |
| 31 | } |
| 32 | return result, true |
| 33 | }) |
| 34 | if applied { |
| 35 | cliProxyModeCodemodLog.Print("Migrated features.cli-proxy: true to tools.github.mode: gh-proxy") |
| 36 | } |
| 37 | return newContent, applied, err |
| 38 | }, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func hasLegacyCliProxyFeatureEnabled(frontmatter map[string]any) bool { |
| 43 | featuresAny, ok := frontmatter["features"] |