mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 01:05:26 +01: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:
		| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Norwin
					Norwin