From 6072e9a52cf01723aea2b9a5ca7dfe22b101fbfc Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 23 Feb 2017 18:25:12 -0500 Subject: 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. --- cmd/hook.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmd') 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), "") -- cgit v1.2.3