mirror of
https://github.com/romdo/go-conventionalcommit.git
synced 2026-02-18 23:56:41 +00:00
The NewRawMessage function returns a RawMessage struct, which has broken the given commit message down into separate lines, and also grouped the lines into paragraphs. This should make it easier to implement proper conventional commit parser, linter, and formatter.
31 lines
738 B
Go
31 lines
738 B
Go
package conventionalcommit
|
|
|
|
import "bytes"
|
|
|
|
// Paragraph represents a textual paragraph defined as; A continuous sequence of
|
|
// textual lines which are not empty or and do not consist of only whitespace.
|
|
type Paragraph struct {
|
|
// Lines is a list of lines which collectively form a paragraph.
|
|
Lines Lines
|
|
}
|
|
|
|
func NewParagraphs(lines Lines) []*Paragraph {
|
|
r := []*Paragraph{}
|
|
|
|
paragraph := &Paragraph{Lines: Lines{}}
|
|
for _, line := range lines {
|
|
if len(bytes.TrimSpace(line.Content)) > 0 {
|
|
paragraph.Lines = append(paragraph.Lines, line)
|
|
} else if len(paragraph.Lines) > 0 {
|
|
r = append(r, paragraph)
|
|
paragraph = &Paragraph{Lines: Lines{}}
|
|
}
|
|
}
|
|
|
|
if len(paragraph.Lines) > 0 {
|
|
r = append(r, paragraph)
|
|
}
|
|
|
|
return r
|
|
}
|