How can I ensure commit comments from a github PR squash merge contains required text?
We use Jira + Github and if a use enters Jira issue IDs in commit comments t
If you're using GitHub Enterprise, you can set up a pre-receive hook to reject commits that don't have a JIRA ticket number in them.
Check out the example here:
#!/bin/bash
#
# check commit messages for JIRA issue numbers formatted as [JIRA-]
REGEX="\[JIRA\-[0-9]*\]"
ERROR_MSG="[POLICY] The commit doesn't reference a JIRA issue"
while read OLDREV NEWREV REFNAME ; do
for COMMIT in `git rev-list $OLDREV..$NEWREV`;
do
MESSAGE=`git cat-file commit $COMMIT | sed '1,/^$/d'`
if ! echo $MESSAGE | grep -iqE "$REGEX"; then
echo "$ERROR_MSG: $MESSAGE" >&2
exit 1
fi
done
done
exit 0