Skip to content

Commit

Permalink
Allow filtering by target branch
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 25, 2018
1 parent 24e6729 commit 295a892
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

var (
mrLabels []string
mrState string
mrNumRet int
mrAll bool
mrLabels []string
mrState string
mrTargetBranch string
mrNumRet int
mrAll bool
)

// listCmd represents the list command
Expand Down Expand Up @@ -45,6 +46,9 @@ var listCmd = &cobra.Command{
log.Fatal(err)
}
for _, mr := range mrs {
if mrTargetBranch != "" && mrTargetBranch != mr.TargetBranch {
continue
}
fmt.Printf("#%d %s\n", mr.IID, mr.Title)
}
},
Expand All @@ -59,6 +63,9 @@ func init() {
listCmd.Flags().IntVarP(
&mrNumRet, "number", "n", 10,
"number of merge requests to return")
listCmd.Flags().StringVarP(
&mrTargetBranch, "target-branch", "t", "",
"filter merge requests by target branch")
listCmd.Flags().BoolVarP(&mrAll, "all", "a", false, "List all MRs on the project")
mrCmd.AddCommand(listCmd)
}
30 changes: 30 additions & 0 deletions cmd/mr_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,33 @@ func Test_mrListFivePerPage(t *testing.T) {
t.Log(mrs)
require.Contains(t, mrs, "#1 Test MR for lab list")
}

func Test_mrFilterByTargetBranch(t *testing.T) {
t.Parallel()
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "mr", "list", "-t", "non-existing")
cmd.Dir = repo

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

mrs := strings.Split(string(b), "\n")
require.Equal(t, "PASS", mrs[0])
}

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

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

mrs := strings.Split(string(b), "\n")
require.Equal(t, "#107 WIP: Resolve \"issue title\"", mrs[0])
}

0 comments on commit 295a892

Please sign in to comment.