Partially fix #791

Reviewed-on: https://gitea.com/gitea/tea/pulls/793
Reviewed-by: hiifong <i@hiif.ong>
This commit is contained in:
Lunny Xiao
2025-08-15 02:38:45 +00:00
parent d643e94a69
commit 07ca1ba106
3 changed files with 11 additions and 5 deletions

View File

@ -6,6 +6,7 @@ package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
@ -56,11 +57,16 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
return err
}
var allowMaintainerEdits *bool
if ctx.IsSet("allow-maintainer-edits") {
allowMaintainerEdits = gitea.OptionalBool(ctx.Bool("allow-maintainer-edits"))
}
return task.CreatePull(
ctx,
ctx.String("base"),
ctx.String("head"),
ctx.Bool("allow-maintainer-edits"),
allowMaintainerEdits,
opts,
)
}

View File

@ -72,6 +72,6 @@ func CreatePull(ctx *context.TeaContext) (err error) {
ctx,
base,
head,
allowMaintainerEdits,
&allowMaintainerEdits,
&opts)
}

View File

@ -23,7 +23,7 @@ var (
)
// CreatePull creates a PR in the given repo and prints the result
func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits bool, 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)
@ -75,9 +75,9 @@ func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits
return fmt.Errorf("could not create PR from %s to %s:%s: %s", head, ctx.Owner, base, err)
}
if pr.AllowMaintainerEdit != allowMaintainerEdits {
if allowMaintainerEdits != nil && pr.AllowMaintainerEdit != *allowMaintainerEdits {
pr, _, err = client.EditPullRequest(ctx.Owner, ctx.Repo, pr.Index, gitea.EditPullRequestOption{
AllowMaintainerEdit: gitea.OptionalBool(allowMaintainerEdits),
AllowMaintainerEdit: allowMaintainerEdits,
})
if err != nil {
return fmt.Errorf("could not enable maintainer edit on pull: %v", err)