2018-09-03 02:43:00 -04:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-09-30 01:11:33 -04:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
|
|
"code.gitea.io/tea/cmd/pulls"
|
|
|
|
"code.gitea.io/tea/modules/config"
|
2020-10-02 10:15:18 -04:00
|
|
|
"code.gitea.io/tea/modules/print"
|
2020-09-30 01:11:33 -04:00
|
|
|
"code.gitea.io/tea/modules/utils"
|
2018-09-03 02:43:00 -04:00
|
|
|
|
2020-01-04 12:44:25 -05:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 02:43:00 -04:00
|
|
|
)
|
|
|
|
|
2020-04-18 23:09:03 -04:00
|
|
|
// CmdPulls is the main command to operate on PRs
|
2018-09-03 02:43:00 -04:00
|
|
|
var CmdPulls = cli.Command{
|
|
|
|
Name: "pulls",
|
2020-04-18 23:09:03 -04:00
|
|
|
Aliases: []string{"pull", "pr"},
|
2020-09-27 10:35:53 -04:00
|
|
|
Usage: "List, create, checkout and clean pull requests",
|
|
|
|
Description: `List, create, checkout and clean pull requests`,
|
2020-09-21 01:03:20 -04:00
|
|
|
ArgsUsage: "[<pull index>]",
|
2018-09-03 02:43:00 -04:00
|
|
|
Action: runPulls,
|
2020-09-30 01:11:33 -04:00
|
|
|
Flags: flags.IssuePRFlags,
|
2020-04-18 23:09:03 -04:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 01:11:33 -04:00
|
|
|
&pulls.CmdPullsList,
|
|
|
|
&pulls.CmdPullsCheckout,
|
|
|
|
&pulls.CmdPullsClean,
|
|
|
|
&pulls.CmdPullsCreate,
|
2020-04-18 23:09:03 -04:00
|
|
|
},
|
2018-09-03 02:43:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func runPulls(ctx *cli.Context) error {
|
2020-09-21 01:03:20 -04:00
|
|
|
if ctx.Args().Len() == 1 {
|
2020-09-30 01:11:33 -04:00
|
|
|
return runPullDetail(ctx.Args().First())
|
2020-09-21 01:03:20 -04:00
|
|
|
}
|
2020-09-30 01:11:33 -04:00
|
|
|
return pulls.RunPullsList(ctx)
|
2020-09-21 01:03:20 -04:00
|
|
|
}
|
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
func runPullDetail(index string) error {
|
|
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
2020-09-21 01:03:20 -04:00
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
idx, err := utils.ArgToIndex(index)
|
2020-09-21 01:03:20 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pr, _, err := login.Client().GetPullRequest(owner, repo, idx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-02 10:15:18 -04:00
|
|
|
print.PullDetails(pr)
|
2020-09-21 01:03:20 -04:00
|
|
|
return nil
|
|
|
|
}
|