mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
Implement more issue filters (#400)
This adds new filters to `tea issues ls` and `tea pr ls`, made available in SDK 0.15: ``` --state value Filter by state (all|open|closed) (default: open) --keyword value, -k value Filter by search string --labels value, -L value Comma-separated list of labels to match issues against. --milestones value, -m value Comma-separated list of milestones to match issues against. --author value, -A value --assignee value, -a value --mentions value, -M value --from value, -F value Filter by activity after this date --until value, -u value Filter by activity before this date ``` Note: I felt free to change parameter names as exposed by SDK & API, as the names exposed by them are partially bollocks (eg `mentioned_by`) and or inconsistent with usage in other commands (eg `tea times --until`) fixes #376, related #323 Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/400 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -5,11 +5,15 @@
|
||||
package issues
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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"
|
||||
)
|
||||
|
||||
@ -24,7 +28,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
|
||||
@ -36,16 +40,57 @@ 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
|
||||
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,
|
||||
Type: kind,
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user