MCPcopy Index your code
hub / github.com/cli/cli / stripDiffFormat

Function stripDiffFormat

pkg/cmd/agent-task/shared/log.go:333–363  ·  view source on GitHub ↗

stripDiffFormat implements a primitive conversion from a diff string to a plain text representation by removing diff-specific formatting.

(diff string)

Source from the content-addressed store, hash-verified

331// stripDiffFormat implements a primitive conversion from a diff string to a
332// plain text representation by removing diff-specific formatting.
333func stripDiffFormat(diff string) string {
334 lines := strings.Split(diff, "\n")
335
336 // Find where the hunk header ends.
337 hunkEndIndex := -1
338 for i, line := range lines {
339 if strings.HasPrefix(line, "@@") {
340 hunkEndIndex = i
341 break
342 }
343 }
344
345 // This isn't a diff.
346 if hunkEndIndex == -1 {
347 return diff
348 }
349
350 // Removing hunk header.
351 lines = lines[hunkEndIndex+1:]
352
353 // Strip the leading + and - from lines, if they exist.
354 var stripped []string
355 for _, line := range lines {
356 if strings.HasPrefix(line, "+") || strings.HasPrefix(line, "-") {
357 stripped = append(stripped, line[1:])
358 } else {
359 stripped = append(stripped, line)
360 }
361 }
362 return strings.Join(stripped, "\n")
363}
364
365// renderFileContentAsMarkdown renders the given content as markdown
366// based on the file extension of the path.

Callers 1

renderLogEntryFunction · 0.85

Calls 1

JoinMethod · 0.80

Tested by

no test coverage detected