MCPcopy
hub / github.com/harness/harness / CleanUpWhitespace

Function CleanUpWhitespace

git/parser/commit_message.go:25–55  ·  view source on GitHub ↗

CleanUpWhitespace removes extra whitespace for the multiline string passed as parameter. The intended usage is to clean up commit messages.

(message string)

Source from the content-addressed store, hash-verified

23// CleanUpWhitespace removes extra whitespace for the multiline string passed as parameter.
24// The intended usage is to clean up commit messages.
25func CleanUpWhitespace(message string) string {
26 var messageStarted bool
27 var isLastLineEmpty bool
28
29 const eol = '\n'
30
31 builder := strings.Builder{}
32
33 scan := bufio.NewScanner(strings.NewReader(message))
34 for scan.Scan() {
35 line := strings.TrimRightFunc(scan.Text(), unicode.IsSpace)
36
37 if len(line) == 0 {
38 if messageStarted {
39 isLastLineEmpty = true
40 }
41 continue
42 }
43
44 if isLastLineEmpty {
45 builder.WriteByte(eol)
46 }
47
48 builder.WriteString(line)
49 builder.WriteByte(eol)
50 isLastLineEmpty = false
51 messageStarted = true
52 }
53
54 return builder.String()
55}
56
57// ExtractSubject extracts subject from a commit message. The result should be like output of
58// the one line commit summary, like "git log --oneline" or "git log --format=%s".

Callers 4

RevertMethod · 0.92
MergeMethod · 0.92
CommitFilesMethod · 0.92
TestCleanUpWhitespaceFunction · 0.85

Calls 3

ScanMethod · 0.95
TextMethod · 0.95
StringMethod · 0.45

Tested by 1

TestCleanUpWhitespaceFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…