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)
| 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". |
| 59 | func 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), |
searching dependent graphs…