From 07ca1ba1066ba707ebc47d05e3f4615a07e90351 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 15 Aug 2025 02:38:45 +0000 Subject: [PATCH] Fix bug (#793) Partially fix #791 Reviewed-on: https://gitea.com/gitea/tea/pulls/793 Reviewed-by: hiifong --- cmd/pulls/create.go | 8 +++++++- modules/interact/pull_create.go | 2 +- modules/task/pull_create.go | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/pulls/create.go b/cmd/pulls/create.go index 19c113b..14a1e67 100644 --- a/cmd/pulls/create.go +++ b/cmd/pulls/create.go @@ -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, ) } diff --git a/modules/interact/pull_create.go b/modules/interact/pull_create.go index 4ccc75a..6ef56fb 100644 --- a/modules/interact/pull_create.go +++ b/modules/interact/pull_create.go @@ -72,6 +72,6 @@ func CreatePull(ctx *context.TeaContext) (err error) { ctx, base, head, - allowMaintainerEdits, + &allowMaintainerEdits, &opts) } diff --git a/modules/task/pull_create.go b/modules/task/pull_create.go index ac39b2d..b07a28a 100644 --- a/modules/task/pull_create.go +++ b/modules/task/pull_create.go @@ -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)