mirror of
https://gitea.com/gitea/tea
synced 2024-10-31 21:20:23 +00:00
dc67630b64
introduce TeaContext clean up InitCommand move GetListOptions to TeaContext ensure context for each command so we fail early with a good error message instead of "Error: 404" etc make linter happy Merge branch 'master' into refactor-global-flags move TeaContext & InitCommand to modules/context Merge branch 'master' into refactor-global-flags CI.restart() Merge branch 'master' into refactor-global-flags Merge branch 'master' into refactor-global-flags Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/291 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
// 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 (
|
|
"fmt"
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/cmd/pulls"
|
|
"code.gitea.io/tea/modules/context"
|
|
"code.gitea.io/tea/modules/print"
|
|
"code.gitea.io/tea/modules/utils"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// CmdPulls is the main command to operate on PRs
|
|
var CmdPulls = cli.Command{
|
|
Name: "pulls",
|
|
Aliases: []string{"pull", "pr"},
|
|
Usage: "List, create, checkout and clean pull requests",
|
|
Description: `List, create, checkout and clean pull requests`,
|
|
ArgsUsage: "[<pull index>]",
|
|
Action: runPulls,
|
|
Flags: flags.IssuePRFlags,
|
|
Subcommands: []*cli.Command{
|
|
&pulls.CmdPullsList,
|
|
&pulls.CmdPullsCheckout,
|
|
&pulls.CmdPullsClean,
|
|
&pulls.CmdPullsCreate,
|
|
},
|
|
}
|
|
|
|
func runPulls(ctx *cli.Context) error {
|
|
if ctx.Args().Len() == 1 {
|
|
return runPullDetail(ctx, ctx.Args().First())
|
|
}
|
|
return pulls.RunPullsList(ctx)
|
|
}
|
|
|
|
func runPullDetail(cmd *cli.Context, index string) error {
|
|
ctx := context.InitCommand(cmd)
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
idx, err := utils.ArgToIndex(index)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client := ctx.Login.Client()
|
|
pr, _, err := client.GetPullRequest(ctx.Owner, ctx.Repo, idx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
reviews, _, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{})
|
|
if err != nil {
|
|
fmt.Printf("error while loading reviews: %v\n", err)
|
|
}
|
|
|
|
print.PullDetails(pr, reviews)
|
|
return nil
|
|
}
|