File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments