2020-09-30 07:11:33 +02: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 20:26:48 +01:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 18:38:22 +01:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 07:11:33 +02: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 20:26:48 +01:00
|
|
|
"github.com/araddon/dateparse"
|
2020-09-30 07:11:33 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2021-09-05 19:11:17 +02:00
|
|
|
var issueFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{
|
2023-06-06 15:25:36 +02:00
|
|
|
"index", "title", "state", "author", "milestone", "labels", "owner", "repo",
|
2021-09-05 19:11:17 +02:00
|
|
|
})
|
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
// CmdIssuesList represents a sub command of issues to list issues
|
|
|
|
var CmdIssuesList = cli.Command{
|
2020-12-16 17:47:40 +01:00
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"ls"},
|
2020-09-30 07:11:33 +02:00
|
|
|
Usage: "List issues of the repository",
|
|
|
|
Description: `List issues of the repository`,
|
2022-09-13 20:14:02 +02:00
|
|
|
ArgsUsage: " ", // command does not accept arguments
|
2020-09-30 07:11:33 +02: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 20:26:48 +01:00
|
|
|
Flags: append([]cli.Flag{issueFieldsFlag}, flags.IssueListingFlags...),
|
2020-09-30 07:11:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunIssuesList list issues
|
2020-12-15 18:38:22 +01:00
|
|
|
func RunIssuesList(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
2020-09-30 07:11:33 +02: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 20:26:48 +01:00
|
|
|
case "", "open":
|
2020-09-30 07:11:33 +02: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 20:26:48 +01: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 07:11:33 +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>
2021-12-02 20:26:48 +01: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
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 15:25:36 +02:00
|
|
|
owner := ctx.Owner
|
|
|
|
if ctx.IsSet("owner") {
|
|
|
|
owner = ctx.String("owner")
|
|
|
|
}
|
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 20:26:48 +01:00
|
|
|
|
|
|
|
// ignore error, as we don't do any input validation on these flags
|
|
|
|
labels, _ := flags.LabelFilterFlag.GetValues(cmd)
|
|
|
|
milestones, _ := flags.MilestoneFilterFlag.GetValues(cmd)
|
2023-06-06 15:25:36 +02:00
|
|
|
var issues []*gitea.Issue
|
|
|
|
if ctx.Repo != "" {
|
|
|
|
issues, _, err = ctx.Login.Client().ListRepoIssues(owner, ctx.Repo, gitea.ListIssueOption{
|
|
|
|
ListOptions: ctx.GetListOptions(),
|
|
|
|
State: state,
|
|
|
|
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,
|
|
|
|
})
|
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 20:26:48 +01:00
|
|
|
|
2023-06-06 15:25:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
issues, _, err = ctx.Login.Client().ListIssues(gitea.ListIssueOption{
|
|
|
|
ListOptions: ctx.GetListOptions(),
|
|
|
|
State: state,
|
|
|
|
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,
|
|
|
|
Owner: owner,
|
|
|
|
})
|
2020-09-30 07:11:33 +02:00
|
|
|
|
2023-06-06 15:25:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-30 07:11:33 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 19:11:17 +02:00
|
|
|
fields, err := issueFieldsFlag.GetValues(cmd)
|
2020-12-21 16:41:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
print.IssuesPullsList(issues, ctx.Output, fields)
|
2020-09-30 07:11:33 +02:00
|
|
|
return nil
|
|
|
|
}
|