Add Allow Maintainer Edits #509
|
@ -30,6 +30,11 @@ 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",
|
||||
},
|
||||
}, flags.IssuePREditFlags...),
|
||||
}
|
||||
|
||||
|
@ -51,6 +56,7 @@ func runPullsCreate(cmd *cli.Context) error {
|
|||
ctx,
|
||||
ctx.String("base"),
|
||||
ctx.String("head"),
|
||||
ctx.Bool("allow-maintainer-edits"),
|
||||
opts,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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 pull base-branch", Default: false}
|
||||
6543 marked this conversation as resolved
Outdated
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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 allowMaintainerEdits {
|
||||
pr, _, err = client.EditPullRequest(ctx.Owner, ctx.Repo, pr.ID, gitea.EditPullRequestOption{
|
||||
6543 marked this conversation as resolved
Outdated
6543
commented
pr.Index pr.Index
|
||||
AllowMaintainerEdit: gitea.OptionalBool(true),
|
||||
})
|
||||
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
Block a user
Also maybe default to true?