2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 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 issues
|
|
|
|
|
|
|
|
import (
|
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>
2021-12-02 19:26:48 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
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>
2021-12-02 19:26:48 +00:00
|
|
|
"github.com/araddon/dateparse"
|
2020-09-30 05:11:33 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2021-09-05 17:11:17 +00:00
|
|
|
var issueFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{
|
|
|
|
"index", "title", "state", "author", "milestone", "labels",
|
|
|
|
})
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
// CmdIssuesList represents a sub command of issues to list issues
|
|
|
|
var CmdIssuesList = cli.Command{
|
2020-12-16 16:47:40 +00:00
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"ls"},
|
2020-09-30 05:11:33 +00:00
|
|
|
Usage: "List issues of the repository",
|
|
|
|
Description: `List issues of the repository`,
|
2022-09-13 18:14:02 +00:00
|
|
|
ArgsUsage: " ", // command does not accept arguments
|
2020-09-30 05:11:33 +00:00
|
|
|
Action: RunIssuesList,
|
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>
2021-12-02 19:26:48 +00:00
|
|
|
Flags: append([]cli.Flag{issueFieldsFlag}, flags.IssueListingFlags...),
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunIssuesList list issues
|
2020-12-15 17:38:22 +00:00
|
|
|
func RunIssuesList(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
state := gitea.StateOpen
|
|
|
|
switch ctx.String("state") {
|
|
|
|
case "all":
|
|
|
|
state = gitea.StateAll
|
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>
2021-12-02 19:26:48 +00:00
|
|
|
case "", "open":
|
2020-09-30 05:11:33 +00:00
|
|
|
state = gitea.StateOpen
|
|
|
|
case "closed":
|
|
|
|
state = gitea.StateClosed
|
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>
2021-12-02 19:26:48 +00:00
|
|
|
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"))
|
2020-09-30 05:11:33 +00: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>
2021-12-02 19:26:48 +00:00
|
|
|
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)
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
|
|
|
|
ListOptions: ctx.GetListOptions(),
|
2020-09-30 05:11:33 +00:00
|
|
|
State: state,
|
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>
2021-12-02 19:26:48 +00:00
|
|
|
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,
|
2020-09-30 05:11:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2020-12-16 16:18:10 +00:00
|
|
|
return err
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 17:11:17 +00:00
|
|
|
fields, err := issueFieldsFlag.GetValues(cmd)
|
2020-12-21 15:41:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
print.IssuesPullsList(issues, ctx.Output, fields)
|
2020-09-30 05:11:33 +00:00
|
|
|
return nil
|
|
|
|
}
|