Skip to content

Commit

Permalink
Merge pull request #222 from marionebl/filter-by-target-branch
Browse files Browse the repository at this point in the history
Allow filtering by target branch
  • Loading branch information
zaquestion authored Sep 26, 2018
2 parents 24e6729 + 0249d96 commit 82c6531
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 35 deletions.
48 changes: 24 additions & 24 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 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 All @@ -37,9 +38,10 @@ var listCmd = &cobra.Command{
ListOptions: gitlab.ListOptions{
PerPage: mrNumRet,
},
Labels: mrLabels,
State: &mrState,
OrderBy: gitlab.String("updated_at"),
Labels: mrLabels,
State: &mrState,
TargetBranch: &mrTargetBranch,
OrderBy: gitlab.String("updated_at"),
}, num)
if err != nil {
log.Fatal(err)
Expand All @@ -59,6 +61,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, 3, len(mrs))
}

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, "#1 Test MR for lab list", mrs[0])
}
9 changes: 5 additions & 4 deletions cmd/project_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ path refers the path on gitlab including the full group/namespace/project. If no
}

opts := gitlab.CreateProjectOptions{
Path: gitlab.String(path),
Name: gitlab.String(name),
Description: gitlab.String(desc),
Visibility: &visibility,
Path: gitlab.String(path),
Name: gitlab.String(name),
Description: gitlab.String(desc),
Visibility: &visibility,
ApprovalsBeforeMerge: gitlab.Int(0),
}
p, err := lab.ProjectCreate(&opts)
if err != nil {
Expand Down

0 comments on commit 82c6531

Please sign in to comment.