-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-msg
More file actions
25 lines (19 loc) · 730 Bytes
/
commit-msg
File metadata and controls
25 lines (19 loc) · 730 Bytes
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
#!/bin/bash
# Declare emojis
emojis=("🏗️" "🔧" "👷" "📚" "✨" "🐛" "🏎" "♻️" "⏪️" "🎨" "🧪" "🚧")
types=("build" "chore" "ci" "docs" "feat" "fix" "perf" "refactor" "revert" "style" "test" "wip")
# Get header and body from commit message
header="$(head -n 1 $1)";
body="$(tail -n +2 $1)";
# Loop through all types
for key in "${!types[@]}"; do
# Check, if emoji is already present
if [[ "$header" == *"${types[key]}"* ]] && [[ "$header" == *"${emojis[key]}"* ]]; then
exit 0;
fi
# Add emoji to commit message
if [[ "$header" == *"${types[key]}"* ]] && [[ "$header" != *"${emojis[key]}"* ]]; then
printf "$header ${emojis[key]}\n$body" > $1
exit 0;
fi
done