MCPcopy
hub / github.com/harness/harness / ExtractSubject

Function ExtractSubject

git/parser/commit_message.go:59–85  ·  view source on GitHub ↗

ExtractSubject extracts subject from a commit message. The result should be like output of the one line commit summary, like "git log --oneline" or "git log --format=%s".

(message string)

Source from the content-addressed store, hash-verified

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".
59func ExtractSubject(message string) string {
60 var messageStarted bool
61
62 builder := strings.Builder{}
63
64 scan := bufio.NewScanner(strings.NewReader(message))
65 for scan.Scan() {
66 line := strings.TrimSpace(scan.Text())
67
68 // process empty lines
69 if len(line) == 0 {
70 if messageStarted {
71 return builder.String()
72 }
73 continue
74 }
75
76 if messageStarted {
77 builder.WriteByte(' ')
78 }
79
80 builder.WriteString(line)
81 messageStarted = true
82 }
83
84 return builder.String()
85}
86
87// SplitMessage splits a commit message. Returns two strings:
88// * subject (the one line commit summary, like "git log --oneline" or "git log --format=%s),

Callers 3

asCommitFunction · 0.92
asTagFunction · 0.92
TestExtractSubjectFunction · 0.85

Calls 3

ScanMethod · 0.95
TextMethod · 0.95
StringMethod · 0.45

Tested by 1

TestExtractSubjectFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…