Browse Source

Protected branches: allow whitelist bypass require pull request check (#4207)

pull/4264/head
Unknwon 8 years ago
parent
commit
83f6b8e847
No known key found for this signature in database
GPG Key ID: 7A02C406FAC875A2
  1. 15
      cmd/hook.go
  2. 2
      conf/locale/locale_en-US.ini
  3. 2
      gogs.go
  4. 2027
      modules/bindata/bindata.go
  5. 2
      templates/.VERSION
  6. 2
      templates/repo/settings/protected_branch.tmpl

15
cmd/hook.go

@ -100,14 +100,21 @@ func runHookPreReceive(c *cli.Context) error {
continue continue
} }
// Check if whitelist is enabled // Whitelist users can bypass require pull request check
bypassRequirePullReuqest := false
// Check if user is in whitelist when enabled
userID := com.StrTo(os.Getenv(http.ENV_AUTH_USER_ID)).MustInt64() userID := com.StrTo(os.Getenv(http.ENV_AUTH_USER_ID)).MustInt64()
if protectBranch.EnableWhitelist && !models.IsUserInProtectBranchWhitelist(repoID, userID, branchName) { if protectBranch.EnableWhitelist {
fail(fmt.Sprintf("Branch '%s' is protected and you are not in the push whitelist", branchName), "") if !models.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
fail(fmt.Sprintf("Branch '%s' is protected and you are not in the push whitelist", branchName), "")
}
bypassRequirePullReuqest = true
} }
// Check if branch allows direct push // Check if branch allows direct push
if protectBranch.RequirePullRequest { if !bypassRequirePullReuqest && protectBranch.RequirePullRequest {
fail(fmt.Sprintf("Branch '%s' is protected and commits must be merged through pull request", branchName), "") fail(fmt.Sprintf("Branch '%s' is protected and commits must be merged through pull request", branchName), "")
} }

2
conf/locale/locale_en-US.ini

@ -656,7 +656,7 @@ settings.protect_this_branch_desc = Disable force pushes and prevent from deleti
settings.protect_require_pull_request = Require pull request instead direct pushing settings.protect_require_pull_request = Require pull request instead direct pushing
settings.protect_require_pull_request_desc = Enable this option to disable direct pushing to this branch. Commits have to be pushed to another non-protected branch and merged to this branch through pull request. settings.protect_require_pull_request_desc = Enable this option to disable direct pushing to this branch. Commits have to be pushed to another non-protected branch and merged to this branch through pull request.
settings.protect_whitelist_committers = Whitelist who can push to this branch settings.protect_whitelist_committers = Whitelist who can push to this branch
settings.protect_whitelist_committers_desc = Add people or teams to whitelist of direct push to this branch. settings.protect_whitelist_committers_desc = Add people or teams to whitelist of direct push to this branch. Users in whitelist will bypass require pull request check.
settings.protect_whitelist_users = Users who can push to this branch settings.protect_whitelist_users = Users who can push to this branch
settings.protect_whitelist_search_users = Search users settings.protect_whitelist_search_users = Search users
settings.protect_whitelist_teams = Teams for which members of them can push to this branch settings.protect_whitelist_teams = Teams for which members of them can push to this branch

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.10.8.0307" const APP_VER = "0.10.8.0308"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

2027
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

2
templates/.VERSION

@ -1 +1 @@
0.10.8.0307 0.10.8.0308

2
templates/repo/settings/protected_branch.tmpl

@ -46,7 +46,7 @@
{{range .Users}} {{range .Users}}
<div class="item" data-value="{{.ID}}"> <div class="item" data-value="{{.ID}}">
<img class="ui mini image" src="{{.RelAvatarLink}}"> <img class="ui mini image" src="{{.RelAvatarLink}}">
{{.DisplayName}} {{.Name}}
</div> </div>
{{end}} {{end}}
</div> </div>

Loading…
Cancel
Save