Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"

"github.com/pkg/errors"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
Expand All @@ -12,12 +13,13 @@ import (
)

var (
issueLabels []string
issueMilestone string
issueState string
issueSearch string
issueNumRet int
issueAll bool
issueLabels []string
issueMilestone string
issueState string
issueSearch string
issueNumRet int
issueAll bool
issueExactMatch bool
)

var issueListCmd = &cobra.Command{
Expand Down Expand Up @@ -70,6 +72,13 @@ func issueList(args []string) ([]*gitlab.Issue, error) {
OrderBy: gitlab.String("updated_at"),
}

if issueExactMatch {
if issueSearch == "" {
return nil, errors.New("Exact match requested, but no search terms provided")
}
issueSearch = "\"" + issueSearch + "\""
}

if issueSearch != "" {
opts.Search = &issueSearch
}
Expand Down Expand Up @@ -97,6 +106,9 @@ func init() {
issueListCmd.Flags().StringVar(
&issueMilestone, "milestone", "",
"filter issues by milestone")
issueListCmd.Flags().BoolVarP(
&issueExactMatch, "exact-match", "x", false,
"match on the exact (case-insensitive) search terms")

issueCmd.AddCommand(issueListCmd)
carapace.Gen(issueListCmd).FlagCompletion(carapace.ActionMap{
Expand Down
30 changes: 24 additions & 6 deletions cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"

"github.com/pkg/errors"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
Expand All @@ -24,6 +25,7 @@ var (
mrReady bool
mrConflicts bool
mrNoConflicts bool
mrExactMatch bool
assigneeID *int
mrAssignee string
order string
Expand All @@ -32,11 +34,15 @@ var (

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list [remote]",
Aliases: []string{"ls"},
Short: "List merge requests",
Long: ``,
Args: cobra.MaximumNArgs(1),
Use: "list [remote] [search]",
Aliases: []string{"ls", "search"},
Short: "List merge requests",
Long: ``,
Args: cobra.MaximumNArgs(2),
Example: `lab mr list
lab mr list "search terms" # search merge requests for "search terms"
lab mr search "search terms" # same as above
lab mr list remote "search terms" # search "remote" for merge requests with "search terms"`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
mrs, err := mrList(args)
Expand All @@ -51,7 +57,7 @@ var listCmd = &cobra.Command{
}

func mrList(args []string) ([]*gitlab.MergeRequest, error) {
rn, _, err := parseArgsRemoteAndID(args)
rn, search, err := parseArgsRemoteAndProject(args)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -115,6 +121,17 @@ func mrList(args []string) ([]*gitlab.MergeRequest, error) {
opts.WIP = gitlab.String("no")
}

if mrExactMatch {
if search == "" {
return nil, errors.New("Exact match requested, but no search terms provided")
}
search = "\"" + search + "\""
}

if search != "" {
opts.Search = &search
}

mrs, err := lab.MRList(rn, opts, num)
if err != nil {
return mrs, err
Expand Down Expand Up @@ -161,6 +178,7 @@ func init() {
listCmd.Flags().SortFlags = false
listCmd.Flags().BoolVar(&mrNoConflicts, "no-conflicts", false, "list only MRs that can be merged")
listCmd.Flags().BoolVar(&mrConflicts, "conflicts", false, "list only MRs that cannot be merged")
listCmd.Flags().BoolVarP(&mrExactMatch, "exact-match", "x", false, "match on the exact (case-insensitive) search terms")

mrCmd.AddCommand(listCmd)
carapace.Gen(listCmd).FlagCompletion(carapace.ActionMap{
Expand Down
16 changes: 16 additions & 0 deletions cmd/mr_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,19 @@ func Test_mrListCreatedDescending(t *testing.T) {
t.Log(mrs)
require.Equal(t, latestCreatedTestMR, mrs[0])
}

func Test_mrListSearch(t *testing.T) {
t.Parallel()
repo := copyTestRepo(t)
cmd := exec.Command(labBinaryPath, "mr", "list", "emoji")
cmd.Dir = repo

b, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}

mrs := strings.Split(string(b), "\n")
t.Log(mrs)
require.Contains(t, mrs, "!6 test award emoji")
}