Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(commit-lint): Fix IsValidMessage method to skip commit lint when … #20

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v2.0.1:
- Fix IsValidMessage method to skip commit lint when the message is a merge from master to a developer branch. (@esequiel.virtuoso)
- Add chore option. (@esequiel.virtuoso)

v2.0.0:
- Change semantic-release message pattern to 'type(scope?): message here'. (@esequiel.virtuoso)

v1.0.5
- Fix isSetNewVersion function logic (@esequiel.virtuoso)

Expand Down
1 change: 1 addition & 0 deletions cmd/semantic-release/semantic-release.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func printCommitTypes() {
fmt.Println(colorYellow + "\t* [refactor]" + colorReset + ": A code change that neither fixes a bug nor adds a feature")
fmt.Println(colorYellow + "\t* [style]" + colorReset + ": Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)")
fmt.Println(colorYellow + "\t* [test]" + colorReset + ": Adding missing tests or correcting existing tests")
fmt.Println(colorYellow + "\t* [chore]" + colorReset + ": No production code change. It won't release a new version.")
fmt.Println(colorYellow + "\t* [skip]" + colorReset + ": Skip versioning")
fmt.Println(colorYellow + "\t* [bc]" + colorReset + ": Changes that will require other changes in dependant applications")
fmt.Println(colorYellow + "\t* [breaking]" + colorReset + ": ||")
Expand Down
15 changes: 15 additions & 0 deletions src/commit-message/commit_message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,22 @@ func (f *CommitMessage) PrettifyCommitMessage(commitMessage string) (string, err
return f.upperFirstLetterOfSentence(message), nil
}

func isMergeMasterBranch(message string) bool {
splitedMessage := strings.Split(strings.ToLower(message), "\n")

for _, row := range splitedMessage {
if strings.Contains(row, "'origin/master' into") {
return true
}
}
return false
}

func (f *CommitMessage) IsValidMessage(message string) bool {
if isMergeMasterBranch(message) {
return true
}

index := strings.Index(message, ":")

if f.commitType.IndexNotFound(index) {
Expand Down
7 changes: 7 additions & 0 deletions src/commit-message/commit_message_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ func TestIsValidMessageFalse(t *testing.T) {
actual = f.commitMessageManager.IsValidMessage(message)
tests.AssertFalse(t, actual)
}

func TestIsValidMessageMergeMasterBranchSuccess(t *testing.T) {
f := setup(t)
message := "first message row \n Merge remote-tracking branch 'origin/master' into something \n last message row"
actual := f.commitMessageManager.IsValidMessage(message)
tests.AssertTrue(t, actual)
}
4 changes: 2 additions & 2 deletions src/commit-type/commit_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CommitType struct {
}

func (c *CommitType) GetAll() []string {
return []string{"build", "ci", "docs", "fix", "feat", "feature", "feature", "perf", "performance", "refactor", "style", "test", "bc", "breaking", "breaking change", "skip"}
return []string{"build", "ci", "docs", "fix", "feat", "feature", "feature", "perf", "performance", "refactor", "style", "test", "bc", "breaking", "breaking change", "chore", "skip"}
}

func (c *CommitType) GetMajorUpgrade() []string {
Expand All @@ -31,7 +31,7 @@ func (c *CommitType) GetPatchUpgrade() []string {
}

func (c *CommitType) GetSkipVersioning() []string {
return []string{"skip"}
return []string{"skip", "chore"}
}

func (c *CommitType) isValidCommitType(commitTypeScope string) bool {
Expand Down
4 changes: 2 additions & 2 deletions src/commit-type/commit_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func setup(t *testing.T) *fixture {

func TestGetAll(t *testing.T) {
f := setup(t)
expected := []string{"build", "ci", "docs", "fix", "feat", "feature", "feature", "perf", "performance", "refactor", "style", "test", "bc", "breaking", "breaking change", "skip"}
expected := []string{"build", "ci", "docs", "fix", "feat", "feature", "feature", "perf", "performance", "refactor", "style", "test", "bc", "breaking", "breaking change", "chore", "skip"}
actual := f.commitType.GetAll()

tests.AssertDeepEqualValues(t, expected, actual)
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestGetPatchUpgrade(t *testing.T) {

func TestGetSkipVersioning(t *testing.T) {
f := setup(t)
expected := []string{"skip"}
expected := []string{"skip", "chore"}
actual := f.commitType.GetSkipVersioning()

tests.AssertDeepEqualValues(t, expected, actual)
Expand Down
Loading