Skip to content

Commit

Permalink
(mr, labels) add support for filtering mrs by labels
Browse files Browse the repository at this point in the history
``-l`` flag can be used to filter mrs by their labels
  • Loading branch information
nkprince007 committed Dec 17, 2017
1 parent 6405134 commit 40d3d31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/mrList.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
lab "github.com/zaquestion/lab/internal/gitlab"
)

var mrLabels []string

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Expand All @@ -35,6 +37,7 @@ var listCmd = &cobra.Command{
Page: int(page),
PerPage: 10,
},
Labels: mrLabels,
State: gitlab.String("opened"),
OrderBy: gitlab.String("updated_at"),
})
Expand All @@ -48,5 +51,7 @@ var listCmd = &cobra.Command{
}

func init() {
listCmd.Flags().StringSliceVarP(
&mrLabels, "label", "l", []string{}, "filter merge requests by label")
mrCmd.AddCommand(listCmd)
}
15 changes: 15 additions & 0 deletions cmd/mrList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@ func Test_mrList(t *testing.T) {
firstIssue := issues[len(issues)-4 : len(issues)-3]
require.Equal(t, "#1 Test MR for lab list", firstIssue[0])
}

func Test_mrListFlagLabel(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "mr", "list", "-l", "confirmed")
cmd.Dir = repo

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

mrs := strings.Split(string(b), "\n")
t.Log(mrs)
require.Equal(t, "#3 for testings filtering with labels and lists", mrs[0])
}

0 comments on commit 40d3d31

Please sign in to comment.