mirror of
https://gitea.com/gitea/tea.git
synced 2024-09-01 04:14:18 -04:00
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -35,12 +34,18 @@ var CmdIssuesList = cli.Command{
|
|||||||
Usage: "List issues of the repository",
|
Usage: "List issues of the repository",
|
||||||
Description: `List issues of the repository`,
|
Description: `List issues of the repository`,
|
||||||
Action: runIssuesList,
|
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 {
|
func runIssues(ctx *cli.Context) error {
|
||||||
if len(os.Args) == 3 {
|
if ctx.Args().Len() == 1 {
|
||||||
return runIssueDetail(ctx, os.Args[2])
|
return runIssueDetail(ctx, ctx.Args().First())
|
||||||
}
|
}
|
||||||
return runIssuesList(ctx)
|
return runIssuesList(ctx)
|
||||||
}
|
}
|
||||||
@ -74,9 +79,19 @@ func runIssueDetail(ctx *cli.Context, index string) error {
|
|||||||
func runIssuesList(ctx *cli.Context) error {
|
func runIssuesList(ctx *cli.Context) error {
|
||||||
login, owner, repo := initCommand()
|
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{
|
issues, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
State: string(gitea.StateOpen),
|
State: string(state),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,7 +100,8 @@ func runIssuesList(ctx *cli.Context) error {
|
|||||||
|
|
||||||
headers := []string{
|
headers := []string{
|
||||||
"Index",
|
"Index",
|
||||||
"Name",
|
"State",
|
||||||
|
"Author",
|
||||||
"Updated",
|
"Updated",
|
||||||
"Title",
|
"Title",
|
||||||
}
|
}
|
||||||
@ -106,6 +122,7 @@ func runIssuesList(ctx *cli.Context) error {
|
|||||||
values,
|
values,
|
||||||
[]string{
|
[]string{
|
||||||
strconv.FormatInt(issue.Index, 10),
|
strconv.FormatInt(issue.Index, 10),
|
||||||
|
string(issue.State),
|
||||||
name,
|
name,
|
||||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
issue.Updated.Format("2006-01-02 15:04:05"),
|
||||||
issue.Title,
|
issue.Title,
|
||||||
|
24
cmd/pulls.go
24
cmd/pulls.go
@ -19,15 +19,31 @@ var CmdPulls = cli.Command{
|
|||||||
Usage: "List open pull requests",
|
Usage: "List open pull requests",
|
||||||
Description: `List open pull requests`,
|
Description: `List open pull requests`,
|
||||||
Action: runPulls,
|
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 {
|
func runPulls(ctx *cli.Context) error {
|
||||||
login, owner, repo := initCommand()
|
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{
|
prs, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
State: string(gitea.StateOpen),
|
State: string(state),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,7 +52,8 @@ func runPulls(ctx *cli.Context) error {
|
|||||||
|
|
||||||
headers := []string{
|
headers := []string{
|
||||||
"Index",
|
"Index",
|
||||||
"Name",
|
"State",
|
||||||
|
"Author",
|
||||||
"Updated",
|
"Updated",
|
||||||
"Title",
|
"Title",
|
||||||
}
|
}
|
||||||
@ -60,6 +77,7 @@ func runPulls(ctx *cli.Context) error {
|
|||||||
values,
|
values,
|
||||||
[]string{
|
[]string{
|
||||||
strconv.FormatInt(pr.Index, 10),
|
strconv.FormatInt(pr.Index, 10),
|
||||||
|
string(pr.State),
|
||||||
name,
|
name,
|
||||||
pr.Updated.Format("2006-01-02 15:04:05"),
|
pr.Updated.Format("2006-01-02 15:04:05"),
|
||||||
pr.Title,
|
pr.Title,
|
||||||
|
Loading…
Reference in New Issue
Block a user