1
0
mirror of https://gitea.com/Sirherobrine23/tea.git synced 2024-07-07 10:26:21 -03:00
tea/cmd/pulls/create.go
Norwin adb2382aa5 Add interactive mode for tea pr create (#279)
refactor pull create into task & interact module

avoid creation of invalid PRs

refactor task.CreatePull

to make functionality reusable in interact module

implement interactive.CreatePull

Co-authored-by: Norwin Roosen <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/279
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Co-Authored-By: Norwin <noerw@noreply.gitea.io>
Co-Committed-By: Norwin <noerw@noreply.gitea.io>
2020-12-09 05:41:50 +08:00

64 lines
1.5 KiB
Go

// 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"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"github.com/urfave/cli/v2"
)
// CmdPullsCreate creates a pull request
var CmdPullsCreate = cli.Command{
Name: "create",
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)",
},
&cli.StringFlag{
Name: "title",
Aliases: []string{"t"},
Usage: "Set title of pull (default is head branch name)",
},
&cli.StringFlag{
Name: "description",
Aliases: []string{"d"},
Usage: "Set body of new pull",
},
}, flags.AllDefaultFlags...),
}
func runPullsCreate(ctx *cli.Context) error {
login, ownerArg, repoArg := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
// no args -> interactive mode
if ctx.NumFlags() == 0 {
return interact.CreatePull(login, ownerArg, repoArg)
}
// else use args to create PR
return task.CreatePull(
login,
ownerArg,
repoArg,
ctx.String("base"),
ctx.String("head"),
ctx.String("title"),
ctx.String("description"),
)
}