mirror of https://gitea.com/gitea/tea.git
make issues & pulls subcommands consistent (#188)
Merge branch 'master' into pr-details make issues & pulls subcommands consistent - by default list open items - show detail when argument is provided - expose listing as ls subcommand - accept --state flag on command and ls subcommand Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/188 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
89e93d90b3
commit
d7f429d246
12
cmd/flags.go
12
cmd/flags.go
|
@ -53,6 +53,13 @@ var OutputFlag = cli.StringFlag{
|
||||||
Destination: &outputValue,
|
Destination: &outputValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StateFlag provides flag to specify issue/pr state, defaulting to "open"
|
||||||
|
var StateFlag = cli.StringFlag{
|
||||||
|
Name: "state",
|
||||||
|
Usage: "Filter by state (all|open|closed)",
|
||||||
|
DefaultText: "open",
|
||||||
|
}
|
||||||
|
|
||||||
// LoginOutputFlags defines login and output flags that should
|
// LoginOutputFlags defines login and output flags that should
|
||||||
// added to all subcommands and appended to the flags of the
|
// added to all subcommands and appended to the flags of the
|
||||||
// subcommand to work around issue and provide --login and --output:
|
// subcommand to work around issue and provide --login and --output:
|
||||||
|
@ -81,6 +88,11 @@ var AllDefaultFlags = append([]cli.Flag{
|
||||||
&RemoteFlag,
|
&RemoteFlag,
|
||||||
}, LoginOutputFlags...)
|
}, LoginOutputFlags...)
|
||||||
|
|
||||||
|
// IssuePRFlags defines flags that should be available on issue & pr listing flags.
|
||||||
|
var IssuePRFlags = append([]cli.Flag{
|
||||||
|
&StateFlag,
|
||||||
|
}, AllDefaultFlags...)
|
||||||
|
|
||||||
// initCommand returns repository and *Login based on flags
|
// initCommand returns repository and *Login based on flags
|
||||||
func initCommand() (*Login, string, string) {
|
func initCommand() (*Login, string, string) {
|
||||||
var login *Login
|
var login *Login
|
||||||
|
|
|
@ -28,7 +28,7 @@ var CmdIssues = cli.Command{
|
||||||
&CmdIssuesReopen,
|
&CmdIssuesReopen,
|
||||||
&CmdIssuesClose,
|
&CmdIssuesClose,
|
||||||
},
|
},
|
||||||
Flags: AllDefaultFlags,
|
Flags: IssuePRFlags,
|
||||||
}
|
}
|
||||||
|
|
||||||
// CmdIssuesList represents a sub command of issues to list issues
|
// CmdIssuesList represents a sub command of issues to list issues
|
||||||
|
@ -37,13 +37,7 @@ 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: append([]cli.Flag{
|
Flags: IssuePRFlags,
|
||||||
&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 {
|
||||||
|
|
48
cmd/pulls.go
48
cmd/pulls.go
|
@ -24,15 +24,11 @@ var CmdPulls = cli.Command{
|
||||||
Aliases: []string{"pull", "pr"},
|
Aliases: []string{"pull", "pr"},
|
||||||
Usage: "List open pull requests",
|
Usage: "List open pull requests",
|
||||||
Description: `List open pull requests`,
|
Description: `List open pull requests`,
|
||||||
|
ArgsUsage: "[<pull index>]",
|
||||||
Action: runPulls,
|
Action: runPulls,
|
||||||
Flags: append([]cli.Flag{
|
Flags: IssuePRFlags,
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "state",
|
|
||||||
Usage: "Filter by PR state (all|open|closed)",
|
|
||||||
DefaultText: "open",
|
|
||||||
},
|
|
||||||
}, AllDefaultFlags...),
|
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
|
&CmdPullsList,
|
||||||
&CmdPullsCheckout,
|
&CmdPullsCheckout,
|
||||||
&CmdPullsClean,
|
&CmdPullsClean,
|
||||||
&CmdPullsCreate,
|
&CmdPullsCreate,
|
||||||
|
@ -40,6 +36,44 @@ var CmdPulls = cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func runPulls(ctx *cli.Context) error {
|
func runPulls(ctx *cli.Context) error {
|
||||||
|
if ctx.Args().Len() == 1 {
|
||||||
|
return runPullDetail(ctx, ctx.Args().First())
|
||||||
|
}
|
||||||
|
return runPullsList(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CmdPullsList represents a sub command of issues to list pulls
|
||||||
|
var CmdPullsList = cli.Command{
|
||||||
|
Name: "ls",
|
||||||
|
Usage: "List pull requests of the repository",
|
||||||
|
Description: `List pull requests of the repository`,
|
||||||
|
Action: runPullsList,
|
||||||
|
Flags: IssuePRFlags,
|
||||||
|
}
|
||||||
|
|
||||||
|
func runPullDetail(ctx *cli.Context, index string) error {
|
||||||
|
login, owner, repo := initCommand()
|
||||||
|
|
||||||
|
idx, err := argToIndex(index)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pr, _, err := login.Client().GetPullRequest(owner, repo, idx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use glamour once #181 is merged
|
||||||
|
fmt.Printf("#%d %s\n%s created %s\n\n%s\n", pr.Index,
|
||||||
|
pr.Title,
|
||||||
|
pr.Poster.UserName,
|
||||||
|
pr.Created.Format("2006-01-02 15:04:05"),
|
||||||
|
pr.Body,
|
||||||
|
)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runPullsList(ctx *cli.Context) error {
|
||||||
login, owner, repo := initCommand()
|
login, owner, repo := initCommand()
|
||||||
|
|
||||||
state := gitea.StateOpen
|
state := gitea.StateOpen
|
||||||
|
|
Loading…
Reference in New Issue