Skip to content

Commit

Permalink
internal/action: fix else clause with if ending with return
Browse files Browse the repository at this point in the history
If the 'if' clause ends with a 'return' call the 'else' can be removed.

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Jun 23, 2021
1 parent aada9db commit 51696f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
17 changes: 9 additions & 8 deletions internal/action/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
// Labels returns a carapace.Action containing all possible labels
func Labels(project string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if labels, err := lab.LabelList(project); err != nil {
labels, err := lab.LabelList(project)
if err != nil {
return carapace.ActionMessage(err.Error())
} else {
values := make([]string, len(labels)*2)
for index, label := range labels {
values[index*2] = label.Name
values[index*2+1] = label.Description
}
return carapace.ActionValuesDescribed(values...)
}

values := make([]string, len(labels)*2)
for index, label := range labels {
values[index*2] = label.Name
values[index*2+1] = label.Description
}
return carapace.ActionValuesDescribed(values...)
}).Cache(5*time.Minute, cache.String(project))
}
20 changes: 10 additions & 10 deletions internal/action/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ type MilestoneOpts struct {
func (o MilestoneOpts) format() string {
if o.Active {
return "active"
} else {
return "closed"
}
return "closed"
}

// Milestones returns a carapace.Action containing all possible milestones with
// their description
func Milestones(project string, opts MilestoneOpts) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
state := opts.format()
if milestones, err := lab.MilestoneList(project, &gitlab.ListMilestonesOptions{State: &state}); err != nil {
milestones, err := lab.MilestoneList(project, &gitlab.ListMilestonesOptions{State: &state})
if err != nil {
return carapace.ActionMessage(err.Error())
} else {
values := make([]string, len(milestones)*2)
for index, milestone := range milestones {
values[index*2] = milestone.Title
values[index*2+1] = strings.SplitN(milestone.Description, "\n", 2)[0]
}
return carapace.ActionValuesDescribed(values...)
}

values := make([]string, len(milestones)*2)
for index, milestone := range milestones {
values[index*2] = milestone.Title
values[index*2+1] = strings.SplitN(milestone.Description, "\n", 2)[0]
}
return carapace.ActionValuesDescribed(values...)
}).Cache(5*time.Minute, cache.String(project, opts.format()))
}

0 comments on commit 51696f9

Please sign in to comment.