2018-09-03 14:43:00 +08: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-12-08 12:06:05 +08:00
|
|
|
"fmt"
|
|
|
|
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
|
|
"code.gitea.io/tea/cmd/pulls"
|
2020-12-16 01:38:22 +08:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-10-02 22:15:18 +08:00
|
|
|
"code.gitea.io/tea/modules/print"
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/modules/utils"
|
2018-09-03 14:43:00 +08:00
|
|
|
|
2020-12-08 12:06:05 +08:00
|
|
|
"code.gitea.io/sdk/gitea"
|
2020-01-05 01:44:25 +08:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 14:43:00 +08:00
|
|
|
)
|
|
|
|
|
2020-04-19 11:09:03 +08:00
|
|
|
// CmdPulls is the main command to operate on PRs
|
2018-09-03 14:43:00 +08:00
|
|
|
var CmdPulls = cli.Command{
|
|
|
|
Name: "pulls",
|
2020-04-19 11:09:03 +08:00
|
|
|
Aliases: []string{"pull", "pr"},
|
2020-09-27 22:35:53 +08:00
|
|
|
Usage: "List, create, checkout and clean pull requests",
|
|
|
|
Description: `List, create, checkout and clean pull requests`,
|
2020-09-21 13:03:20 +08:00
|
|
|
ArgsUsage: "[<pull index>]",
|
2018-09-03 14:43:00 +08:00
|
|
|
Action: runPulls,
|
2020-09-30 13:11:33 +08:00
|
|
|
Flags: flags.IssuePRFlags,
|
2020-04-19 11:09:03 +08:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 13:11:33 +08:00
|
|
|
&pulls.CmdPullsList,
|
|
|
|
&pulls.CmdPullsCheckout,
|
|
|
|
&pulls.CmdPullsClean,
|
|
|
|
&pulls.CmdPullsCreate,
|
2020-04-19 11:09:03 +08:00
|
|
|
},
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runPulls(ctx *cli.Context) error {
|
2020-09-21 13:03:20 +08:00
|
|
|
if ctx.Args().Len() == 1 {
|
2020-12-16 01:38:22 +08:00
|
|
|
return runPullDetail(ctx, ctx.Args().First())
|
2020-09-21 13:03:20 +08:00
|
|
|
}
|
2020-09-30 13:11:33 +08:00
|
|
|
return pulls.RunPullsList(ctx)
|
2020-09-21 13:03:20 +08:00
|
|
|
}
|
|
|
|
|
2020-12-16 01:38:22 +08:00
|
|
|
func runPullDetail(cmd *cli.Context, index string) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
2020-09-30 13:11:33 +08:00
|
|
|
idx, err := utils.ArgToIndex(index)
|
2020-09-21 13:03:20 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-08 12:06:05 +08:00
|
|
|
|
2020-12-16 01:38:22 +08:00
|
|
|
client := ctx.Login.Client()
|
|
|
|
pr, _, err := client.GetPullRequest(ctx.Owner, ctx.Repo, idx)
|
2020-09-21 13:03:20 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-16 01:38:22 +08:00
|
|
|
reviews, _, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{})
|
2020-12-08 12:06:05 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("error while loading reviews: %v\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
print.PullDetails(pr, reviews)
|
2020-09-21 13:03:20 +08:00
|
|
|
return nil
|
|
|
|
}
|