Skip to content

Commit

Permalink
chore: fix a bunch of golangci-lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap committed Jul 11, 2023
1 parent e508f29 commit 5655ac3
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 29 deletions.
1 change: 0 additions & 1 deletion client/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,4 @@ func (c Client) PipelinesLogs(repoOrga string, repoSlug, idOrUuid string, StepUu
IDOrUuid: idOrUuid,
StepUuid: StepUuid,
})

}
2 changes: 1 addition & 1 deletion client/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions client/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
8 changes: 5 additions & 3 deletions cmd/commands/issue/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/pr/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -77,7 +78,6 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
return
}
}

},
}
prCmd.AddCommand(checkoutCmd)
Expand Down
4 changes: 0 additions & 4 deletions cmd/commands/pr/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -457,7 +454,6 @@ func manageReviewers(bbrepo *bbgit.BitbucketRepo, c *client.Client, currentUser
reviewers = append(reviewers, uuid)
}
}

}
return reviewers, nil
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/commands/pr/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
20 changes: 16 additions & 4 deletions cmd/commands/repo/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ 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 {
logging.Error(err)
return
}
viper.Set("git_protocol", gitProtocol)
viper.WriteConfig()
err = viper.WriteConfig()
if err != nil {
logging.Error(err)
return
}
}

if len(args) == 0 {
Expand Down Expand Up @@ -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], "/")
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions util/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""

Expand Down

0 comments on commit 5655ac3

Please sign in to comment.