diff --git a/cmd/list.go b/cmd/list.go index a20684c..a662d52 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" ) -var listCmd = &cobra.Command{ +var listCmd = &cobra.Command{ //nolint Use: "list", Short: "List up GitHub pull request information", Long: `List up GitHub repository or pull request information. @@ -28,7 +28,7 @@ func init() { //nolint */ } -func list(cmd *cobra.Command, args []string) error { +func list(cmd *cobra.Command, args []string) error { //nolint leadTime, err := di.NewLeadTime() if err != nil { return err diff --git a/cmd/root.go b/cmd/root.go index 0a198bb..bcc51c3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,7 +16,9 @@ func Execute() int { rootCmd.CompletionOptions.DisableDefaultCmd = true if err := rootCmd.Execute(); err != nil { log.Error(err) + return 1 } + return 0 } diff --git a/cmd/stat.go b/cmd/stat.go index 76f28b4..955ab6d 100644 --- a/cmd/stat.go +++ b/cmd/stat.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -var statCmd = &cobra.Command{ +var statCmd = &cobra.Command{ //nolint Use: "stat", Short: "Print GitHub pull request leadtime statics", Long: `Print GitHub pull request leadtime statics`, @@ -22,7 +22,7 @@ func init() { //nolint rootCmd.AddCommand(statCmd) } -func stat(cmd *cobra.Command, args []string) error { +func stat(cmd *cobra.Command, args []string) error { //nolint leadTime, err := di.NewLeadTime() if err != nil { return err @@ -64,5 +64,6 @@ func stat(cmd *cobra.Command, args []string) error { fmt.Printf(" Lead Time(Sum) = %d[min]\n", output.LeadTime.Sum()) fmt.Printf(" Lead Time(Ave) = %.2f[min]\n", output.LeadTime.Ave()) fmt.Printf(" Lead Time(Median) = %.2f[min]\n", output.LeadTime.Median()) + return nil } diff --git a/config/config.go b/config/config.go index a15d8d0..f3f9b1a 100644 --- a/config/config.go +++ b/config/config.go @@ -20,6 +20,7 @@ func NewGitHubConfig() (*GitHubConfig, error) { if err := env.Parse(cfg); err != nil { return nil, ErrNotSetGitHubAccessToken } + return cfg, nil } diff --git a/config/config_test.go b/config/config_test.go index b822788..051715c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -9,10 +9,10 @@ import ( "github.com/nao1215/leadtime/domain/model" ) -func TestNewGitHubConfig(t *testing.T) { +func TestNewGitHubConfig(t *testing.T) { //nolint const token = model.Token("test_token") - t.Run("Get github config", func(t *testing.T) { + t.Run("Get github config", func(t *testing.T) { //nolint t.Setenv("LT_GITHUB_ACCESS_TOKEN", token.String()) want := &GitHubConfig{ @@ -28,7 +28,7 @@ func TestNewGitHubConfig(t *testing.T) { } }) - t.Run("if user does not set github access token", func(t *testing.T) { + t.Run("if user does not set github access token", func(t *testing.T) { //nolint _, got := NewGitHubConfig() if !errors.Is(got, ErrNotSetGitHubAccessToken) { t.Errorf("mismatch want=%v, got=%v", ErrNotSetGitHubAccessToken, got) diff --git a/domain/usecase/pull_request.go b/domain/usecase/pull_request.go index 016a3ca..875a539 100644 --- a/domain/usecase/pull_request.go +++ b/domain/usecase/pull_request.go @@ -34,7 +34,7 @@ func (pr *PRUsecaseListInput) Valid() error { // isEmptyRepositoryName check whether repository name is empty. // true means empty, false means not empty. -func (pr *PRUsecaseListInput) isEmptyRepositoryName() bool { +func (pr *PRUsecaseListInput) isEmptyRepositoryName() bool { //nolist return pr.Repository == "" } diff --git a/infrastructure/github/github.go b/infrastructure/github/github.go index 56154e2..f9cc91c 100644 --- a/infrastructure/github/github.go +++ b/infrastructure/github/github.go @@ -77,11 +77,12 @@ func (c *GitHubRepository) ListRepositories(ctx context.Context) ([]*model.Repos // ListPullRequests return List the pull requests. func (c *GitHubRepository) ListPullRequests(ctx context.Context, owner, repo string) ([]*model.PullRequest, error) { + const pagingLimit = 20 pullReqs := make([]*model.PullRequest, 0) opts := &github.PullRequestListOptions{ State: "all", - ListOptions: github.ListOptions{PerPage: 20}, + ListOptions: github.ListOptions{PerPage: pagingLimit}, } for { @@ -115,7 +116,9 @@ func (c *GitHubRepository) ListPullRequests(ctx context.Context, owner, repo str // ListCommitsInPR return List the commits in the PR. // oreder is newest to oldest. func (c *GitHubRepository) ListCommitsInPR(ctx context.Context, owner, repo string, number int) ([]*model.Commit, error) { - opts := &github.ListOptions{PerPage: 20} + const pagingLimit = 20 + + opts := &github.ListOptions{PerPage: pagingLimit} commitsInPR := make([]*model.Commit, 0) for { diff --git a/main.go b/main.go index baaa554..e9e4eba 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( ) // osExit is wrapper for os.Exit(). It's for unit test. -var osExit = os.Exit +var osExit = os.Exit //nolint func main() { osExit(cmd.Execute())