diff --git a/client/pipelines.go b/client/pipelines.go index 32dfbb3..1f86e6e 100644 --- a/client/pipelines.go +++ b/client/pipelines.go @@ -134,5 +134,4 @@ func (c Client) PipelinesLogs(repoOrga string, repoSlug, idOrUuid string, StepUu IDOrUuid: idOrUuid, StepUuid: StepUuid, }) - } diff --git a/client/pr.go b/client/pr.go index 8994571..c53a923 100644 --- a/client/pr.go +++ b/client/pr.go @@ -83,7 +83,7 @@ type CommentContent struct { type CommentParent struct { ID int `mapstructure:"id"` - _Links map[string]interface{} `mapstructure:"links"` + _Links map[string]interface{} `mapstructure:"links"` //nolint:unused Comment *Comment } diff --git a/client/workspaces.go b/client/workspaces.go index 6733708..4c94610 100644 --- a/client/workspaces.go +++ b/client/workspaces.go @@ -36,8 +36,8 @@ func (c Client) GetWorkspaceMembers(workspace string) (*Members, error) { return nil, err } members := Members{} - mapstructure.Decode(response, &members) - return &members, nil + err = mapstructure.Decode(response, &members) + return &members, err } func (c Client) GetWorkspaces() (*Workspaces, error) { @@ -49,6 +49,6 @@ func (c Client) GetWorkspaces() (*Workspaces, error) { } var workspaces *Workspaces - mapstructure.Decode(response, &workspaces) - return workspaces, nil + err = mapstructure.Decode(response, &workspaces) + return workspaces, err } diff --git a/cmd/commands/issue/list/list.go b/cmd/commands/issue/list/list.go index f8c6cc7..f2a60c3 100644 --- a/cmd/commands/issue/list/list.go +++ b/cmd/commands/issue/list/list.go @@ -18,6 +18,8 @@ var ( Priorities []string ) +const FLAG_OPTION_ALL = "ALL" + func Add(issueCmd *cobra.Command, globalOpts *options.GlobalOptions) { listCmd := &cobra.Command{ Use: "list", @@ -50,19 +52,19 @@ func Add(issueCmd *cobra.Command, globalOpts *options.GlobalOptions) { } for _, state := range States { - if strings.ToUpper(state) == "ALL" { + if strings.ToUpper(state) == FLAG_OPTION_ALL { States = []string{"new", "open", "resolved", "on hold", "invalid", "duplicate", "wontfix", "closed"} } } for _, typus := range Types { - if strings.ToUpper(typus) == "ALL" { + if strings.ToUpper(typus) == FLAG_OPTION_ALL { Types = []string{"bug", "enhancement", "proposal", "task"} } } for _, priority := range Priorities { - if strings.ToUpper(priority) == "ALL" { + if strings.ToUpper(priority) == FLAG_OPTION_ALL { Priorities = []string{"trivial", "minor", "major", "critical", "blocker"} } } diff --git a/cmd/commands/pr/checkout/checkout.go b/cmd/commands/pr/checkout/checkout.go index dedc698..d063d5f 100644 --- a/cmd/commands/pr/checkout/checkout.go +++ b/cmd/commands/pr/checkout/checkout.go @@ -39,7 +39,8 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { return } } else { - //TODO: Error + logging.Error("no PR id specified") + return } pr, err := c.PrView(bbrepo.RepoOrga, bbrepo.RepoSlug, fmt.Sprintf("%d", id)) if err != nil { @@ -77,7 +78,6 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { return } } - }, } prCmd.AddCommand(checkoutCmd) diff --git a/cmd/commands/pr/create/create.go b/cmd/commands/pr/create/create.go index 37d0819..489033c 100644 --- a/cmd/commands/pr/create/create.go +++ b/cmd/commands/pr/create/create.go @@ -141,7 +141,6 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { } reviewers = []string{} for _, reviewer := range existingPr.Reviewers { - // TODO: make this memory efficient reviewers = append(reviewers, reviewer.UUID) } } @@ -191,7 +190,6 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { fmt.Println("None") } else { for _, reviewer := range reviewers { - name, ok := ReviewersNameCache[reviewer] if ok { fmt.Println("-", name) @@ -365,7 +363,6 @@ func manageReviewers(bbrepo *bbgit.BitbucketRepo, c *client.Client, currentUser fmt.Println("None") } else { for _, reviewer := range reviewers { - name, ok := ReviewersNameCache[reviewer] if ok { fmt.Println("-", name) @@ -457,7 +454,6 @@ func manageReviewers(bbrepo *bbgit.BitbucketRepo, c *client.Client, currentUser reviewers = append(reviewers, uuid) } } - } return reviewers, nil } diff --git a/cmd/commands/pr/merge/merge.go b/cmd/commands/pr/merge/merge.go index f0f0ba0..4b3dc0f 100644 --- a/cmd/commands/pr/merge/merge.go +++ b/cmd/commands/pr/merge/merge.go @@ -69,7 +69,6 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { logging.Error(err) return } - } else { pr, err = c.PrMerge(bbrepo.RepoOrga, bbrepo.RepoSlug, fmt.Sprintf("%d", id)) if err != nil { @@ -87,7 +86,7 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { }, } - mergeCmd.Flags().BoolVar(&CloseBranch, "close-source-branch", false, "close the source branch (pr setting if omited)") + mergeCmd.Flags().BoolVar(&CloseBranch, "close-source-branch", false, "close the source branch (pr setting if omitted)") prCmd.AddCommand(mergeCmd) } diff --git a/cmd/commands/repo/clone/clone.go b/cmd/commands/repo/clone/clone.go index 57afc91..8851abe 100644 --- a/cmd/commands/repo/clone/clone.go +++ b/cmd/commands/repo/clone/clone.go @@ -27,7 +27,7 @@ func Add(repoCmd *cobra.Command, globalOpts *options.GlobalOptions) { gitProtocol := viper.GetString("git_protocol") if gitProtocol == "" || (gitProtocol != "ssh" && gitProtocol != "https") { err := survey.AskOne(&survey.Select{ - Message: "Please select a prefered protocol of cloning repositories", + Message: "Please select a preferred protocol of cloning repositories", Options: []string{"ssh", "https"}, }, &gitProtocol) if err != nil { @@ -35,7 +35,11 @@ func Add(repoCmd *cobra.Command, globalOpts *options.GlobalOptions) { return } viper.Set("git_protocol", gitProtocol) - viper.WriteConfig() + err = viper.WriteConfig() + if err != nil { + logging.Error(err) + return + } } if len(args) == 0 { @@ -88,7 +92,11 @@ func Add(repoCmd *cobra.Command, globalOpts *options.GlobalOptions) { } f := FormatRemoteURL(gitProtocol, splitted[0], splitted[1]) - git.RunClone(f, []string{}) + _, err = git.RunClone(f, []string{}) + if err != nil { + logging.Error(err) + return + } } } else if len(args) == 1 { splitted := strings.Split(args[0], "/") @@ -100,7 +108,11 @@ func Add(repoCmd *cobra.Command, globalOpts *options.GlobalOptions) { } f := FormatRemoteURL(gitProtocol, splitted[0], splitted[1]) - git.RunClone(f, []string{}) + _, err = git.RunClone(f, []string{}) + if err != nil { + logging.Error(err) + return + } } else { fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occurred: "), "too less or many args") return diff --git a/internal/run/run.go b/internal/run/run.go index ba66e01..83da582 100644 --- a/internal/run/run.go +++ b/internal/run/run.go @@ -14,19 +14,19 @@ import ( "strings" ) -// Runnable is typically an exec.Cmd or its stub in tests +// Runnable is typically an exec.Cmd or its stub in tests. type Runnable interface { Output() ([]byte, error) Run() error } // PrepareCmd extends exec.Cmd with extra error reporting features and provides a -// hook to stub command execution in tests +// hook to stub command execution in tests. var PrepareCmd = func(cmd *exec.Cmd) Runnable { return &cmdWithStderr{cmd} } -// SetPrepareCmd overrides PrepareCmd and returns a func to revert it back +// SetPrepareCmd overrides PrepareCmd and returns a func to revert it back. func SetPrepareCmd(fn func(*exec.Cmd) Runnable) func() { origPrepare := PrepareCmd PrepareCmd = func(cmd *exec.Cmd) Runnable { @@ -41,7 +41,7 @@ func SetPrepareCmd(fn func(*exec.Cmd) Runnable) func() { } } -// cmdWithStderr augments exec.Cmd by adding stderr to the error message +// cmdWithStderr augments exec.Cmd by adding stderr to the error message. type cmdWithStderr struct { *exec.Cmd } @@ -78,7 +78,7 @@ func (c cmdWithStderr) Run() error { return err } -// CmdError provides more visibility into why an exec.Cmd had failed +// CmdError provides more visibility into why an exec.Cmd had failed. type CmdError struct { Stderr *bytes.Buffer Args []string diff --git a/util/editor/editor.go b/util/editor/editor.go index 7b3fd70..2718c7f 100644 --- a/util/editor/editor.go +++ b/util/editor/editor.go @@ -4,10 +4,10 @@ import "github.com/AlecAivazis/survey/v2" func OpenInEditor(body string, filePattern string) (string, error) { prompt := &survey.Editor{ - Default: body, - FileName: filePattern, + Default: body, + FileName: filePattern, AppendDefault: true, - HideDefault: true, + HideDefault: true, } content := ""