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 fac0313635 - Show all commits

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