-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add bypass allowlist for branch protection #36514
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
Draft
bircni
wants to merge
28
commits into
go-gitea:main
Choose a base branch
from
bircni:feature/bypass-branch-protection-allowlist
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.
Draft
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b108b00
Add bypass allowlist for branch protection
bircni 42e04fa
Merge branch 'main' into feature/bypass-branch-protection-allowlist
bircni d2c9157
change to v328 migration
bircni c429020
Merge remote-tracking branch 'upstream/main' into feature/bypass-bran…
bircni e16164e
Add a migration test test
bircni 24db2e2
rename migration to 330
bircni 994f5f5
Merge remote-tracking branch 'origin/main' into feature/bypass-branch…
bircni d3b4ae8
Merge branch 'main' into feature/bypass-branch-protection-allowlist
silverwind a75de17
fixes
bircni 7e9d0ce
Merge branch 'main' into feature/bypass-branch-protection-allowlist
bircni 6c444bb
rename migration
bircni ac2f907
Merge branch 'main' into feature/bypass-branch-protection-allowlist
bircni 96f4123
fix
bircni 8a006ac
Merge branch 'main' into feature/bypass-branch-protection-allowlist
bircni 342f7e8
Merge branch 'main' into feature/bypass-branch-protection-allowlist
GiteaBot 6c3c829
Merge branch 'main' into feature/bypass-branch-protection-allowlist
GiteaBot 3510261
Merge branch 'main' into feature/bypass-branch-protection-allowlist
GiteaBot c7fb30f
fix CanBypassBranchProtection
wxiaoguang 56accf4
refactor
wxiaoguang 13dc7b9
fix variable name
wxiaoguang 9642ce5
fine tune
wxiaoguang 0125c5a
fix layout (due to recent checkbox changes)
wxiaoguang b3591f9
fix logic
wxiaoguang 060a5e4
fix logic
wxiaoguang a1d3638
Merge branch 'main' into feature/bypass-branch-protection-allowlist
GiteaBot 02551a2
remove bypass-allowlist team cache
bircni 2a6516b
Merge branch 'main' into feature/bypass-branch-protection-allowlist
bircni 68b505d
fix merge box
bircni 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
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,20 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_26 | ||
|
|
||
| import "xorm.io/xorm" | ||
|
|
||
| func AddBranchProtectionBypassAllowlist(x *xorm.Engine) error { | ||
| type ProtectedBranch struct { | ||
| EnableBypassAllowlist bool `xorm:"NOT NULL DEFAULT false"` | ||
| BypassAllowlistUserIDs []int64 `xorm:"JSON TEXT"` | ||
| BypassAllowlistTeamIDs []int64 `xorm:"JSON TEXT"` | ||
| } | ||
|
|
||
| _, err := x.SyncWithOptions(xorm.SyncOptions{ | ||
| IgnoreConstrains: true, | ||
| IgnoreIndices: true, | ||
| }, new(ProtectedBranch)) | ||
| return err | ||
| } |
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,60 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_26 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "code.gitea.io/gitea/models/migrations/base" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func Test_AddBranchProtectionBypassAllowlist(t *testing.T) { | ||
| type ProtectedBranch struct { | ||
| ID int64 `xorm:"pk autoincr"` | ||
| RepoID int64 `xorm:"INDEX"` | ||
| BranchName string `xorm:"INDEX"` | ||
| EnableBypassAllowlist bool `xorm:"NOT NULL DEFAULT false"` | ||
| BypassAllowlistUserIDs []int64 `xorm:"JSON TEXT"` | ||
| BypassAllowlistTeamIDs []int64 `xorm:"JSON TEXT"` | ||
| } | ||
|
|
||
| x, deferable := base.PrepareTestEnv(t, 0, new(ProtectedBranch)) | ||
| defer deferable() | ||
|
|
||
| // Test with default values | ||
| _, err := x.Insert(&ProtectedBranch{RepoID: 1, BranchName: "main"}) | ||
| require.NoError(t, err) | ||
|
|
||
| // Test with populated allowlist | ||
| _, err = x.Insert(&ProtectedBranch{ | ||
| RepoID: 1, | ||
| BranchName: "develop", | ||
| EnableBypassAllowlist: true, | ||
| BypassAllowlistUserIDs: []int64{1, 2, 3}, | ||
| BypassAllowlistTeamIDs: []int64{10, 20}, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| require.NoError(t, AddBranchProtectionBypassAllowlist(x)) | ||
|
|
||
| // Verify the default values record | ||
| var pb ProtectedBranch | ||
| has, err := x.Where("repo_id = ? AND branch_name = ?", 1, "main").Get(&pb) | ||
| require.NoError(t, err) | ||
| require.True(t, has) | ||
| require.False(t, pb.EnableBypassAllowlist) | ||
| require.Nil(t, pb.BypassAllowlistUserIDs) | ||
| require.Nil(t, pb.BypassAllowlistTeamIDs) | ||
|
|
||
| // Verify the populated allowlist record | ||
| var pb2 ProtectedBranch | ||
| has, err = x.Where("repo_id = ? AND branch_name = ?", 1, "develop").Get(&pb2) | ||
| require.NoError(t, err) | ||
| require.True(t, has) | ||
| require.True(t, pb2.EnableBypassAllowlist) | ||
| require.Equal(t, []int64{1, 2, 3}, pb2.BypassAllowlistUserIDs) | ||
| require.Equal(t, []int64{10, 20}, pb2.BypassAllowlistTeamIDs) | ||
| } |
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
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
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.