-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Fix bug to check whether user can update pull request branch or rebase branch #36465
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
Open
lunny
wants to merge
16
commits into
go-gitea:main
Choose a base branch
from
lunny:lunny/fix_perm_check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+225
−88
Open
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fab22b2
Fix bug to check whether user can merge
lunny 7b0eb88
Fix bug
lunny afe66cb
Fix bug
lunny c01d395
Revert unnecessary change
lunny f77f7d6
fix year
lunny 632a92b
Merge branch 'main' into lunny/fix_perm_check
lunny 0587531
Merge branch 'main' into lunny/fix_perm_check
lunny 42db6e8
Merge branch 'main' into lunny/fix_perm_check
lunny deeaece
Fix bug and add more tests
lunny 178f5e6
Merge branch 'main' into lunny/fix_perm_check
lunny 8bfb464
Merge branch 'lunny/fix_perm_check' of github.com:lunny/gitea into lu…
lunny f8a789f
more checks
lunny 643dea0
Add more comments
lunny 6934b14
Fix test
lunny 6ded397
Merge branch 'main' into lunny/fix_perm_check
lunny 6418855
Merge branch 'main' into lunny/fix_perm_check
lunny 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
Some comments aren't visible on the classic Files Changed page.
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,39 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package pull | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "code.gitea.io/gitea/models/db" | ||
| git_model "code.gitea.io/gitea/models/git" | ||
| issues_model "code.gitea.io/gitea/models/issues" | ||
| "code.gitea.io/gitea/models/unittest" | ||
| user_model "code.gitea.io/gitea/models/user" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestIsUserAllowedToUpdateRespectsProtectedBranch(t *testing.T) { | ||
| assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
|
||
| pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}) | ||
| assert.NoError(t, pr.LoadHeadRepo(t.Context())) | ||
|
|
||
| user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) | ||
|
|
||
| protectedBranch := &git_model.ProtectedBranch{ | ||
| RepoID: pr.HeadRepoID, | ||
| RuleName: pr.HeadBranch, | ||
| CanPush: false, | ||
| CanForcePush: false, | ||
| } | ||
| _, err := db.GetEngine(t.Context()).Insert(protectedBranch) | ||
| assert.NoError(t, err) | ||
|
|
||
| pushAllowed, rebaseAllowed, err := IsUserAllowedToUpdate(t.Context(), pr, user) | ||
| assert.NoError(t, err) | ||
| assert.False(t, pushAllowed) | ||
| assert.False(t, rebaseAllowed) | ||
| } |
Oops, something went wrong.
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.