1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00
anytype-heart/.githooks/commit-msg
Roman Khafizianov c06310ecf5
GO-5600 fix hook
2025-05-09 14:20:32 +02:00

28 lines
No EOL
830 B
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
#
# Extract ISSUE_ID from branch (e.g. JS-1234, GO-4222, FOO-99999) and
# prepend it to your commit message if not already present.
REGEX_ISSUE_ID='[A-Za-z]+-[0-9]+' # letters-dash-numbers
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
COMMIT_MSG_FILE=$1
COMMIT_TEXT=$(< "$COMMIT_MSG_FILE")
# Find and uppercase the first matching issue key
ISSUE_ID=$(echo "$BRANCH_NAME" \
| grep -oE "$REGEX_ISSUE_ID" \
| head -1 \
| tr '[:lower:]' '[:upper:]')
# If no issue key, reject the commit
if [[ -z "$ISSUE_ID" ]]; then
echo "ERROR: Branch name must contain an issue key (e.g. GO-1234)." >&2
exit 1
fi
# If the commit message doesnt already start with ISSUE_ID, prepend it
if [[ ! "$COMMIT_TEXT" =~ ^$ISSUE_ID ]]; then
printf "%s %s\n" "$ISSUE_ID" "$COMMIT_TEXT" > "$COMMIT_MSG_FILE"
fi
exit 0