0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-10 02:10:38 +00:00

refactor: rename parser to processor

This commit is contained in:
Beatriz Vieira 2021-02-13 23:49:24 -03:00
parent 8cf6f1eb56
commit 740f05b84a
4 changed files with 22 additions and 22 deletions

View File

@ -27,7 +27,7 @@ func main() {
}
////
git := sv.NewGit(sv.NewCommitMessageParser(commitMessageCfg), cfg.TagPattern)
git := sv.NewGit(sv.NewCommitMessageProcessor(commitMessageCfg), cfg.TagPattern)
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes)
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags)
outputFormatter := sv.NewOutputFormatter()

View File

@ -52,23 +52,23 @@ func (m CommitMessage) BreakingMessage() string {
return m.Metadata[breakingKey]
}
// CommitMessageParser parse commit messages.
type CommitMessageParser interface {
// CommitMessageProcessor parse commit messages.
type CommitMessageProcessor interface {
Parse(subject, body string) CommitMessage
}
// CommitMessageParserImpl commit message parser implementation
type CommitMessageParserImpl struct {
// CommitMessageProcessorImpl commit message processor implementation
type CommitMessageProcessorImpl struct {
cfg CommitMessageConfig
}
// NewCommitMessageParser CommitMessageParserImpl constructor
func NewCommitMessageParser(cfg CommitMessageConfig) CommitMessageParser {
return &CommitMessageParserImpl{cfg: cfg}
// NewCommitMessageProcessor CommitMessageProcessorImpl constructor
func NewCommitMessageProcessor(cfg CommitMessageConfig) CommitMessageProcessor {
return &CommitMessageProcessorImpl{cfg: cfg}
}
// Parse parse a commit message
func (p CommitMessageParserImpl) Parse(subject, body string) CommitMessage {
func (p CommitMessageProcessorImpl) Parse(subject, body string) CommitMessage {
commitType, scope, description, hasBreakingChange := parseSubjectMessage(subject)
metadata := make(map[string]string)

View File

@ -33,7 +33,7 @@ var hashMetadataBody = `some descriptions
Jira: JIRA-999
Refs #123`
func TestCommitMessageParserImpl_Parse(t *testing.T) {
func TestCommitMessageProcessorImpl_Parse(t *testing.T) {
tests := []struct {
name string
subject string
@ -51,9 +51,9 @@ func TestCommitMessageParserImpl_Parse(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewCommitMessageParser(cfg)
p := NewCommitMessageProcessor(cfg)
if got := p.Parse(tt.subject, tt.body); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CommitMessageParserImpl.Parse() = %v, want %v", got, tt.want)
t.Errorf("CommitMessageProcessorImpl.Parse() = %v, want %v", got, tt.want)
}
})
}

View File

@ -64,15 +64,15 @@ func NewLogRange(t LogRangeType, start, end string) LogRange {
// GitImpl git command implementation
type GitImpl struct {
messageParser CommitMessageParser
tagPattern string
messageProcessor CommitMessageProcessor
tagPattern string
}
// NewGit constructor
func NewGit(messageParser CommitMessageParser, tagPattern string) *GitImpl {
func NewGit(messageProcessor CommitMessageProcessor, tagPattern string) *GitImpl {
return &GitImpl{
messageParser: messageParser,
tagPattern: tagPattern,
messageProcessor: messageProcessor,
tagPattern: tagPattern,
}
}
@ -109,7 +109,7 @@ func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) {
if err != nil {
return nil, combinedOutputErr(err, out)
}
return parseLogOutput(g.messageParser, string(out)), nil
return parseLogOutput(g.messageProcessor, string(out)), nil
}
// Commit runs git commit
@ -167,25 +167,25 @@ func parseTagsOutput(input string) ([]GitTag, error) {
return result, nil
}
func parseLogOutput(messageParser CommitMessageParser, log string) []GitCommitLog {
func parseLogOutput(messageProcessor CommitMessageProcessor, log string) []GitCommitLog {
scanner := bufio.NewScanner(strings.NewReader(log))
scanner.Split(splitAt([]byte(endLine)))
var logs []GitCommitLog
for scanner.Scan() {
if text := strings.TrimSpace(strings.Trim(scanner.Text(), "\"")); text != "" {
logs = append(logs, parseCommitLog(messageParser, text))
logs = append(logs, parseCommitLog(messageProcessor, text))
}
}
return logs
}
func parseCommitLog(messageParser CommitMessageParser, commit string) GitCommitLog {
func parseCommitLog(messageProcessor CommitMessageProcessor, commit string) GitCommitLog {
content := strings.Split(strings.Trim(commit, "\""), logSeparator)
return GitCommitLog{
Date: content[0],
Hash: content[1],
Message: messageParser.Parse(content[2], content[3]),
Message: messageProcessor.Parse(content[2], content[3]),
}
}