renameGitHubReposToAllowedRepos renames 'repos:' to 'allowed-repos:' within the tools.github configuration block.
(lines []string)
| 59 | // renameGitHubReposToAllowedRepos renames 'repos:' to 'allowed-repos:' within the |
| 60 | // tools.github configuration block. |
| 61 | func renameGitHubReposToAllowedRepos(lines []string) ([]string, bool) { |
| 62 | var result []string |
| 63 | modified := false |
| 64 | |
| 65 | var inTools, inToolsGithub bool |
| 66 | var toolsIndent, toolsGithubIndent string |
| 67 | |
| 68 | for i, line := range lines { |
| 69 | trimmed := strings.TrimSpace(line) |
| 70 | |
| 71 | // Skip empty lines without resetting state |
| 72 | if trimmed == "" { |
| 73 | result = append(result, line) |
| 74 | continue |
| 75 | } |
| 76 | |
| 77 | // Exit blocks when indentation signals we've left them |
| 78 | if !strings.HasPrefix(trimmed, "#") { |
| 79 | if inToolsGithub && hasExitedBlock(line, toolsGithubIndent) { |
| 80 | inToolsGithub = false |
| 81 | } |
| 82 | if inTools && hasExitedBlock(line, toolsIndent) { |
| 83 | inTools = false |
| 84 | inToolsGithub = false |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Detect 'tools:' block |
| 89 | if strings.HasPrefix(trimmed, "tools:") { |
| 90 | inTools = true |
| 91 | inToolsGithub = false |
| 92 | toolsIndent = getIndentation(line) |
| 93 | result = append(result, line) |
| 94 | continue |
| 95 | } |
| 96 | |
| 97 | // Detect 'github:' block inside 'tools:' |
| 98 | if inTools && strings.HasPrefix(trimmed, "github:") { |
| 99 | inToolsGithub = true |
| 100 | toolsGithubIndent = getIndentation(line) |
| 101 | result = append(result, line) |
| 102 | continue |
| 103 | } |
| 104 | |
| 105 | // Rename 'repos:' to 'allowed-repos:' when inside tools.github |
| 106 | if inToolsGithub && strings.HasPrefix(trimmed, "repos:") { |
| 107 | lineIndent := getIndentation(line) |
| 108 | if isDescendant(lineIndent, toolsGithubIndent) { |
| 109 | newLine, replaced := findAndReplaceInLine(line, "repos", "allowed-repos") |
| 110 | if replaced { |
| 111 | result = append(result, newLine) |
| 112 | modified = true |
| 113 | githubReposCodemodLog.Printf("Renamed 'repos' to 'allowed-repos' on line %d", i+1) |
| 114 | continue |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 |
nothing calls this directly
no test coverage detected