Add tea pr merge #348

Merged
zeripath merged 3 commits from noerw/tea:add-merge into master 2021-03-17 19:56:05 +00:00
2 changed files with 58 additions and 0 deletions
Showing only changes of commit 1e7daeaf49 - Show all commits

View File

@ -43,6 +43,7 @@ var CmdPulls = cli.Command{
&pulls.CmdPullsReview,
&pulls.CmdPullsApprove,
&pulls.CmdPullsReject,
&pulls.CmdPullsMerge,
},
}

57
cmd/pulls/merge.go Normal file
View File

@ -0,0 +1,57 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
6543 marked this conversation as resolved Outdated
Outdated
Review

2021?

2021?
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package pulls
import (
"fmt"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
)
// CmdPullsMerge merges a PR
var CmdPullsMerge = cli.Command{
Name: "merge",
Aliases: []string{"m"},
Usage: "Merge a pull request",
Description: "Merge a pull request",
ArgsUsage: "<pull index>",
Flags: append([]cli.Flag{
&cli.StringFlag{
Name: "style",
Aliases: []string{"s"},
Usage: "Kind of merge to perform: merge, rebase, squash, rebase-merge",
6543 marked this conversation as resolved
Review

for squash merge, we need flags for "Title" and "Message" options

for squash merge, we need flags for "Title" and "Message" options
Review

Default: "merge",

Default: "merge",
},
}, flags.AllDefaultFlags...),
Action: func(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() != 1 {
return fmt.Errorf("Must specify a PR index")
}
idx, err := utils.ArgToIndex(ctx.Args().First())
if err != nil {
return err
}
success, _, err := ctx.Login.Client().MergePullRequest(ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
Style: gitea.MergeStyle(ctx.String("style")),
})
if err != nil {
return err
}
if !success {
return fmt.Errorf("Failed to merge PR. Is it still open?")
}
return nil
},
}