Skip to content

Commit

Permalink
(mr, state) add state flag to filter MRs by state
Browse files Browse the repository at this point in the history
  • Loading branch information
nkprince007 committed Dec 17, 2017
1 parent c9ccd9b commit c273987
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/mrList.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var mrLabels []string
var mrState string

// listCmd represents the list command
var listCmd = &cobra.Command{
Expand Down Expand Up @@ -38,7 +39,7 @@ var listCmd = &cobra.Command{
PerPage: 10,
},
Labels: mrLabels,
State: gitlab.String("opened"),
State: &mrState,
OrderBy: gitlab.String("updated_at"),
})
if err != nil {
Expand All @@ -53,5 +54,8 @@ var listCmd = &cobra.Command{
func init() {
listCmd.Flags().StringSliceVarP(
&mrLabels, "label", "l", []string{}, "filter merge requests by label")
listCmd.Flags().StringVarP(
&mrState, "state", "s", "opened",
"filter merge requests by state (opened/closed/merged)")
mrCmd.AddCommand(listCmd)
}
30 changes: 30 additions & 0 deletions cmd/mrList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ func Test_mrListFlagLabel(t *testing.T) {
t.Log(mrs)
require.Equal(t, "#3 for testings filtering with labels and lists", mrs[0])
}

func Test_mrListStateMerged(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "mr", "list", "-s", "merged")
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, "#4 merged merge request", mrs[0])
}

func Test_mrListStateClosed(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "mr", "list", "-s", "closed")
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, "#2 asdf", mrs[0])
}

0 comments on commit c273987

Please sign in to comment.