mirror of https://gitea.com/gitea/tea.git
Add --state flag filter to issue & PR lists (#100)
Add --state flag filter to issue & PR lists Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/100 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
12f38c892f
commit
f5d0790619
|
@ -7,7 +7,6 @@ package cmd
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -35,12 +34,18 @@ var CmdIssuesList = cli.Command{
|
|||
Usage: "List issues of the repository",
|
||||
Description: `List issues of the repository`,
|
||||
Action: runIssuesList,
|
||||
Flags: AllDefaultFlags,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by issue state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runIssues(ctx *cli.Context) error {
|
||||
if len(os.Args) == 3 {
|
||||
return runIssueDetail(ctx, os.Args[2])
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runIssueDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return runIssuesList(ctx)
|
||||
}
|
||||
|
@ -74,9 +79,19 @@ func runIssueDetail(ctx *cli.Context, index string) error {
|
|||
func runIssuesList(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
case "all":
|
||||
state = gitea.StateAll
|
||||
case "open":
|
||||
state = gitea.StateOpen
|
||||
case "closed":
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
issues, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
Page: 0,
|
||||
State: string(gitea.StateOpen),
|
||||
State: string(state),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -85,7 +100,8 @@ func runIssuesList(ctx *cli.Context) error {
|
|||
|
||||
headers := []string{
|
||||
"Index",
|
||||
"Name",
|
||||
"State",
|
||||
"Author",
|
||||
"Updated",
|
||||
"Title",
|
||||
}
|
||||
|
@ -106,6 +122,7 @@ func runIssuesList(ctx *cli.Context) error {
|
|||
values,
|
||||
[]string{
|
||||
strconv.FormatInt(issue.Index, 10),
|
||||
string(issue.State),
|
||||
name,
|
||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
||||
issue.Title,
|
||||
|
|
24
cmd/pulls.go
24
cmd/pulls.go
|
@ -19,15 +19,31 @@ var CmdPulls = cli.Command{
|
|||
Usage: "List open pull requests",
|
||||
Description: `List open pull requests`,
|
||||
Action: runPulls,
|
||||
Flags: AllDefaultFlags,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by PR state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runPulls(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
case "all":
|
||||
state = gitea.StateAll
|
||||
case "open":
|
||||
state = gitea.StateOpen
|
||||
case "closed":
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
prs, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||
Page: 0,
|
||||
State: string(gitea.StateOpen),
|
||||
State: string(state),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -36,7 +52,8 @@ func runPulls(ctx *cli.Context) error {
|
|||
|
||||
headers := []string{
|
||||
"Index",
|
||||
"Name",
|
||||
"State",
|
||||
"Author",
|
||||
"Updated",
|
||||
"Title",
|
||||
}
|
||||
|
@ -60,6 +77,7 @@ func runPulls(ctx *cli.Context) error {
|
|||
values,
|
||||
[]string{
|
||||
strconv.FormatInt(pr.Index, 10),
|
||||
string(pr.State),
|
||||
name,
|
||||
pr.Updated.Format("2006-01-02 15:04:05"),
|
||||
pr.Title,
|
||||
|
|
Loading…
Reference in New Issue