diff --git a/cmd/issueList.go b/cmd/issueList.go index d4fb310b..7100c0e6 100644 --- a/cmd/issueList.go +++ b/cmd/issueList.go @@ -11,6 +11,7 @@ import ( ) var issueLabels []string +var issueState string var issueListCmd = &cobra.Command{ Use: "list", @@ -36,7 +37,7 @@ var issueListCmd = &cobra.Command{ PerPage: 10, }, Labels: issueLabels, - State: gitlab.String("opened"), + State: &issueState, OrderBy: gitlab.String("updated_at"), }) if err != nil { @@ -51,5 +52,8 @@ var issueListCmd = &cobra.Command{ func init() { issueListCmd.Flags().StringSliceVarP( &issueLabels, "label", "l", []string{}, "filter issues by label") + issueListCmd.Flags().StringVarP( + &issueState, "state", "s", "opened", + "filter issues by state (opened/closed)") issueCmd.AddCommand(issueListCmd) } diff --git a/cmd/issueList_test.go b/cmd/issueList_test.go index dee784c4..eb6cdd53 100644 --- a/cmd/issueList_test.go +++ b/cmd/issueList_test.go @@ -38,3 +38,18 @@ func Test_issueListFlagLabel(t *testing.T) { t.Log(issues) require.Equal(t, "#3 test filter labels 1", issues[0]) } + +func Test_issueListStateClosed(t *testing.T) { + repo := copyTestRepo(t) + cmd := exec.Command("../lab_bin", "issue", "list", "-s", "closed") + cmd.Dir = repo + + b, err := cmd.CombinedOutput() + if err != nil { + t.Fatal(err) + } + + issues := strings.Split(string(b), "\n") + t.Log(issues) + require.Equal(t, "#4 test closed issue", issues[0]) +}