Last active
March 19, 2022 16:16
-
-
Save Ligalaiz/831b188857754f5a443cd10b825a5145 to your computer and use it in GitHub Desktop.
Git hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
commitRegex='^(feat|fix|docs|refactor|test|build|ci|perf|style|test|init)' | |
if ! grep -qE "$commitRegex" "$1"; then | |
echo "Aborting according commit message policy. Please specify type commit issue 'feat' or another." | |
exit 1 | |
fi | |
commitRegex='(STARDB-[0-9])' | |
if ! grep -qE "$commitRegex" "$1"; then | |
echo "Aborting according commit message policy. Please specify JIRA issue STARDB-XXXX." | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# An example hook script to prepare the commit log message. | |
# Called by "git commit" with the name of the file that has the | |
# commit message, followed by the description of the commit | |
# message's source. The hook's purpose is to edit the commit | |
# message file. If the hook fails with a non-zero status, | |
# the commit is aborted. | |
# | |
# To enable this hook, rename this file to "prepare-commit-msg". | |
COMMIT_MSG_FILE=$1 | |
COMMIT_SOURCE=$2 | |
SHA1=$3 | |
# Only add custom message when there is no commit source | |
# ($COMMIT_SOURCE is empty). Otherwise, keep the default message | |
# proposed by Git. Possible commit source: message, template, | |
# merge, squash or commit. See https://git-scm.com/docs/githooks | |
if [[ -z "$COMMIT_SOURCE" ]] | |
then | |
ref=$(git rev-parse --abbrev-ref HEAD) | |
if [[ $ref =~ ^.*((STARDB)-[0-9]+).* ]] | |
then | |
hint=$(cat "$COMMIT_MSG_FILE") | |
ticket="${BASH_REMATCH[1]}" | |
echo ": ${ticket} " > "$COMMIT_MSG_FILE" | |
echo "$hint" >> "$COMMIT_MSG_FILE" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment