0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-22 08:20:39 +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) semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes)
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags) releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags)
outputFormatter := sv.NewOutputFormatter() outputFormatter := sv.NewOutputFormatter()

View File

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

View File

@ -33,7 +33,7 @@ var hashMetadataBody = `some descriptions
Jira: JIRA-999 Jira: JIRA-999
Refs #123` Refs #123`
func TestCommitMessageParserImpl_Parse(t *testing.T) { func TestCommitMessageProcessorImpl_Parse(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
subject string subject string
@ -51,9 +51,9 @@ func TestCommitMessageParserImpl_Parse(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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) { 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,14 +64,14 @@ func NewLogRange(t LogRangeType, start, end string) LogRange {
// GitImpl git command implementation // GitImpl git command implementation
type GitImpl struct { type GitImpl struct {
messageParser CommitMessageParser messageProcessor CommitMessageProcessor
tagPattern string tagPattern string
} }
// NewGit constructor // NewGit constructor
func NewGit(messageParser CommitMessageParser, tagPattern string) *GitImpl { func NewGit(messageProcessor CommitMessageProcessor, tagPattern string) *GitImpl {
return &GitImpl{ return &GitImpl{
messageParser: messageParser, messageProcessor: messageProcessor,
tagPattern: tagPattern, tagPattern: tagPattern,
} }
} }
@ -109,7 +109,7 @@ 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.messageParser, string(out)), nil return parseLogOutput(g.messageProcessor, string(out)), nil
} }
// Commit runs git commit // Commit runs git commit
@ -167,25 +167,25 @@ func parseTagsOutput(input string) ([]GitTag, error) {
return result, nil return result, nil
} }
func parseLogOutput(messageParser CommitMessageParser, log string) []GitCommitLog { func parseLogOutput(messageProcessor CommitMessageProcessor, log string) []GitCommitLog {
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 != "" {
logs = append(logs, parseCommitLog(messageParser, text)) logs = append(logs, parseCommitLog(messageProcessor, text))
} }
} }
return logs return logs
} }
func parseCommitLog(messageParser CommitMessageParser, commit string) GitCommitLog { func parseCommitLog(messageProcessor CommitMessageProcessor, commit string) GitCommitLog {
content := strings.Split(strings.Trim(commit, "\""), logSeparator) content := strings.Split(strings.Trim(commit, "\""), logSeparator)
return GitCommitLog{ return GitCommitLog{
Date: content[0], Date: content[0],
Hash: content[1], Hash: content[1],
Message: messageParser.Parse(content[2], content[3]), Message: messageProcessor.Parse(content[2], content[3]),
} }
} }