From 295a892a47332f2cdb910e6ea7545f4cac004081 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Tue, 25 Sep 2018 13:56:40 +0200 Subject: [PATCH] Allow filtering by target branch --- cmd/mr_list.go | 15 +++++++++++---- cmd/mr_list_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/cmd/mr_list.go b/cmd/mr_list.go index c8fbd869..339d2c41 100644 --- a/cmd/mr_list.go +++ b/cmd/mr_list.go @@ -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 @@ -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) } }, @@ -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) } diff --git a/cmd/mr_list_test.go b/cmd/mr_list_test.go index 41fce928..547ab5a5 100644 --- a/cmd/mr_list_test.go +++ b/cmd/mr_list_test.go @@ -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]) +}