0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-02-21 13:38:39 +01:00

Merge 55ae2102bef98b1f209155c2d729d5048086bc9b into bbea5e6c2d75a4a710d7838b7bec7e851e046d3c

This commit is contained in:
Adam Majer 2026-02-20 19:24:34 +00:00 committed by GitHub
commit e876755f2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 79 additions and 1 deletions

View File

@ -362,7 +362,17 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
return false
}
merger, _ := user_model.GetUserByEmail(ctx, commit.Author.Email)
var merger *user_model.User
if commit.ParentCount() > 1 {
merger, _ = user_model.GetUserByEmail(ctx, commit.Author.Email)
} else {
branch, err := git_model.GetBranch(ctx, pr.BaseRepoID, pr.BaseBranch)
if err == nil {
if err = branch.LoadPusher(ctx); err == nil {
merger = branch.Pusher
}
}
}
// When the commit author is unknown set the BaseRepo owner as merger
if merger == nil {

View File

@ -0,0 +1,68 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
"net/url"
"testing"
auth_model "code.gitea.io/gitea/models/auth"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
)
func TestManualMergeAutodetect(t *testing.T) {
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
// user2 is the repo owner
// user1 is the pusher/merger
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session2 := loginUser(t, user2.Name)
// Create a repo owned by user2
repoName := "manual-merge-autodetect"
var repo api.Repository
user2Ctx := NewAPITestContext(t, user2.Name, repoName, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
doAPICreateRepository(user2Ctx, false, func(t *testing.T, r api.Repository) {
repo = r
})(t)
// Enable autodetect manual merge
doAPIEditRepository(user2Ctx, &api.EditRepoOption{
HasPullRequests: util.ToPointer(true),
AllowManualMerge: util.ToPointer(true),
AutodetectManualMerge: util.ToPointer(true),
})(t)
// Create a PR from a branch
branchName := "feature"
testEditFileToNewBranch(t, session2, user2.Name, repo.Name, repo.DefaultBranch, branchName, "README.md", "Manual Merge Test")
apiPull, err := doAPICreatePullRequest(NewAPITestContext(t, user1.Name, repo.Name, auth_model.AccessTokenScopeWriteRepository), user2.Name, repo.Name, repo.DefaultBranch, branchName)(t)
assert.NoError(t, err)
// user1 clones and pushes the branch to master (fast-forward)
dstPath := t.TempDir()
u, _ := url.Parse(giteaURL.String())
u.Path = fmt.Sprintf("%s/%s.git", user2.Name, repo.Name)
u.User = url.UserPassword(user1.Name, userPassword)
doGitClone(dstPath, u)(t)
doGitMerge(dstPath, "origin/"+branchName)(t)
doGitPushTestRepository(dstPath, "origin", repo.DefaultBranch)(t)
// Check if the PR is merged and who is the merger
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: apiPull.ID})
assert.True(t, pr.HasMerged)
assert.Equal(t, issues_model.PullRequestStatusManuallyMerged, pr.Status)
// Merger should be user1 (the pusher), not the commit author (user2) or repo owner (user2)
assert.Equal(t, user1.ID, pr.MergerID)
})
}