-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathblock_branch_names_not_starting_with_userID.sh
More file actions
29 lines (26 loc) · 1.32 KB
/
block_branch_names_not_starting_with_userID.sh
File metadata and controls
29 lines (26 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
#
# Pre-receive hook that will block any new commits that their names do not being with the userID
#
# More details on pre-receive hooks and how to apply them can be found on
# https://help.github.com/enterprise/admin/guides/developer-workflow/managing-pre-receive-hooks-on-the-github-enterprise-appliance/
#
zero_commit="0000000000000000000000000000000000000000"
while read oldrev newrev refname; do
# Only check new branches ($oldrev is zero commit), don't block tags
if [[ $oldrev == $zero_commit && $refname =~ ^refs/heads/ ]]; then
# Check if the branch name begins with the userID - NOTE THIS IS CASE SENSITIVE AT THE MOMENT
if [[ ! $refname =~ ^refs/heads/$GITHUB_USER_LOGIN ]]; then
echo "Hi, $GITHUB_USER_LOGIN Blocking creation of new branch $refname"
echo "because it does not start with your username ($GITHUB_USER_LOGIN)"
echo "as outlined in the branch naming policy guide"
exit 1
fi
fi
done
# The following echoes may be enabled if you like. They are a purely a cosmetic
# demo item to show that it does not have to be just error messages passed back.
# echo "Hi $GITHUB_USER_LOGIN, allowing creation of new branch $refname"
# echo "because it does start with your username ($GITHUB_USER_LOGIN)"
# echo "as outlined in the branch naming policy guide - thank you!"
exit 0