aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-23 18:25:12 -0500
committerUnknwon <u@gogs.io>2017-02-23 18:25:12 -0500
commit6072e9a52cf01723aea2b9a5ca7dfe22b101fbfc (patch)
tree17fe0e830584dfef2ff855bc75992df727997c08 /cmd
parentb78e03934d057bdb4c628fefb364dda6eb1f260a (diff)
repo: add protect branch whitelist (#4177)
Add options to add users and teams to whitelist of a protected branch. This is only available for organizational repositories.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hook.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/cmd/hook.go b/cmd/hook.go
index c65b76e2..32461745 100644
--- a/cmd/hook.go
+++ b/cmd/hook.go
@@ -100,6 +100,12 @@ func runHookPreReceive(c *cli.Context) error {
continue
}
+ // Check if whitelist is enabled
+ userID := com.StrTo(os.Getenv(http.ENV_AUTH_USER_ID)).MustInt64()
+ if protectBranch.EnableWhitelist && !models.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
+ fail(fmt.Sprintf("Branch '%s' is protected and you are not in the push whitelist", branchName), "")
+ }
+
// Check if branch allows direct push
if protectBranch.RequirePullRequest {
fail(fmt.Sprintf("Branch '%s' is protected and commits must be merged through pull request", branchName), "")