changeloguru/internal/convention/commit.go

44 lines
838 B
Go
Raw Normal View History

2020-11-09 08:46:42 +00:00
package convention
import (
"github.com/haunt98/changeloguru/internal/git"
2020-11-09 08:46:42 +00:00
)
// https://www.conventionalcommits.org/en/v1.0.0/
// <type>[optional scope]: <description>
// [optional body]
// [optional footer(s)]
// Commit represens conventional commit
2020-11-09 08:46:42 +00:00
type Commit struct {
// Commit as is
RawHeader string
Type string
Scope string
2020-11-09 08:46:42 +00:00
}
// NewCommit return conventional commit from git commit
func NewCommit(c git.Commit) (Commit, error) {
return NewCommitWithOptions(
GetRawHeader(c),
GetTypeAndScope(c),
AddAuthorDate(c),
)
}
2020-11-09 08:46:42 +00:00
// 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
}
}
2020-11-09 08:46:42 +00:00
return
}
func (c *Commit) String() string {
return c.RawHeader
}