2020-09-30 13:11:33 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 09:40:02 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 13:11:33 +08:00
|
|
|
|
|
|
|
package pulls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-16 01:38:22 +08:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-12-09 05:41:50 +08:00
|
|
|
"code.gitea.io/tea/modules/interact"
|
|
|
|
"code.gitea.io/tea/modules/task"
|
2020-09-30 13:11:33 +08:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdPullsCreate creates a pull request
|
|
|
|
var CmdPullsCreate = cli.Command{
|
|
|
|
Name: "create",
|
2020-12-17 00:47:40 +08:00
|
|
|
Aliases: []string{"c"},
|
2020-09-30 13:11:33 +08:00
|
|
|
Usage: "Create a pull-request",
|
2021-12-03 02:33:56 +08:00
|
|
|
Description: "Create a pull-request in the current repo",
|
2020-09-30 13:11:33 +08:00
|
|
|
Action: runPullsCreate,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "head",
|
2021-12-03 02:33:56 +08:00
|
|
|
Usage: "Branch name of the PR source (default is current one). To specify a different head repo, use <user>:<branch>",
|
2020-09-30 13:11:33 +08:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "base",
|
|
|
|
Aliases: []string{"b"},
|
2021-12-03 02:33:56 +08:00
|
|
|
Usage: "Branch name of the PR target (default is repos default branch)",
|
2020-09-30 13:11:33 +08:00
|
|
|
},
|
2022-09-27 23:36:36 +08:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "allow-maintainer-edits",
|
|
|
|
Aliases: []string{"edits"},
|
|
|
|
Usage: "Enable maintainers to push to the base branch of created pull",
|
|
|
|
Value: true,
|
|
|
|
},
|
2022-10-25 08:40:00 +08:00
|
|
|
}, flags.IssuePRCreateFlags...),
|
2020-09-30 13:11:33 +08:00
|
|
|
}
|
|
|
|
|
2020-12-16 01:38:22 +08:00
|
|
|
func runPullsCreate(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
2020-09-30 13:11:33 +08:00
|
|
|
|
2020-12-09 05:41:50 +08:00
|
|
|
// no args -> interactive mode
|
|
|
|
if ctx.NumFlags() == 0 {
|
2021-09-22 23:48:21 +08:00
|
|
|
return interact.CreatePull(ctx)
|
2020-12-09 05:41:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// else use args to create PR
|
2022-10-25 08:40:00 +08:00
|
|
|
opts, err := flags.GetIssuePRCreateFlags(ctx)
|
2021-03-08 19:48:03 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-09 05:41:50 +08:00
|
|
|
return task.CreatePull(
|
2021-09-22 23:48:21 +08:00
|
|
|
ctx,
|
2020-12-09 05:41:50 +08:00
|
|
|
ctx.String("base"),
|
|
|
|
ctx.String("head"),
|
2022-09-27 23:36:36 +08:00
|
|
|
ctx.Bool("allow-maintainer-edits"),
|
2021-03-08 19:48:03 +08:00
|
|
|
opts,
|
2020-12-09 05:41:50 +08:00
|
|
|
)
|
2020-09-30 13:11:33 +08:00
|
|
|
}
|