Skip to content

Commit

Permalink
Revert "feat: add support to filter commit msgs by prefixes (#45)"
Browse files Browse the repository at this point in the history
This reverts commit 283525f.
  • Loading branch information
caarlos0 committed Nov 19, 2021
1 parent 3c1e6c9 commit 8d4d5d8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 126 deletions.
27 changes: 0 additions & 27 deletions internal/svu/svu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package svu

import (
"regexp"
"strings"

"github.com/Masterminds/semver"
)
Expand Down Expand Up @@ -41,29 +40,3 @@ func FindNext(current *semver.Version, forcePatchIncrement bool, log string) sem

return *current
}

func FilterCommits(log string, prefixes []string) string {
lines := strings.Split(log, "\n")
filtered := make([]string, 0)
for _, line := range lines {
if strings.TrimSpace(line) == "" {
continue
}

commitMsgPrefix := strings.Split(line, " ")
if len(commitMsgPrefix) < 2 {
continue
}

for _, prefix := range prefixes {
if strings.HasPrefix(commitMsgPrefix[1], prefix) {
filtered = append(filtered, line)
}
}
}
if len(filtered) > 0 {
return strings.Join(filtered, "\n")
} else {
return ""
}
}
44 changes: 0 additions & 44 deletions internal/svu/svu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,47 +84,3 @@ func TestFindNext(t *testing.T) {
is.New(t).True(semver.MustParse(expected).Equal(&next)) // expected and next version should match
}
}

func TestFilterCommits(t *testing.T) {
type Input struct {
log string
prefixes []string
}
tests := []struct {
name string
args Input
want string
}{
{
name: "test-filter-happy-path",
args: Input{
log: "feat: something\nBREAKING CHANGE: something else",
prefixes: []string{"feat:"},
},
want: "feat: something",
},
{
name: "test-filter-drop-all",
args: Input{
log: "feat: something\nBREAKING CHANGE: something else",
prefixes: []string{"fix:"},
},
want: "",
},
{
name: "test-filter-return-all",
args: Input{
log: "feat: something\nBREAKING CHANGE: something else",
prefixes: []string{"feat:", "BREAKING"},
},
want: "feat: something\nBREAKING CHANGE: something else",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FilterCommits(tt.args.log, tt.args.prefixes); got != tt.want {
t.Errorf("FilterCommits() = %v, want %v", got, tt.want)
}
})
}
}
9 changes: 3 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
minorCmd = app.Command("minor", "new minor version").Alias("m")
patchCmd = app.Command("patch", "new patch version").Alias("p")
currentCmd = app.Command("current", "prints current version").Alias("c")
commitPrefix = app.Flag("commit-prefix", "Limits calculation based on commit type prefixes instead of considering all commit msgs").Strings()
metadata = app.Flag("metadata", "discards pre-release and build metadata if set to false").Default("true").Bool()
pattern = app.Flag("pattern", "limits calculations to be based on tags matching the given pattern").String()
preRelease = app.Flag("pre-release", "discards pre-release metadata if set to false").Default("true").Bool()
Expand Down Expand Up @@ -59,7 +58,7 @@ func main() {
var result semver.Version
switch cmd {
case nextCmd.FullCommand():
result = findNext(current, tag, *commitPrefix)
result = findNext(current, tag)
case majorCmd.FullCommand():
result = current.IncMajor()
case minorCmd.FullCommand():
Expand Down Expand Up @@ -114,12 +113,10 @@ func unsetMetadata(current *semver.Version) *semver.Version {
return unsetBuild(unsetPreRelease(current))
}

func findNext(current *semver.Version, tag string, commitPrefixes []string) semver.Version {
func findNext(current *semver.Version, tag string) semver.Version {
log, err := git.Changelog(tag)
app.FatalIfError(err, "failed to get changelog")
if len(commitPrefixes) > 0 {
log = svu.FilterCommits(log, commitPrefixes)
}

return svu.FindNext(current, *forcePatchIncrement, log)
}

Expand Down
49 changes: 0 additions & 49 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"reflect"
"testing"

"github.com/Masterminds/semver"
Expand Down Expand Up @@ -40,51 +39,3 @@ func TestNoStripPrefixReturnsPrefixAndVersion(t *testing.T) {
func TestSuffix(t *testing.T) {
is.New(t).True(getVersion("v2.3.4", "v", "4.5.6", "dev", false) == "v4.5.6-dev")
}

func Test_findNextWithSelectCommits(t *testing.T) {
type args struct {
current *semver.Version
tag string
commitPrefixes []string
}
tests := []struct {
name string
args args
want semver.Version
}{
{
name: "next-version-with-valid-filter",
args: args{
current: semver.MustParse("v1.7.0"),
tag: "v1.7.0",
commitPrefixes: []string{"fix"},
},
want: *semver.MustParse("v1.7.1"),
},
{
name: "next-version-with-valid-filter",
args: args{
current: semver.MustParse("v1.7.0"),
tag: "v1.7.0",
commitPrefixes: []string{"fix", "feat"},
},
want: *semver.MustParse("v1.8.0"),
},
{
name: "next-version-with-no-filter",
args: args{
current: semver.MustParse("v1.7.0"),
tag: "v1.7.0",
commitPrefixes: []string{},
},
want: *semver.MustParse("v1.8.0"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findNext(tt.args.current, tt.args.tag, tt.args.commitPrefixes); !reflect.DeepEqual(got, tt.want) {
t.Errorf("findNextWithSelectCommits() = %v, want %v", got, tt.want)
}
})
}
}

3 comments on commit 8d4d5d8

@brewkode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caarlos0 -- is there a reason why we reverted this ? Trying to understand.

@caarlos0
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brewkode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @caarlos0!!!

Please sign in to comment.