Skip to content

Commit

Permalink
fix: pass conventionalcommits.Machine by reference (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunet authored May 30, 2022
1 parent eb02715 commit 7c8a8dd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/handler/semanticpullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ func NewSemanticPullRequests(username, password string, logger *zap.Logger) (*Se
}

// NewSemanticMachine instantiates and returns a new conventionalcommits parser machine.
func NewSemanticMachine(conventionalTypes bool) conventionalcommits.Machine {
func NewSemanticMachine(conventionalTypes bool) *conventionalcommits.Machine {
var machine conventionalcommits.Machine

if conventionalTypes {
return parser.NewMachine(
machine = parser.NewMachine(
conventionalcommits.WithTypes(conventionalcommits.TypesConventional),
)
} else {
machine = parser.NewMachine(
conventionalcommits.WithTypes(conventionalcommits.TypesFreeForm),
)
}

return parser.NewMachine(
conventionalcommits.WithTypes(conventionalcommits.TypesFreeForm),
)
return &machine
}

// IsSemanticMessage validates the semantic of a given message.
func (spr *SemanticPullRequests) IsSemanticMessage(machine conventionalcommits.Machine, cfg *UserConfig, msg string) bool {
func (spr *SemanticPullRequests) IsSemanticMessage(machine *conventionalcommits.Machine, cfg *UserConfig, msg string) bool {
if *cfg.AllowMergeCommits && strings.HasPrefix(msg, "Merge") {
return true
}
Expand All @@ -60,7 +64,7 @@ func (spr *SemanticPullRequests) IsSemanticMessage(machine conventionalcommits.M
return true
}

ccMsg, err := machine.Parse([]byte(msg))
ccMsg, err := (*machine).Parse([]byte(msg))
if err != nil {
spr.Logger.Debug(
"failed to parse message",
Expand Down Expand Up @@ -93,7 +97,7 @@ func (spr *SemanticPullRequests) IsSemanticMessage(machine conventionalcommits.M
}

// AreSemanticCommits validates a given list of Bitbucket commits.
func (spr *SemanticPullRequests) AreSemanticCommits(machine conventionalcommits.Machine, cfg *UserConfig, commits []interface{}) bool {
func (spr *SemanticPullRequests) AreSemanticCommits(machine *conventionalcommits.Machine, cfg *UserConfig, commits []interface{}) bool {
var c map[string]interface{}

var isSemantic, ok bool
Expand Down

0 comments on commit 7c8a8dd

Please sign in to comment.