[v12.0/forgejo] fix: prevent pull requests from being merged multiple times (#8862)

Backport of https://codeberg.org/forgejo/forgejo/pulls/8842

Contains a partial cherry-pick of 184e068f37, for the parts the PR depends on. The whole commit is way too involved to cherry-pick as a whole.

Co-authored-by: Danko Aleksejevs <danko@very.lv>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8862
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: BtbN <btbn@btbn.de>
Co-committed-by: BtbN <btbn@btbn.de>
This commit is contained in:
BtbN 2025-08-11 23:08:46 +02:00 committed by Earl Warren
commit 53c4c6bda8
6 changed files with 92 additions and 4 deletions

View file

@ -42,6 +42,7 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"xorm.io/xorm/convert"
)
func exitf(format string, args ...any) {
@ -342,6 +343,7 @@ type DeclarativeRepoOptions struct {
Name optional.Option[string]
EnabledUnits optional.Option[[]unit_model.Type]
DisabledUnits optional.Option[[]unit_model.Type]
UnitConfig optional.Option[map[unit_model.Type]convert.Conversion]
Files optional.Option[[]*files_service.ChangeRepoFile]
WikiBranch optional.Option[string]
AutoInit optional.Option[bool]
@ -390,9 +392,14 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
enabledUnits = make([]repo_model.RepoUnit, len(units))
for i, unitType := range units {
var config convert.Conversion
if cfg, ok := opts.UnitConfig.Value()[unitType]; ok {
config = cfg
}
enabledUnits[i] = repo_model.RepoUnit{
RepoID: repo.ID,
Type: unitType,
Config: config,
}
}
}
@ -470,6 +477,25 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
}
if enabledUnits != nil {
opts.EnabledUnits = optional.Some(enabledUnits)
for _, unitType := range enabledUnits {
if unitType == unit_model.TypePullRequests {
opts.UnitConfig = optional.Some(map[unit_model.Type]convert.Conversion{
unit_model.TypePullRequests: &repo_model.PullRequestsConfig{
AllowMerge: true,
AllowRebase: true,
AllowRebaseMerge: true,
AllowSquash: true,
AllowFastForwardOnly: true,
AllowManualMerge: true,
AllowRebaseUpdate: true,
DefaultMergeStyle: repo_model.MergeStyleMerge,
DefaultUpdateStyle: repo_model.UpdateStyleMerge,
},
})
break
}
}
}
if disabledUnits != nil {
opts.DisabledUnits = optional.Some(disabledUnits)