Merge branch 'allow-filter-issues-by-issue-type' into 'main'

feat(issue): add issue-type filter to issue cmd

Closes #1092

See merge request https://gitlab.com/gitlab-org/cli/-/merge_requests/1073

Merged-by: Gary Holtz <gholtz@gitlab.com>
Approved-by: Jaime Martinez <jmartinez@gitlab.com>
Approved-by: Gary Holtz <gholtz@gitlab.com>
Co-authored-by: Vitali Tatarintev <vtatarintev@gitlab.com>
This commit is contained in:
Gary Holtz 2022-11-07 20:58:56 +00:00
commit 9863c9cf3b
4 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,23 @@
[
{
"state": "opened",
"description": "description incident here",
"project_id": 1,
"updated_at": "2016-01-04T16:31:51.081Z",
"id": 78,
"title": "Incident",
"created_at": "2016-01-04T16:31:51.081Z",
"iid": 8,
"labels": [
"foo",
"baz"
],
"web_url": "http://gitlab.com/OWNER/REPO/issues/8",
"references": {
"full": "OWNER/REPO/issues/8",
"relative": "#8",
"short": "#8"
},
"issue_type": "incident"
}
]

View File

@ -30,6 +30,7 @@ type ListOptions struct {
Mine bool
Search string
Group string
IssueType string
// issue states
State string
@ -126,6 +127,7 @@ func NewCmdList(f *cmdutils.Factory, runE func(opts *ListOptions) error) *cobra.
issueListCmd.Flags().IntVarP(&opts.Page, "page", "p", 1, "Page number")
issueListCmd.Flags().IntVarP(&opts.PerPage, "per-page", "P", 30, "Number of items to list per page. (default 30)")
issueListCmd.Flags().StringVarP(&opts.Group, "group", "g", "", "Get issues from group and it's subgroups")
issueListCmd.Flags().StringVarP(&opts.IssueType, "issue-type", "t", "", "Filter issue by its type {issue|incident|test_case}")
issueListCmd.Flags().BoolP("opened", "o", false, "Get only opened issues")
_ = issueListCmd.Flags().MarkHidden("opened")
@ -215,6 +217,10 @@ func listRun(opts *ListOptions) error {
listOpts.PerPage = opts.PerPage
opts.ListType = "search"
}
if opts.IssueType != "" {
listOpts.IssueType = gitlab.String(opts.IssueType)
opts.ListType = "search"
}
var issues []*gitlab.Issue
title := utils.NewListTitle(opts.TitleQualifier + " issue")

View File

@ -181,6 +181,31 @@ func TestIssueList_tty_withFlags(t *testing.T) {
})
}
func TestIssueList_tty_withIssueType(t *testing.T) {
fakeHTTP := httpmock.New()
defer fakeHTTP.Verify(t)
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
httpmock.NewFileResponse(200, "./fixtures/incidentList.json"))
output, err := runCommand(fakeHTTP, true, "--issue-type=incident", nil, "")
if err != nil {
t.Errorf("error running command `issue list`: %v", err)
}
out := output.String()
timeRE := regexp.MustCompile(`\d+ years`)
out = timeRE.ReplaceAllString(out, "X years")
assert.Equal(t, heredoc.Doc(`
Showing 1 open issue in OWNER/REPO that match your search (Page 1)
#8 OWNER/REPO/issues/8 Incident (foo, baz) about X years ago
`), out)
assert.Equal(t, ``, output.Stderr())
}
func TestIssueList_tty_mine(t *testing.T) {
t.Run("mine with all flag and user exists", func(t *testing.T) {

View File

@ -37,6 +37,7 @@ glab issue list --milestone release-2.0.0 --opened
-C, --confidential Filter by confidential issues
-g, --group string Get issues from group and it's subgroups
--in string search in {title|description} (default "title,description")
-t, --issue-type string Filter issue by its type {issue|incident|test_case}
-l, --label strings Filter issue by label <name>
-m, --milestone string Filter issue by milestone <id>
--not-assignee strings Filter issue by not being assigneed to <username>