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

Function addGitHubModeGhProxyToTools

pkg/cli/codemod_cli_proxy_mode.go:80–147  ·  view source on GitHub ↗
(lines []string)

Source from the content-addressed store, hash-verified

78}
79
80func addGitHubModeGhProxyToTools(lines []string) []string {
81 toolsLine := -1
82 toolsIndent := ""
83
84 for i, line := range lines {
85 trimmed := strings.TrimSpace(line)
86 if strings.HasPrefix(trimmed, "tools:") {
87 toolsLine = i
88 toolsIndent = getIndentation(line)
89 break
90 }
91 }
92
93 if toolsLine == -1 {
94 return append(lines, "tools:", " github:", " mode: gh-proxy")
95 }
96
97 githubLine := -1
98 githubIndent := ""
99 toolsEnd := len(lines)
100 for i := toolsLine + 1; i < len(lines); i++ {
101 trimmed := strings.TrimSpace(lines[i])
102 if len(trimmed) > 0 && !strings.HasPrefix(trimmed, "#") && hasExitedBlock(lines[i], toolsIndent) {
103 toolsEnd = i
104 break
105 }
106 if strings.HasPrefix(trimmed, "github:") && strings.HasPrefix(getIndentation(lines[i]), toolsIndent+" ") {
107 githubLine = i
108 githubIndent = getIndentation(lines[i])
109 break
110 }
111 }
112
113 if githubLine == -1 {
114 result := make([]string, 0, len(lines)+2)
115 result = append(result, lines[:toolsEnd]...)
116 result = append(result, toolsIndent+" github:")
117 result = append(result, toolsIndent+" mode: gh-proxy")
118 result = append(result, lines[toolsEnd:]...)
119 return result
120 }
121
122 if strings.TrimSpace(lines[githubLine]) != "github:" {
123 cliProxyModeCodemodLog.Print("Skipping mode addition: github line has inline content")
124 return lines
125 }
126
127 fieldIndent := githubIndent + " "
128 insertAt := githubLine + 1
129 for i := githubLine + 1; i < len(lines); i++ {
130 trimmed := strings.TrimSpace(lines[i])
131 if len(trimmed) > 0 && !strings.HasPrefix(trimmed, "#") {
132 if hasExitedBlock(lines[i], githubIndent) {
133 insertAt = i
134 } else {
135 fieldIndent = getIndentation(lines[i])
136 insertAt = i
137 }

Callers 1

Calls 3

getIndentationFunction · 0.85
hasExitedBlockFunction · 0.85
PrintMethod · 0.80

Tested by

no test coverage detected