Add Allow Maintainer Edits (#509)
close #508 Reviewed-on: https://gitea.com/gitea/tea/pulls/509 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: strk <strk@noreply.gitea.io>
This commit is contained in:
parent
4487213581
commit
15457f1770
|
@ -7,3 +7,5 @@ dist/
|
|||
|
||||
.vscode/
|
||||
vendor/
|
||||
|
||||
coverage.out
|
||||
|
|
|
@ -30,6 +30,12 @@ var CmdPullsCreate = cli.Command{
|
|||
Aliases: []string{"b"},
|
||||
Usage: "Branch name of the PR target (default is repos default branch)",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "allow-maintainer-edits",
|
||||
Aliases: []string{"edits"},
|
||||
Usage: "Enable maintainers to push to the base branch of created pull",
|
||||
Value: true,
|
||||
},
|
||||
}, flags.IssuePREditFlags...),
|
||||
}
|
||||
|
||||
|
@ -51,6 +57,7 @@ func runPullsCreate(cmd *cli.Context) error {
|
|||
ctx,
|
||||
ctx.String("base"),
|
||||
ctx.String("head"),
|
||||
ctx.Bool("allow-maintainer-edits"),
|
||||
opts,
|
||||
)
|
||||
}
|
||||
|
|
6
go.mod
6
go.mod
|
@ -4,7 +4,7 @@ go 1.18
|
|||
|
||||
require (
|
||||
code.gitea.io/gitea-vet v0.2.1
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20220831004139-a0127ed0e7fe
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20220927025037-8f846bdb9bbe
|
||||
gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c
|
||||
github.com/AlecAivazis/survey/v2 v2.3.6
|
||||
github.com/adrg/xdg v0.4.0
|
||||
|
@ -17,7 +17,7 @@ require (
|
|||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/urfave/cli/v2 v2.16.3
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
|
||||
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
|
@ -59,7 +59,7 @@ require (
|
|||
github.com/yuin/goldmark v1.4.14 // indirect
|
||||
github.com/yuin/goldmark-emoji v1.0.1 // indirect
|
||||
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
|
||||
golang.org/x/sys v0.0.0-20220913153101-76c7481b5158 // indirect
|
||||
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 // indirect
|
||||
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.12 // indirect
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,7 +1,7 @@
|
|||
code.gitea.io/gitea-vet v0.2.1 h1:b30by7+3SkmiftK0RjuXqFvZg2q4p68uoPGuxhzBN0s=
|
||||
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20220831004139-a0127ed0e7fe h1:PeLyxnUZE85QuJtBZ4P8qCQcgWG5Ked67mlNgr0WkCQ=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20220831004139-a0127ed0e7fe/go.mod h1:aRmrQC3CAHdJAU1LQt0C9zqzqI8tUB/5oQtNE746aYE=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20220927025037-8f846bdb9bbe h1:3mI5Ea4NmdFIu4yhENz5YT3FsVGntP47ErcZlb3nPPE=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20220927025037-8f846bdb9bbe/go.mod h1:aRmrQC3CAHdJAU1LQt0C9zqzqI8tUB/5oQtNE746aYE=
|
||||
gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c h1:8fTkq2UaVkLHZCF+iB4wTxINmVAToe2geZGayk9LMbA=
|
||||
gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c/go.mod h1:Fc8iyPm4NINRWujeIk2bTfcbGc4ZYY29/oMAAGcr4qI=
|
||||
github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw=
|
||||
|
@ -182,8 +182,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
|||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be h1:fmw3UbQh+nxngCAHrDCCztao/kbYFnWjoqop8dHx05A=
|
||||
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
|
@ -221,8 +221,8 @@ golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220913153101-76c7481b5158 h1:XQphkCZeKYaMRSo28HqvvNYuLOoM5CIOOvTZfthvTgI=
|
||||
golang.org/x/sys v0.0.0-20220913153101-76c7481b5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 h1:nwzwVf0l2Y/lkov/+IYgMMbFyI+QypZDds9RxlSmsFQ=
|
||||
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
|
||||
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
|
||||
|
|
|
@ -14,7 +14,10 @@ import (
|
|||
|
||||
// CreatePull interactively creates a PR
|
||||
func CreatePull(ctx *context.TeaContext) (err error) {
|
||||
var base, head string
|
||||
var (
|
||||
base, head string
|
||||
allowMaintainerEdits bool
|
||||
)
|
||||
|
||||
// owner, repo
|
||||
if ctx.Owner, ctx.Repo, err = promptRepoSlug(ctx.Owner, ctx.Repo); err != nil {
|
||||
|
@ -49,6 +52,11 @@ func CreatePull(ctx *context.TeaContext) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
promptC := &survey.Confirm{Message: "Allow Maintainers to push to the base branch", Default: true}
|
||||
if err := survey.AskOne(promptC, &allowMaintainerEdits); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
head = task.GetHeadSpec(headOwner, headBranch, ctx.Owner)
|
||||
|
||||
opts := gitea.CreateIssueOption{Title: task.GetDefaultPRTitle(head)}
|
||||
|
@ -60,5 +68,6 @@ func CreatePull(ctx *context.TeaContext) (err error) {
|
|||
ctx,
|
||||
base,
|
||||
head,
|
||||
allowMaintainerEdits,
|
||||
&opts)
|
||||
}
|
||||
|
|
|
@ -64,6 +64,10 @@ func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview, ciStatus *g
|
|||
}
|
||||
}
|
||||
|
||||
if pr.AllowMaintainerEdit {
|
||||
out += "- Maintainers are allowed to edit\n"
|
||||
}
|
||||
|
||||
outputMarkdown(out, getRepoURL(pr.HTMLURL))
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
// CreatePull creates a PR in the given repo and prints the result
|
||||
func CreatePull(ctx *context.TeaContext, base, head string, opts *gitea.CreateIssueOption) (err error) {
|
||||
func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits bool, opts *gitea.CreateIssueOption) (err error) {
|
||||
// default is default branch
|
||||
if len(base) == 0 {
|
||||
base, err = GetDefaultPRBase(ctx.Login, ctx.Owner, ctx.Repo)
|
||||
|
@ -53,7 +53,9 @@ func CreatePull(ctx *context.TeaContext, base, head string, opts *gitea.CreateIs
|
|||
return fmt.Errorf("title is required")
|
||||
}
|
||||
|
||||
pr, _, err := ctx.Login.Client().CreatePullRequest(ctx.Owner, ctx.Repo, gitea.CreatePullRequestOption{
|
||||
client := ctx.Login.Client()
|
||||
|
||||
pr, _, err := client.CreatePullRequest(ctx.Owner, ctx.Repo, gitea.CreatePullRequestOption{
|
||||
Head: head,
|
||||
Base: base,
|
||||
Title: opts.Title,
|
||||
|
@ -68,6 +70,15 @@ func CreatePull(ctx *context.TeaContext, base, head string, opts *gitea.CreateIs
|
|||
return fmt.Errorf("could not create PR from %s to %s:%s: %s", head, ctx.Owner, base, err)
|
||||
}
|
||||
|
||||
if pr.AllowMaintainerEdit != allowMaintainerEdits {
|
||||
pr, _, err = client.EditPullRequest(ctx.Owner, ctx.Repo, pr.Index, gitea.EditPullRequestOption{
|
||||
AllowMaintainerEdit: gitea.OptionalBool(allowMaintainerEdits),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not enable maintainer edit on pull: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
print.PullDetails(pr, nil, nil)
|
||||
|
||||
fmt.Println(pr.HTMLURL)
|
||||
|
|
Loading…
Reference in New Issue