mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-14 07:40:40 +00:00
refactor: make handling with unconventional commits configurable
issue: #45
This commit is contained in:
parent
f36433692d
commit
8bce43b160
@ -121,6 +121,7 @@ branches: # Git branches config.
|
|||||||
commit-message:
|
commit-message:
|
||||||
types: [build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test] # Supported commit types.
|
types: [build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test] # Supported commit types.
|
||||||
header-selector: '' # You can put in a regex here to select only a certain part of the commit message. Please define a regex group 'header'.
|
header-selector: '' # You can put in a regex here to select only a certain part of the commit message. Please define a regex group 'header'.
|
||||||
|
skip-unconventional: false # Allows to skip commits that do not comply with conventional commits. Otherwise those will cause errors.
|
||||||
scope:
|
scope:
|
||||||
# Define supported scopes, if blank, scope will not be validated, if not, only scope listed will be valid.
|
# Define supported scopes, if blank, scope will not be validated, if not, only scope listed will be valid.
|
||||||
# Don't forget to add "" on your list if you need to define scopes and keep it optional.
|
# Don't forget to add "" on your list if you need to define scopes and keep it optional.
|
||||||
|
@ -103,6 +103,7 @@ func defaultConfig() Config {
|
|||||||
},
|
},
|
||||||
Issue: sv.CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
Issue: sv.CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
||||||
HeaderSelector: "",
|
HeaderSelector: "",
|
||||||
|
SkipUnconventional: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func main() {
|
|||||||
|
|
||||||
cfg := loadCfg(repoPath)
|
cfg := loadCfg(repoPath)
|
||||||
messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
|
messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
|
||||||
git := sv.NewGit(messageProcessor, cfg.Tag)
|
git := sv.NewGit(messageProcessor, cfg.Tag, cfg.CommitMessage)
|
||||||
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage)
|
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage)
|
||||||
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes)
|
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes)
|
||||||
outputFormatter := sv.NewOutputFormatter(templateFS(filepath.Join(repoPath, configDir, "templates")))
|
outputFormatter := sv.NewOutputFormatter(templateFS(filepath.Join(repoPath, configDir, "templates")))
|
||||||
|
@ -9,6 +9,7 @@ type CommitMessageConfig struct {
|
|||||||
Scope CommitMessageScopeConfig `yaml:"scope"`
|
Scope CommitMessageScopeConfig `yaml:"scope"`
|
||||||
Footer map[string]CommitMessageFooterConfig `yaml:"footer"`
|
Footer map[string]CommitMessageFooterConfig `yaml:"footer"`
|
||||||
Issue CommitMessageIssueConfig `yaml:"issue"`
|
Issue CommitMessageIssueConfig `yaml:"issue"`
|
||||||
|
SkipUnconventional bool `yaml:"skip-unconventional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssueFooterConfig config for issue.
|
// IssueFooterConfig config for issue.
|
||||||
|
22
sv/git.go
22
sv/git.go
@ -71,13 +71,15 @@ func NewLogRange(t LogRangeType, start, end string) LogRange {
|
|||||||
type GitImpl struct {
|
type GitImpl struct {
|
||||||
messageProcessor MessageProcessor
|
messageProcessor MessageProcessor
|
||||||
tagCfg TagConfig
|
tagCfg TagConfig
|
||||||
|
messageCfg CommitMessageConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGit constructor.
|
// NewGit constructor.
|
||||||
func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl {
|
func NewGit(messageProcessor MessageProcessor, tagCfg TagConfig, messageCfg CommitMessageConfig) *GitImpl {
|
||||||
return &GitImpl{
|
return &GitImpl{
|
||||||
messageProcessor: messageProcessor,
|
messageProcessor: messageProcessor,
|
||||||
tagCfg: cfg,
|
tagCfg: tagCfg,
|
||||||
|
messageCfg: messageCfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +116,14 @@ func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, combinedOutputErr(err, out)
|
return nil, combinedOutputErr(err, out)
|
||||||
}
|
}
|
||||||
return parseLogOutput(g.messageProcessor, string(out)), nil
|
|
||||||
|
logs, parseErr := g.parseLogOutput(g.messageProcessor, string(out))
|
||||||
|
|
||||||
|
if parseErr != nil {
|
||||||
|
return nil, parseErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit runs git commit.
|
// Commit runs git commit.
|
||||||
@ -188,20 +197,21 @@ func parseTagsOutput(input string) ([]GitTag, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLogOutput(messageProcessor MessageProcessor, log string) []GitCommitLog {
|
func (g GitImpl) parseLogOutput(messageProcessor MessageProcessor, log string) ([]GitCommitLog, error) {
|
||||||
scanner := bufio.NewScanner(strings.NewReader(log))
|
scanner := bufio.NewScanner(strings.NewReader(log))
|
||||||
scanner.Split(splitAt([]byte(endLine)))
|
scanner.Split(splitAt([]byte(endLine)))
|
||||||
var logs []GitCommitLog
|
var logs []GitCommitLog
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
if text := strings.TrimSpace(strings.Trim(scanner.Text(), "\"")); text != "" {
|
if text := strings.TrimSpace(strings.Trim(scanner.Text(), "\"")); text != "" {
|
||||||
log, err := parseCommitLog(messageProcessor, text)
|
log, err := parseCommitLog(messageProcessor, text)
|
||||||
// Ignore errors occuring during parsing
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logs = append(logs, log)
|
logs = append(logs, log)
|
||||||
|
} else if !g.messageCfg.SkipUnconventional {
|
||||||
|
return logs, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return logs
|
return logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCommitLog(messageProcessor MessageProcessor, commit string) (GitCommitLog, error) {
|
func parseCommitLog(messageProcessor MessageProcessor, commit string) (GitCommitLog, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user