generated from ddev/ddev-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommit-msg
executable file
·33 lines (27 loc) · 952 Bytes
/
commit-msg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
#ddev-generated
# Regex patterns
COMMIT_PATTERN="^T-[0-9]*"
BRANCH_PATTERN="[0-9]{6}_(T-[0-9]{8})"
# Read the commit message
commit_message=$(cat "$1")
# Ignore merge commits
if git rev-parse -q --verify MERGE_HEAD >/dev/null 2>&1; then
exit 0
fi
# Check if the commit message starts with the desired pattern
if [[ $commit_message =~ $COMMIT_PATTERN ]]; then
exit 0
fi
# Get the current branch name
branch_name=$(git rev-parse --abbrev-ref HEAD)
# Try to extract the pattern from the branch name
if [[ $branch_name =~ $BRANCH_PATTERN ]]; then
ticket_id="${BASH_REMATCH[1]}"
# Prepend the ticket ID to the commit message
echo "$ticket_id $commit_message" > "$1"
exit 0
else
echo "Error: Commit message must start with the pattern 'T-0000000' or the branch name must follow 'YYYYMM_T-XXXXXXXX__description' You can opt out of this rule by passing the '--no-verify' argument in the git commit command."
exit 1
fi