2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 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 pulls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-12-08 21:41:50 +00:00
|
|
|
"code.gitea.io/tea/modules/interact"
|
|
|
|
"code.gitea.io/tea/modules/task"
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdPullsCreate creates a pull request
|
|
|
|
var CmdPullsCreate = cli.Command{
|
|
|
|
Name: "create",
|
2020-12-16 16:47:40 +00:00
|
|
|
Aliases: []string{"c"},
|
2020-09-30 05:11:33 +00:00
|
|
|
Usage: "Create a pull-request",
|
|
|
|
Description: "Create a pull-request",
|
|
|
|
Action: runPullsCreate,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "head",
|
|
|
|
Usage: "Set head branch (default is current one)",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "base",
|
|
|
|
Aliases: []string{"b"},
|
|
|
|
Usage: "Set base branch (default is default branch)",
|
|
|
|
},
|
2021-03-08 11:48:03 +00:00
|
|
|
}, flags.IssuePREditFlags...),
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
func runPullsCreate(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
|
2020-09-30 05:11:33 +00:00
|
|
|
|
2020-12-08 21:41:50 +00:00
|
|
|
// no args -> interactive mode
|
|
|
|
if ctx.NumFlags() == 0 {
|
2020-12-15 17:38:22 +00:00
|
|
|
return interact.CreatePull(ctx.Login, ctx.Owner, ctx.Repo)
|
2020-12-08 21:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// else use args to create PR
|
2021-03-08 11:48:03 +00:00
|
|
|
opts, err := flags.GetIssuePREditFlags(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-08 21:41:50 +00:00
|
|
|
return task.CreatePull(
|
2020-12-15 17:38:22 +00:00
|
|
|
ctx.Login,
|
|
|
|
ctx.Owner,
|
|
|
|
ctx.Repo,
|
2020-12-08 21:41:50 +00:00
|
|
|
ctx.String("base"),
|
|
|
|
ctx.String("head"),
|
2021-03-08 11:48:03 +00:00
|
|
|
opts,
|
2020-12-08 21:41:50 +00:00
|
|
|
)
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|