-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Pull Request Pusher should be the author of the merge #36581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
180aaba
Pusher is author of manual merged changes
AdamMajer 6317ddb
Add integration test
AdamMajer 9d3d2e3
remove commit author as merger
AdamMajer 4e15f7a
fix comment
AdamMajer 97da5ce
avoid ghost user
wxiaoguang 92710ff
modern go: new(val)
wxiaoguang 6563441
refactor "get merger"
wxiaoguang 91849fa
fix pusher check
wxiaoguang 0806a5c
avoid err shadow
wxiaoguang 2bca632
Merge branch 'main' into pushes-is-author
GiteaBot 7c7925a
Merge branch 'main' into pushes-is-author
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/url" | ||
| "testing" | ||
| "time" | ||
|
|
||
| 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" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| api "code.gitea.io/gitea/modules/structs" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| 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" | ||
| defaultBranch := setting.Repository.DefaultBranch | ||
| user2Ctx := NewAPITestContext(t, user2.Name, repoName, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) | ||
| doAPICreateRepository(user2Ctx, false)(t) | ||
|
|
||
| // Enable autodetect manual merge | ||
| doAPIEditRepository(user2Ctx, &api.EditRepoOption{ | ||
| HasPullRequests: new(true), | ||
| AllowManualMerge: new(true), | ||
| AutodetectManualMerge: new(true), | ||
| })(t) | ||
|
|
||
| // Create a PR from a branch | ||
| branchName := "feature" | ||
| testEditFileToNewBranch(t, session2, user2.Name, repoName, defaultBranch, branchName, "README.md", "Manual Merge Test") | ||
|
|
||
| apiPull, err := doAPICreatePullRequest(NewAPITestContext(t, user1.Name, repoName, auth_model.AccessTokenScopeWriteRepository), user2.Name, repoName, 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, repoName) | ||
| u.User = url.UserPassword(user1.Name, userPassword) | ||
|
|
||
| doGitClone(dstPath, u)(t) | ||
| doGitMerge(dstPath, "origin/"+branchName)(t) | ||
| doGitPushTestRepository(dstPath, "origin", defaultBranch)(t) | ||
|
|
||
| // Wait for the PR to be marked as merged by the background task | ||
| var pr *issues_model.PullRequest | ||
| require.Eventually(t, func() bool { | ||
| pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: apiPull.ID}) | ||
| return pr.HasMerged | ||
| }, 10*time.Second, 100*time.Millisecond) | ||
|
|
||
| // 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) | ||
| }) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.