diff --git a/cmd/go-gitlint/main.go b/cmd/go-gitlint/main.go index b2050d2..561d719 100644 --- a/cmd/go-gitlint/main.go +++ b/cmd/go-gitlint/main.go @@ -18,8 +18,7 @@ import ( "os" "github.com/llorllale/go-gitlint/internal/commits" - "github.com/llorllale/go-gitlint/internal/commits/filter" - "github.com/llorllale/go-gitlint/internal/commits/issues" + "github.com/llorllale/go-gitlint/internal/issues" "github.com/llorllale/go-gitlint/internal/repo" ) @@ -32,9 +31,9 @@ func main() { issues.Printed( os.Stdout, "\n", issues.Collected( - []func(*commits.Commit) issues.Issue{ - filter.OfSubjectRegex(".{,1}"), - filter.OfBodyRegex(".{,1}"), + []issues.Filter{ + issues.OfSubjectRegex(".{,1}"), + issues.OfBodyRegex(".{,1}"), }, commits.In( repo.Filesystem("."), diff --git a/internal/commits/filter/filter.go b/internal/issues/filters.go similarity index 69% rename from internal/commits/filter/filter.go rename to internal/issues/filters.go index 7152c94..b9b1d63 100644 --- a/internal/commits/filter/filter.go +++ b/internal/issues/filters.go @@ -12,32 +12,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -package filter +package issues import ( "fmt" "regexp" "github.com/llorllale/go-gitlint/internal/commits" - "github.com/llorllale/go-gitlint/internal/commits/issues" ) -/* - Filters identify issues with a commit. - A filter returning a zero-valued Issue signals that it found no issue - with the commit. -*/ +// Filter identifies an issue with a commit. +// A filter returning a zero-valued Issue signals that it found no issue +// with the commit. +type Filter func(*commits.Commit) Issue // OfSubjectRegex tests a commit's subject with the regex. -func OfSubjectRegex(regex string) func(*commits.Commit) issues.Issue { - return func(c *commits.Commit) issues.Issue { - var issue issues.Issue +func OfSubjectRegex(regex string) Filter { + return func(c *commits.Commit) Issue { + var issue Issue matched, err := regexp.MatchString(regex, c.Subject()) if err != nil { panic(err) } if !matched { - issue = issues.Issue{ + issue = Issue{ Desc: fmt.Sprintf("subject does not match regex [%s]", regex), Commit: *c, } @@ -47,15 +45,15 @@ func OfSubjectRegex(regex string) func(*commits.Commit) issues.Issue { } // OfBodyRegex tests a commit's body with the regex. -func OfBodyRegex(regex string) func(*commits.Commit) issues.Issue { - return func(c *commits.Commit) issues.Issue { - var issue issues.Issue +func OfBodyRegex(regex string) Filter { + return func(c *commits.Commit) Issue { + var issue Issue matched, err := regexp.MatchString(regex, c.Body()) if err != nil { panic(err) } if !matched { - issue = issues.Issue{ + issue = Issue{ Desc: fmt.Sprintf("body does not conform to regex [%s]", regex), Commit: *c, } diff --git a/internal/commits/filter/filter_test.go b/internal/issues/filters_test.go similarity index 99% rename from internal/commits/filter/filter_test.go rename to internal/issues/filters_test.go index ee05cfd..a463b4c 100644 --- a/internal/commits/filter/filter_test.go +++ b/internal/issues/filters_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package filter +package issues import ( "testing" diff --git a/internal/commits/issues/issues.go b/internal/issues/issues.go similarity index 94% rename from internal/commits/issues/issues.go rename to internal/issues/issues.go index 9e647bf..085c3a9 100644 --- a/internal/commits/issues/issues.go +++ b/internal/issues/issues.go @@ -35,7 +35,7 @@ func (i *Issue) String() string { type Issues func() []Issue // Collected returns a collection of issues identified. -func Collected(filters []func(c *commits.Commit) Issue, cmts commits.Commits) Issues { +func Collected(filters []Filter, cmts commits.Commits) Issues { return func() []Issue { issues := make([]Issue, 0) for _, c := range cmts() { diff --git a/internal/commits/issues/issues_test.go b/internal/issues/issues_test.go similarity index 98% rename from internal/commits/issues/issues_test.go rename to internal/issues/issues_test.go index 8dcf58c..f359af7 100644 --- a/internal/commits/issues/issues_test.go +++ b/internal/issues/issues_test.go @@ -27,7 +27,7 @@ func TestCollected(t *testing.T) { {Hash: "456"}, } issues := Collected( - []func(*commits.Commit) Issue{ + []Filter{ func(c *commits.Commit) Issue { var issue Issue if c.Hash == "123" || c.Hash == "456" {