From 77fe634c8a52c5b95ec1449abb4d560e081e89e4 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 14 Sep 2021 11:07:31 +0200 Subject: [PATCH 1/8] split up cmd/flags/flags.go --- cmd/flags/{flags.go => generic.go} | 98 -------------------------- cmd/flags/issue_pr.go | 107 +++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 98 deletions(-) rename cmd/flags/{flags.go => generic.go} (57%) create mode 100644 cmd/flags/issue_pr.go diff --git a/cmd/flags/flags.go b/cmd/flags/generic.go similarity index 57% rename from cmd/flags/flags.go rename to cmd/flags/generic.go index c3de546..b86ab3c 100644 --- a/cmd/flags/flags.go +++ b/cmd/flags/generic.go @@ -5,14 +5,6 @@ package flags import ( - "fmt" - "strings" - - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" - - "github.com/araddon/dateparse" "github.com/urfave/cli/v2" ) @@ -44,13 +36,6 @@ var OutputFlag = cli.StringFlag{ Usage: "Output format. (csv, simple, table, tsv, yaml)", } -// StateFlag provides flag to specify issue/pr state, defaulting to "open" -var StateFlag = cli.StringFlag{ - Name: "state", - Usage: "Filter by state (all|open|closed)", - DefaultText: "open", -} - // PaginationPageFlag provides flag for pagination options var PaginationPageFlag = cli.StringFlag{ Name: "page", @@ -93,13 +78,6 @@ var AllDefaultFlags = append([]cli.Flag{ &RemoteFlag, }, LoginOutputFlags...) -// IssuePRFlags defines flags that should be available on issue & pr listing flags. -var IssuePRFlags = append([]cli.Flag{ - &StateFlag, - &PaginationPageFlag, - &PaginationLimitFlag, -}, AllDefaultFlags...) - // NotificationFlags defines flags that should be available on notifications. var NotificationFlags = append([]cli.Flag{ NotificationStateFlag, @@ -121,82 +99,6 @@ var NotificationStateFlag = NewCsvFlag( []string{"unread", "pinned"}, ) -// IssuePREditFlags defines flags for properties of issues and PRs -var IssuePREditFlags = append([]cli.Flag{ - &cli.StringFlag{ - Name: "title", - Aliases: []string{"t"}, - }, - &cli.StringFlag{ - Name: "description", - Aliases: []string{"d"}, - }, - &cli.StringFlag{ - Name: "assignees", - Aliases: []string{"a"}, - Usage: "Comma-separated list of usernames to assign", - }, - &cli.StringFlag{ - Name: "labels", - Aliases: []string{"L"}, - Usage: "Comma-separated list of labels to assign", - }, - &cli.StringFlag{ - Name: "deadline", - Aliases: []string{"D"}, - Usage: "Deadline timestamp to assign", - }, - &cli.StringFlag{ - Name: "milestone", - Aliases: []string{"m"}, - Usage: "Milestone to assign", - }, -}, LoginRepoFlags...) - -// GetIssuePREditFlags parses all IssuePREditFlags -func GetIssuePREditFlags(ctx *context.TeaContext) (*gitea.CreateIssueOption, error) { - opts := gitea.CreateIssueOption{ - Title: ctx.String("title"), - Body: ctx.String("description"), - Assignees: strings.Split(ctx.String("assignees"), ","), - } - var err error - - date := ctx.String("deadline") - if date != "" { - t, err := dateparse.ParseAny(date) - if err != nil { - return nil, err - } - opts.Deadline = &t - } - - client := ctx.Login.Client() - - labelNames := strings.Split(ctx.String("labels"), ",") - if len(labelNames) != 0 { - if client == nil { - client = ctx.Login.Client() - } - if opts.Labels, err = task.ResolveLabelNames(client, ctx.Owner, ctx.Repo, labelNames); err != nil { - return nil, err - } - } - - if milestoneName := ctx.String("milestone"); len(milestoneName) != 0 { - if client == nil { - client = ctx.Login.Client() - } - ms, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestoneName) - if err != nil { - return nil, fmt.Errorf("Milestone '%s' not found", milestoneName) - } - opts.Milestone = ms.ID - } - - return &opts, nil -} - // FieldsFlag generates a flag selecting printable fields. // To retrieve the value, use f.GetValues() func FieldsFlag(availableFields, defaultFields []string) *CsvFlag { diff --git a/cmd/flags/issue_pr.go b/cmd/flags/issue_pr.go new file mode 100644 index 0000000..02382c2 --- /dev/null +++ b/cmd/flags/issue_pr.go @@ -0,0 +1,107 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package flags + +import ( + "fmt" + "strings" + + "code.gitea.io/sdk/gitea" + "code.gitea.io/tea/modules/context" + "code.gitea.io/tea/modules/task" + + "github.com/araddon/dateparse" + "github.com/urfave/cli/v2" +) + +// StateFlag provides flag to specify issue/pr state, defaulting to "open" +var StateFlag = cli.StringFlag{ + Name: "state", + Usage: "Filter by state (all|open|closed)", + DefaultText: "open", +} + +// IssuePRFlags defines flags that should be available on issue & pr listing flags. +var IssuePRFlags = append([]cli.Flag{ + &StateFlag, + &PaginationPageFlag, + &PaginationLimitFlag, +}, AllDefaultFlags...) + +// IssuePREditFlags defines flags for properties of issues and PRs +var IssuePREditFlags = append([]cli.Flag{ + &cli.StringFlag{ + Name: "title", + Aliases: []string{"t"}, + }, + &cli.StringFlag{ + Name: "description", + Aliases: []string{"d"}, + }, + &cli.StringFlag{ + Name: "assignees", + Aliases: []string{"a"}, + Usage: "Comma-separated list of usernames to assign", + }, + &cli.StringFlag{ + Name: "labels", + Aliases: []string{"L"}, + Usage: "Comma-separated list of labels to assign", + }, + &cli.StringFlag{ + Name: "deadline", + Aliases: []string{"D"}, + Usage: "Deadline timestamp to assign", + }, + &cli.StringFlag{ + Name: "milestone", + Aliases: []string{"m"}, + Usage: "Milestone to assign", + }, +}, LoginRepoFlags...) + +// GetIssuePREditFlags parses all IssuePREditFlags +func GetIssuePREditFlags(ctx *context.TeaContext) (*gitea.CreateIssueOption, error) { + opts := gitea.CreateIssueOption{ + Title: ctx.String("title"), + Body: ctx.String("description"), + Assignees: strings.Split(ctx.String("assignees"), ","), + } + var err error + + date := ctx.String("deadline") + if date != "" { + t, err := dateparse.ParseAny(date) + if err != nil { + return nil, err + } + opts.Deadline = &t + } + + client := ctx.Login.Client() + + labelNames := strings.Split(ctx.String("labels"), ",") + if len(labelNames) != 0 { + if client == nil { + client = ctx.Login.Client() + } + if opts.Labels, err = task.ResolveLabelNames(client, ctx.Owner, ctx.Repo, labelNames); err != nil { + return nil, err + } + } + + if milestoneName := ctx.String("milestone"); len(milestoneName) != 0 { + if client == nil { + client = ctx.Login.Client() + } + ms, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestoneName) + if err != nil { + return nil, fmt.Errorf("Milestone '%s' not found", milestoneName) + } + opts.Milestone = ms.ID + } + + return &opts, nil +} -- 2.40.1 From 2cd2363000698c81bf8e723dad056f2ebc9c0a3c Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 14 Sep 2021 11:12:08 +0200 Subject: [PATCH 2/8] add new issue filter flags they are now exposed on `tea pr ls` too, but have no effect yet --- cmd/flags/issue_pr.go | 39 +++++++++++++++++++++++++++++++++++++++ cmd/issues/list.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/cmd/flags/issue_pr.go b/cmd/flags/issue_pr.go index 02382c2..4540194 100644 --- a/cmd/flags/issue_pr.go +++ b/cmd/flags/issue_pr.go @@ -23,9 +23,48 @@ var StateFlag = cli.StringFlag{ DefaultText: "open", } +var MilestoneFilterFlag = NewCsvFlag( + "milestones", + "milestones to match issues against", + []string{"m"}, nil, nil) + +var LabelFilterFlag = NewCsvFlag( + "labels", + "labels to match issues against", + []string{"L"}, nil, nil) + // IssuePRFlags defines flags that should be available on issue & pr listing flags. var IssuePRFlags = append([]cli.Flag{ &StateFlag, + &cli.StringFlag{ + Name: "keyword", + Aliases: []string{"k"}, + Usage: "Filter by search string", + }, + LabelFilterFlag, + MilestoneFilterFlag, + &cli.StringFlag{ + Name: "author", + Aliases: []string{"A"}, + }, + &cli.StringFlag{ + Name: "assignee", + Aliases: []string{"a"}, + }, + &cli.StringFlag{ + Name: "mentions", + Aliases: []string{"M"}, + }, + &cli.StringFlag{ + Name: "from", + Aliases: []string{"F"}, + Usage: "Filter by activity after this date", + }, + &cli.StringFlag{ + Name: "until", + Aliases: []string{"u"}, + Usage: "Filter by activity before this date", + }, &PaginationPageFlag, &PaginationLimitFlag, }, AllDefaultFlags...) diff --git a/cmd/issues/list.go b/cmd/issues/list.go index 3089af3..d6aa59b 100644 --- a/cmd/issues/list.go +++ b/cmd/issues/list.go @@ -5,11 +5,14 @@ package issues import ( + "time" + "code.gitea.io/tea/cmd/flags" "code.gitea.io/tea/modules/context" "code.gitea.io/tea/modules/print" "code.gitea.io/sdk/gitea" + "github.com/araddon/dateparse" "github.com/urfave/cli/v2" ) @@ -42,10 +45,37 @@ func RunIssuesList(cmd *cli.Context) error { state = gitea.StateClosed } + var err error + var from, until time.Time + if ctx.IsSet("from") { + from, err = dateparse.ParseLocal(ctx.String("from")) + if err != nil { + return err + } + } + if ctx.IsSet("until") { + until, err = dateparse.ParseLocal(ctx.String("until")) + if err != nil { + return err + } + } + + // ignore error, as we don't do any input validation on these flags + labels, _ := flags.LabelFilterFlag.GetValues(cmd) + milestones, _ := flags.MilestoneFilterFlag.GetValues(cmd) + issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{ ListOptions: ctx.GetListOptions(), State: state, Type: gitea.IssueTypeIssue, + KeyWord: ctx.String("keyword"), + CreatedBy: ctx.String("author"), + AssignedBy: ctx.String("assigned-to"), + MentionedBy: ctx.String("mentions"), + Labels: labels, + Milestones: milestones, + Since: from, + Before: until, }) if err != nil { -- 2.40.1 From bbcb4f63d7a7491fef266b0f30ef33503879cb59 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 14 Sep 2021 11:41:03 +0200 Subject: [PATCH 3/8] make NewCsvFlag() smarter --- cmd/flags/csvflag.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/flags/csvflag.go b/cmd/flags/csvflag.go index 99f80fb..02def8e 100644 --- a/cmd/flags/csvflag.go +++ b/cmd/flags/csvflag.go @@ -21,15 +21,19 @@ type CsvFlag struct { // NewCsvFlag creates a CsvFlag, while setting its usage string and default values func NewCsvFlag(name, usage string, aliases, availableValues, defaults []string) *CsvFlag { + var availableDesc string + if len(availableValues) != 0 { + availableDesc = " Available values:" + } return &CsvFlag{ AvailableFields: availableValues, StringFlag: cli.StringFlag{ Name: name, Aliases: aliases, Value: strings.Join(defaults, ","), - Usage: fmt.Sprintf(`Comma-separated list of %s. Available values: + Usage: fmt.Sprintf(`Comma-separated list of %s.%s %s - `, usage, strings.Join(availableValues, ",")), + `, usage, availableDesc, strings.Join(availableValues, ",")), }, } } -- 2.40.1 From e1094c47a032e717a87ce5d344d58d8239e280d9 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 14 Sep 2021 11:48:02 +0200 Subject: [PATCH 4/8] refactor `pr list` to use same filter flags as issues previously we used the /pulls endpoint, but that didn't support many filters (https://gitea.com/api/swagger#/repository/repoListPullRequests). Instead, we now do an issue listing, which also supports listing PRs. The drawback here is that it only returns issue fields, but none of a PR's special fields like head repo, base branch, mergeable flag, ... This is a limitation of the upstream API, and we should carefully decide which limitation to take, as changes to the API etc will take quite some time to propagate through the ecosystem This commit also adds the --fields flag to `tea pulls list`, with the same fields available as issues (see above) --- cmd/issues/list.go | 7 ++++++- cmd/pulls/list.go | 32 +++++++------------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/cmd/issues/list.go b/cmd/issues/list.go index d6aa59b..21baa7b 100644 --- a/cmd/issues/list.go +++ b/cmd/issues/list.go @@ -32,6 +32,11 @@ var CmdIssuesList = cli.Command{ // RunIssuesList list issues func RunIssuesList(cmd *cli.Context) error { + return DoIssuePRListing(cmd, gitea.IssueTypeIssue, issueFieldsFlag) +} + +// DoIssuePRListing lists issues + PRs of the repo in a generic way, and handles parsing of all filter flags. +func DoIssuePRListing(cmd *cli.Context, kind gitea.IssueType, fieldsFlag *flags.CsvFlag) error { ctx := context.InitCommand(cmd) ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) @@ -67,7 +72,7 @@ func RunIssuesList(cmd *cli.Context) error { issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{ ListOptions: ctx.GetListOptions(), State: state, - Type: gitea.IssueTypeIssue, + Type: kind, KeyWord: ctx.String("keyword"), CreatedBy: ctx.String("author"), AssignedBy: ctx.String("assigned-to"), diff --git a/cmd/pulls/list.go b/cmd/pulls/list.go index 5037b48..fddb213 100644 --- a/cmd/pulls/list.go +++ b/cmd/pulls/list.go @@ -6,13 +6,17 @@ package pulls import ( "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "code.gitea.io/tea/cmd/issues" "code.gitea.io/tea/modules/print" "code.gitea.io/sdk/gitea" "github.com/urfave/cli/v2" ) +var prFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{ + "index", "title", "state", "author", "milestone", "updated", +}) + // CmdPullsList represents a sub command of issues to list pulls var CmdPullsList = cli.Command{ Name: "list", @@ -20,32 +24,10 @@ var CmdPullsList = cli.Command{ Usage: "List pull requests of the repository", Description: `List pull requests of the repository`, Action: RunPullsList, - Flags: flags.IssuePRFlags, + Flags: append([]cli.Flag{prFieldsFlag}, flags.IssuePRFlags...), } // RunPullsList return list of pulls func RunPullsList(cmd *cli.Context) error { - ctx := context.InitCommand(cmd) - ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) - - state := gitea.StateOpen - switch ctx.String("state") { - case "all": - state = gitea.StateAll - case "open": - state = gitea.StateOpen - case "closed": - state = gitea.StateClosed - } - - prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{ - State: state, - }) - - if err != nil { - return err - } - - print.PullsList(prs, ctx.Output) - return nil + return issues.DoIssuePRListing(cmd, gitea.IssueTypePull, prFieldsFlag) } -- 2.40.1 From 9baad74766fce32b197d17b6381bd97d7df0a299 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 14 Sep 2021 12:06:25 +0200 Subject: [PATCH 5/8] lint --- cmd/flags/issue_pr.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/flags/issue_pr.go b/cmd/flags/issue_pr.go index 4540194..4b1124d 100644 --- a/cmd/flags/issue_pr.go +++ b/cmd/flags/issue_pr.go @@ -23,11 +23,13 @@ var StateFlag = cli.StringFlag{ DefaultText: "open", } +// MilestoneFilterFlag is a CSV flag used to filter issues by milestones var MilestoneFilterFlag = NewCsvFlag( "milestones", "milestones to match issues against", []string{"m"}, nil, nil) +// LabelFilterFlag is a CSV flag used to filter issues by labels var LabelFilterFlag = NewCsvFlag( "labels", "labels to match issues against", -- 2.40.1 From 31ee79ae4c6838c78d7c85b5b9fcaf90ec8955f5 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 28 Sep 2021 10:31:32 +0200 Subject: [PATCH 6/8] Revert "refactor `pr list` to use same filter flags as issues" This reverts commit e1094c47a032e717a87ce5d344d58d8239e280d9. --- cmd/issues/list.go | 7 +------ cmd/pulls/list.go | 32 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/cmd/issues/list.go b/cmd/issues/list.go index 21baa7b..d6aa59b 100644 --- a/cmd/issues/list.go +++ b/cmd/issues/list.go @@ -32,11 +32,6 @@ var CmdIssuesList = cli.Command{ // RunIssuesList list issues func RunIssuesList(cmd *cli.Context) error { - return DoIssuePRListing(cmd, gitea.IssueTypeIssue, issueFieldsFlag) -} - -// DoIssuePRListing lists issues + PRs of the repo in a generic way, and handles parsing of all filter flags. -func DoIssuePRListing(cmd *cli.Context, kind gitea.IssueType, fieldsFlag *flags.CsvFlag) error { ctx := context.InitCommand(cmd) ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) @@ -72,7 +67,7 @@ func DoIssuePRListing(cmd *cli.Context, kind gitea.IssueType, fieldsFlag *flags. issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{ ListOptions: ctx.GetListOptions(), State: state, - Type: kind, + Type: gitea.IssueTypeIssue, KeyWord: ctx.String("keyword"), CreatedBy: ctx.String("author"), AssignedBy: ctx.String("assigned-to"), diff --git a/cmd/pulls/list.go b/cmd/pulls/list.go index fddb213..5037b48 100644 --- a/cmd/pulls/list.go +++ b/cmd/pulls/list.go @@ -6,17 +6,13 @@ package pulls import ( "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/issues" + "code.gitea.io/tea/modules/context" "code.gitea.io/tea/modules/print" "code.gitea.io/sdk/gitea" "github.com/urfave/cli/v2" ) -var prFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{ - "index", "title", "state", "author", "milestone", "updated", -}) - // CmdPullsList represents a sub command of issues to list pulls var CmdPullsList = cli.Command{ Name: "list", @@ -24,10 +20,32 @@ var CmdPullsList = cli.Command{ Usage: "List pull requests of the repository", Description: `List pull requests of the repository`, Action: RunPullsList, - Flags: append([]cli.Flag{prFieldsFlag}, flags.IssuePRFlags...), + Flags: flags.IssuePRFlags, } // RunPullsList return list of pulls func RunPullsList(cmd *cli.Context) error { - return issues.DoIssuePRListing(cmd, gitea.IssueTypePull, prFieldsFlag) + ctx := context.InitCommand(cmd) + ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) + + state := gitea.StateOpen + switch ctx.String("state") { + case "all": + state = gitea.StateAll + case "open": + state = gitea.StateOpen + case "closed": + state = gitea.StateClosed + } + + prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{ + State: state, + }) + + if err != nil { + return err + } + + print.PullsList(prs, ctx.Output) + return nil } -- 2.40.1 From 635de20ce2bf501bd9110d2200674d3009313354 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 28 Sep 2021 11:37:02 +0200 Subject: [PATCH 7/8] separate IssuePRListing flags again as the APIs are incompatible --- cmd/flags/issue_pr.go | 11 +++++++++-- cmd/issues/list.go | 2 +- cmd/pulls/list.go | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/flags/issue_pr.go b/cmd/flags/issue_pr.go index 4b1124d..a026d36 100644 --- a/cmd/flags/issue_pr.go +++ b/cmd/flags/issue_pr.go @@ -35,8 +35,15 @@ var LabelFilterFlag = NewCsvFlag( "labels to match issues against", []string{"L"}, nil, nil) -// IssuePRFlags defines flags that should be available on issue & pr listing flags. -var IssuePRFlags = append([]cli.Flag{ +// PRListingFlags defines flags that should be available on pr listing flags. +var PRListingFlags = append([]cli.Flag{ + &StateFlag, + &PaginationPageFlag, + &PaginationLimitFlag, +}, AllDefaultFlags...) + +// IssueListingFlags defines flags that should be available on issue listing flags. +var IssueListingFlags = append([]cli.Flag{ &StateFlag, &cli.StringFlag{ Name: "keyword", diff --git a/cmd/issues/list.go b/cmd/issues/list.go index d6aa59b..e68697f 100644 --- a/cmd/issues/list.go +++ b/cmd/issues/list.go @@ -27,7 +27,7 @@ var CmdIssuesList = cli.Command{ Usage: "List issues of the repository", Description: `List issues of the repository`, Action: RunIssuesList, - Flags: append([]cli.Flag{issueFieldsFlag}, flags.IssuePRFlags...), + Flags: append([]cli.Flag{issueFieldsFlag}, flags.IssueListingFlags...), } // RunIssuesList list issues diff --git a/cmd/pulls/list.go b/cmd/pulls/list.go index 5037b48..c1bae56 100644 --- a/cmd/pulls/list.go +++ b/cmd/pulls/list.go @@ -20,7 +20,7 @@ var CmdPullsList = cli.Command{ Usage: "List pull requests of the repository", Description: `List pull requests of the repository`, Action: RunPullsList, - Flags: flags.IssuePRFlags, + Flags: flags.PRListingFlags, } // RunPullsList return list of pulls -- 2.40.1 From bdbf678dabd9b04fa0c337d1945ea40af80ebd88 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 28 Sep 2021 11:46:20 +0200 Subject: [PATCH 8/8] add --kind, to make keyword search on PRs available for PRs too as a workaround for the missing filters on the PR listing API, tea issues can also show PRs now --- cmd/flags/issue_pr.go | 6 ++++++ cmd/issues/list.go | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/flags/issue_pr.go b/cmd/flags/issue_pr.go index a026d36..71d1e0a 100644 --- a/cmd/flags/issue_pr.go +++ b/cmd/flags/issue_pr.go @@ -45,6 +45,12 @@ var PRListingFlags = append([]cli.Flag{ // IssueListingFlags defines flags that should be available on issue listing flags. var IssueListingFlags = append([]cli.Flag{ &StateFlag, + &cli.StringFlag{ + Name: "kind", + Aliases: []string{"K"}, + Usage: "Wether to return `issues`, `pulls`, or `all` (you can use this to apply advanced search filters to PRs)", + DefaultText: "issues", + }, &cli.StringFlag{ Name: "keyword", Aliases: []string{"k"}, diff --git a/cmd/issues/list.go b/cmd/issues/list.go index e68697f..e5999fb 100644 --- a/cmd/issues/list.go +++ b/cmd/issues/list.go @@ -5,6 +5,7 @@ package issues import ( + "fmt" "time" "code.gitea.io/tea/cmd/flags" @@ -39,10 +40,24 @@ func RunIssuesList(cmd *cli.Context) error { switch ctx.String("state") { case "all": state = gitea.StateAll - case "open": + case "", "open": state = gitea.StateOpen case "closed": state = gitea.StateClosed + default: + return fmt.Errorf("unknown state '%s'", ctx.String("state")) + } + + kind := gitea.IssueTypeIssue + switch ctx.String("kind") { + case "", "issues", "issue": + kind = gitea.IssueTypeIssue + case "pulls", "pull", "pr": + kind = gitea.IssueTypePull + case "all": + kind = gitea.IssueTypeAll + default: + return fmt.Errorf("unknown kind '%s'", ctx.String("kind")) } var err error @@ -67,7 +82,7 @@ func RunIssuesList(cmd *cli.Context) error { issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{ ListOptions: ctx.GetListOptions(), State: state, - Type: gitea.IssueTypeIssue, + Type: kind, KeyWord: ctx.String("keyword"), CreatedBy: ctx.String("author"), AssignedBy: ctx.String("assigned-to"), -- 2.40.1