-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit.go
43 lines (35 loc) · 838 Bytes
/
commit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package convention
import (
"github.com/haunt98/changeloguru/internal/git"
)
// https://www.conventionalcommits.org/en/v1.0.0/
// <type>[optional scope]: <description>
// [optional body]
// [optional footer(s)]
// Commit represens conventional commit
type Commit struct {
// Commit as is
RawHeader string
Type string
Scope string
}
// NewCommit return conventional commit from git commit
func NewCommit(c git.Commit) (Commit, error) {
return NewCommitWithOptions(
GetRawHeader(c),
GetTypeAndScope(c),
AddAuthorDate(c),
)
}
// NewCommitWithOptions return conventional commit with custom option
func NewCommitWithOptions(opts ...OptionFn) (result Commit, err error) {
for _, opt := range opts {
if err = opt(&result); err != nil {
return
}
}
return
}
func (c *Commit) String() string {
return c.RawHeader
}