-
-
Notifications
You must be signed in to change notification settings - Fork 2
β¨ feat: auto update icon for commit #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,67 @@ | ||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # TiLoKit Prepare-commit-msg Hook | ||||||||||||||||||||||||||||||
| # Auto-inserts the correct emoji based on conventional commit type | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Colors | ||||||||||||||||||||||||||||||
| RED='\033[0;31m' | ||||||||||||||||||||||||||||||
| GREEN='\033[0;32m' | ||||||||||||||||||||||||||||||
| YELLOW='\033[1;33m' | ||||||||||||||||||||||||||||||
| BLUE='\033[0;34m' | ||||||||||||||||||||||||||||||
| NC='\033[0m' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| COMMIT_MSG_FILE="$1" | ||||||||||||||||||||||||||||||
| COMMIT_SOURCE="$2" # message, commit, merge, template, squash | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Do not modify merge, squash, or template generated messages | ||||||||||||||||||||||||||||||
| case "$COMMIT_SOURCE" in | ||||||||||||||||||||||||||||||
| merge|squash|template) | ||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Read first line only | ||||||||||||||||||||||||||||||
| FIRST_LINE=$(head -n1 "$COMMIT_MSG_FILE") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Trim leading/trailing whitespace | ||||||||||||||||||||||||||||||
| TRIMMED=$(echo "$FIRST_LINE" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # If already starts with an emoji then do nothing | ||||||||||||||||||||||||||||||
| if echo "$TRIMMED" | grep -qE '^[^[:space:]]+ [a-z]+: '; then | ||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # If doesn't match type: description, try to detect and prepend | ||||||||||||||||||||||||||||||
| if echo "$TRIMMED" | grep -qE '^[a-z]+: .+'; then | ||||||||||||||||||||||||||||||
| TYPE=$(echo "$TRIMMED" | sed -E 's/^([a-z]+): .*/\1/') | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Support scoped and breaking-change commits. -# If already starts with an emoji then do nothing
-if echo "$TRIMMED" | grep -qE '^[^[:space:]]+ [a-z]+: '; then
+# If already starts with an emoji then do nothing (allow optional scope and !)
+if echo "$TRIMMED" | grep -qE '^[^[:space:]]+ [a-z]+(\([^)]+\))?(!)?: '; then
exit 0
fi
-# If doesn't match type: description, try to detect and prepend
-if echo "$TRIMMED" | grep -qE '^[a-z]+: .+'; then
- TYPE=$(echo "$TRIMMED" | sed -E 's/^([a-z]+): .*/\1/')
+# If matches conventional commit without emoji, detect and prepend (allow scope and !)
+if echo "$TRIMMED" | grep -qE '^[a-z]+(\([^)]+\))?(!)?: .+'; then
+ TYPE=$(echo "$TRIMMED" | sed -E 's/^([a-z]+)(\([^)]+\))?(!)?: .*/\1/')π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||
| case "$TYPE" in | ||||||||||||||||||||||||||||||
| feat) EMOJI="β¨" ;; | ||||||||||||||||||||||||||||||
| fix) EMOJI="π" ;; | ||||||||||||||||||||||||||||||
| docs) EMOJI="π" ;; | ||||||||||||||||||||||||||||||
| refactor) EMOJI="β»οΈ" ;; | ||||||||||||||||||||||||||||||
| perf) EMOJI="β‘" ;; | ||||||||||||||||||||||||||||||
| test) EMOJI="π§ͺ" ;; | ||||||||||||||||||||||||||||||
| build) EMOJI="π οΈ" ;; | ||||||||||||||||||||||||||||||
| ci) EMOJI="π" ;; | ||||||||||||||||||||||||||||||
| chore) EMOJI="π§Ή" ;; | ||||||||||||||||||||||||||||||
| style) EMOJI="π¨" ;; | ||||||||||||||||||||||||||||||
| revert) EMOJI="βͺ" ;; | ||||||||||||||||||||||||||||||
| release) EMOJI="π" ;; | ||||||||||||||||||||||||||||||
| *) EMOJI="" ;; | ||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if [ -n "$EMOJI" ]; then | ||||||||||||||||||||||||||||||
| NEW_LINE="$EMOJI $TRIMMED" | ||||||||||||||||||||||||||||||
| # Replace first line, keep the rest | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| echo "$NEW_LINE" | ||||||||||||||||||||||||||||||
| tail -n +2 "$COMMIT_MSG_FILE" | ||||||||||||||||||||||||||||||
| } > "$COMMIT_MSG_FILE.tmp" | ||||||||||||||||||||||||||||||
| mv "$COMMIT_MSG_FILE.tmp" "$COMMIT_MSG_FILE" | ||||||||||||||||||||||||||||||
| echo -e "${GREEN}β Auto-inserted emoji:${NC} $NEW_LINE" | ||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Keep CI in sync with scope/! support. Apply in .husky/ci-check-commits.sh: - local emoji_pattern='^[^[:space:]]+ [a-z]+: .+'
- local no_emoji_pattern='^[a-z]+: .+'
+ local emoji_pattern='^[^[:space:]]+ [a-z]+(\([^)]+\))?(!)?: .+'
+ local no_emoji_pattern='^[a-z]+(\([^)]+\))?(!)?: .+'
@@
- local commit_type=$(echo "$commit_msg" | sed -E 's/^[^[:space:]]+ ([a-z]+): .*/\1/')
- local commit_emoji=$(echo "$commit_msg" | sed -E 's/^([^[:space:]]+) [a-z]+: .*/\1/')
+ local commit_type=$(echo "$commit_msg" | sed -E 's/^[^[:space:]]+ ([a-z]+)(\([^)]+\))?(!)?: .*/\1/')
+ local commit_emoji=$(echo "$commit_msg" | sed -E 's/^([^[:space:]]+) [a-z]+(\([^)]+\))?(!)?: .*/\1/')
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Ensure auto-install detects the new hook.
check-hooks.sh currently considers only commit-msg and pre-commit as βinstalledβ. Existing clones with those two hooks wonβt auto-install the new prepare-commit-msg. Update check_hooks_installed to include prepare-commit-msg.
Apply in .husky/check-hooks.sh:
check_hooks_installed() { local git_hooks_dir="$(git rev-parse --git-dir)/hooks" - if [[ -f "$git_hooks_dir/commit-msg" ]] && [[ -f "$git_hooks_dir/pre-commit" ]]; then + if [[ -f "$git_hooks_dir/commit-msg" ]] && [[ -f "$git_hooks_dir/pre-commit" ]] && [[ -f "$git_hooks_dir/prepare-commit-msg" ]]; then return 0 # Hooks are installed else return 1 # Hooks are missing fi }π Committable suggestion
π€ Prompt for AI Agents