Skip to content

Commit 36154d6

Browse files
author
Thomas Osowski
committed
initial hook restricting author merges
1 parent 3795262 commit 36154d6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
#
3+
# This hook restricts changes on the default branch to those made with the GUI Pull Request Merge button, or the Pull Request Merge API.
4+
#
5+
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
6+
while read -r oldrev newrev refname; do
7+
if [[ "${refname}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
8+
exit 0
9+
else
10+
if [[ "${GITHUB_VIA}" != 'pull request merge button' && \
11+
"${GITHUB_VIA}" != 'pull request merge api' ]]; then
12+
echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
13+
exit 1
14+
else
15+
AUTHOR_COUNT=$(git log ${DEFAULT_BRANCH}..${newrev} --author="${GITHUB_USER_LOGIN}" --format='%an %cn' | wc -l)
16+
echo "Found ${AUTHOR_COUNT} commits"
17+
echo "$oldrev"
18+
echo "$GITHUB_USER_LOGIN"
19+
if (( ${AUTHOR_COUNT} == 0 )); then
20+
# No commits containing the current author
21+
exit 0
22+
else
23+
echo "Merging restricted on this branch. Author of commits cannot merge."
24+
echo "Found the following commits by author ${GITHUB_USER_LOGIN}"
25+
echo -e $(git log ${DEFAULT_BRANCH}..${newrev} --author="${GITHUB_USER_LOGIN}")
26+
# --format='%an %h'
27+
exit 1
28+
fi
29+
fi
30+
fi
31+
done

0 commit comments

Comments
 (0)