From 8465bed99464c5ef4abc8e0a6944911d1c5ef358 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Sat, 31 Oct 2026 19:00:47 +0500 Subject: [PATCH] fix(pull): respect max approvers in default merge message (#40118) The approver limit was checked before writing each `Reviewed-by:` line but compared with `>`, so the default merge message got one more trailer than `DEFAULT_MERGE_MESSAGE_MAX_APPROVERS` allows (2 with a limit of 1, 11 with the default 10). It now stops once the limit is reached. Fixes https://github.com/go-gitea/gitea/issues/40116 Assisted-by: Claude Code:claude-opus-5-5 --- models/issues/pull.go | 2 +- models/issues/pull_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/models/issues/pull.go b/models/issues/pull.go index 4557488167c..91c52250330 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -378,7 +378,7 @@ func (pr *PullRequest) getReviewedByLines(ctx context.Context, writer io.Writer) reviewersWritten := 0 for _, review := range reviews { - if maxReviewers > 0 && reviewersWritten > maxReviewers { + if maxReviewers > 0 && reviewersWritten >= maxReviewers { break } diff --git a/models/issues/pull_test.go b/models/issues/pull_test.go index 0364acebef1..0aebda3290b 100644 --- a/models/issues/pull_test.go +++ b/models/issues/pull_test.go @@ -15,6 +15,7 @@ import ( user_model "gitea.dev/models/user" "gitea.dev/modules/optional" "gitea.dev/modules/setting" + "gitea.dev/modules/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -404,6 +405,10 @@ func testGetApprovers(t *testing.T) { approvers := pr.GetApprovers(t.Context()) expected := "Reviewed-by: User Five \nReviewed-by: Org Six \n" assert.Equal(t, expected, approvers) + + defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageMaxApprovers, 1)() + approvers = pr.GetApprovers(t.Context()) + assert.Equal(t, "Reviewed-by: User Five \n", approvers) } func testGetPullRequestByMergedCommit(t *testing.T) {