Add --state flag filter to issue & PR lists #100

Merged
6543 merged 3 commits from noerw/tea:state-flag into master 2020-03-29 13:16:10 +00:00
Showing only changes of commit ffb5979bfb - Show all commits

@ -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,