Skip to content

Commit 88ed0ea

Browse files
authored
Affrae add block_branch_names_not_starting_with_userID.sh (#144)
* Create block_branch_names_not_starting_with_userID.sh * change check comment * change comments * remove uneeded code * comma fix * comment fixes * commented out the happy message
1 parent b09645d commit 88ed0ea

File tree

1 file changed

+29
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)