Skip to content

Commit

Permalink
refactor(root_runner): move Strict under RunnerOptions
Browse files Browse the repository at this point in the history
Strict was for some reason passed in the Runner struct unlike all the other options and flags.
  • Loading branch information
fallion committed Jun 16, 2020
1 parent 5c1f2cc commit 1a79530
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion internal/root_runner/log_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestLogBranch(t *testing.T) {
runner := Runner{
DebugLogger: log.New(ioutil.Discard, "", 0),
Logger: &testLogger,
Strict: false,
Debug: false,
}

Expand Down
5 changes: 2 additions & 3 deletions internal/root_runner/root_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
type Runner struct {
DebugLogger *log.Logger
Logger *log.Logger
Strict bool
// Debug is a deprecated flag. Will be replaced as all repos accept the debugLogger
Debug bool
}
Expand All @@ -23,10 +22,11 @@ type RunnerOptions struct {
Limit int
// AllCommits will check all the commits on the upstream branch. Regardless of Limit setting.
AllCommits bool
Strict bool
}

// New returns a new instance of a RootRunner with fallback for logging
func New(logger *log.Logger, debugLogger *log.Logger, strict bool) *Runner {
func New(logger *log.Logger, debugLogger *log.Logger) *Runner {
if logger == nil {
logger = log.New(os.Stdout, "", 0)
}
Expand All @@ -37,6 +37,5 @@ func New(logger *log.Logger, debugLogger *log.Logger, strict bool) *Runner {
return &Runner{
Logger: logger,
DebugLogger: debugLogger,
Strict: strict,
}
}
2 changes: 1 addition & 1 deletion internal/root_runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (runner *Runner) Run(options RunnerOptions, args ...string) error {

parsedCommit := quoad.ParseCommitMessage(commitObject.Message)

textErr := text.CheckMessageTitle(parsedCommit, runner.Strict)
textErr := text.CheckMessageTitle(parsedCommit, options.Strict)

if textErr != nil {
faultyCommits = append(faultyCommits, text.FailingCommit{Hash: commitHash.String(), Message: parsedCommit.Heading, Error: textErr})
Expand Down
15 changes: 9 additions & 6 deletions internal/root_runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ func TestCommitsOnMaster(t *testing.T) {
runner := Runner{
DebugLogger: log.New(ioutil.Discard, "", 0),
Logger: &testLogger,
Strict: false,
Debug: false,

Debug: false,
}

options := RunnerOptions{
Path: "../../testdata/commits-on-master",
UpstreamBranch: "master",
Limit: 0,
AllCommits: false,
Strict: false,
}

err := runner.Run(options)
Expand All @@ -44,15 +45,16 @@ func TestCommitsOnBranch(t *testing.T) {
runner := Runner{
DebugLogger: log.New(ioutil.Discard, "", 0),
Logger: &testLogger,
Strict: false,
Debug: false,

Debug: false,
}

options := RunnerOptions{
Path: "../../testdata/commits-on-different-branches",
UpstreamBranch: "master",
Limit: 0,
AllCommits: false,
Strict: false,
}

err := runner.Run(options, "master")
Expand All @@ -69,15 +71,16 @@ func TestFromToCommits(t *testing.T) {
runner := Runner{
DebugLogger: log.New(ioutil.Discard, "", 0),
Logger: &testLogger,
Strict: false,
Debug: false,

Debug: false,
}

options := RunnerOptions{
Path: "../../testdata/commits-on-different-branches",
UpstreamBranch: "master",
Limit: 0,
AllCommits: false,
Strict: false,
}

err := runner.Run(options, "7dbf3e7db93ae2e02902cae9d2f1de1b1e5c8c92...d0240d3ed34685d0a5329b185e120d3e8c205be4")
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ func runRoot(cmd *cobra.Command, args []string) error {

logger := log.New(os.Stdout, "", 0)

runner := root_runner.New(logger, &debugLogger, Strict)
runner := root_runner.New(logger, &debugLogger)

options := root_runner.RunnerOptions{
Path: ".",
UpstreamBranch: upstreamBranch,
Limit: 0,
AllCommits: AllCommits,
Strict: Strict,
}

return runner.Run(options, args...)
Expand Down

0 comments on commit 1a79530

Please sign in to comment.