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

Function addIntegrityProxyFalseToToolsGitHub

pkg/cli/codemod_difc_proxy.go:111–176  ·  view source on GitHub ↗

addIntegrityProxyFalseToToolsGitHub inserts 'integrity-proxy: false' inside the tools.github block. The line is inserted immediately after the 'github:' key line. The indentation is derived from the first existing sub-field inside the github block.

(lines []string)

Source from the content-addressed store, hash-verified

109// tools.github block. The line is inserted immediately after the 'github:' key line.
110// The indentation is derived from the first existing sub-field inside the github block.
111func addIntegrityProxyFalseToToolsGitHub(lines []string) []string {
112 var result []string
113 var inTools bool
114 var toolsIndent string
115 var inGitHub bool
116 var githubIndent string
117 var fieldInserted bool
118
119 for _, line := range lines {
120 trimmed := strings.TrimSpace(line)
121
122 // Track if we're in the tools block
123 if strings.HasPrefix(trimmed, "tools:") {
124 inTools = true
125 toolsIndent = getIndentation(line)
126 result = append(result, line)
127 continue
128 }
129
130 // Check if we've left the tools block
131 if inTools && len(trimmed) > 0 && !strings.HasPrefix(trimmed, "#") {
132 if hasExitedBlock(line, toolsIndent) {
133 inTools = false
134 inGitHub = false
135 }
136 }
137
138 // Detect 'github:' inside tools
139 if inTools && !inGitHub && strings.HasPrefix(trimmed, "github:") {
140 inGitHub = true
141 githubIndent = getIndentation(line)
142 result = append(result, line)
143 continue
144 }
145
146 // Inside github block: inject integrity-proxy: false before the first sub-field
147 if inGitHub && !fieldInserted && len(trimmed) > 0 && !strings.HasPrefix(trimmed, "#") {
148 if hasExitedBlock(line, githubIndent) {
149 // Exited github block without seeing any sub-fields; use default indentation
150 fieldIndent := githubIndent + " "
151 result = append(result, fieldIndent+"integrity-proxy: false")
152 difcProxyCodemodLog.Printf("Added integrity-proxy: false to tools.github (before exit)")
153 fieldInserted = true
154 inGitHub = false
155 } else {
156 // Use the indentation of the first existing sub-field
157 fieldIndent := getIndentation(line)
158 result = append(result, fieldIndent+"integrity-proxy: false")
159 difcProxyCodemodLog.Printf("Added integrity-proxy: false to tools.github")
160 fieldInserted = true
161 inGitHub = false
162 }
163 }
164
165 result = append(result, line)
166 }
167
168 // Edge case: github block was the last entry in the file

Callers 1

Calls 3

getIndentationFunction · 0.85
hasExitedBlockFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected