-
-
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
Conversation
WalkthroughAdds a new Husky prepare-commit-msg hook that auto-prefixes conventional commit types with emojis. Updates the hook installer to include this hook. The new script parses the first line, skips merge/squash/template commits, maps known types to emojis, and rewrites the message when applicable. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant Git as Git
participant Hook as prepare-commit-msg (Husky)
participant FS as Commit Message File
Dev->>Git: git commit
Git->>Hook: Invoke with path to commit message
Hook->>FS: Read first line
alt Merge/Squash/Template commit
Hook-->>Git: Exit (no change)
else Conventional type without emoji
rect rgba(200,240,255,0.4)
Note over Hook: Map type -> emoji
Hook->>FS: Rewrite first line with emoji prefix<br/>(preserve remainder)
end
Hook-->>Git: Success (message updated)
else No known type or already has emoji
Hook-->>Git: Exit (no change)
end
Git-->>Dev: Commit proceeds
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Commit Validation PassedAll commits follow the conventional commit format! 🎉 Thank you for following our commit standards. This helps with:
|
|
🚨 Emergency Labeling Applied This PR was automatically labeled as "❓ Needs Review" because no other labels could be applied. Please:
This ensures proper organization and searchability of PRs. |
1 similar comment
|
🚨 Emergency Labeling Applied This PR was automatically labeled as "❓ Needs Review" because no other labels could be applied. Please:
This ensures proper organization and searchability of PRs. |
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.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
.husky/hooks/install-hooks.sh (2)
99-114: Align guidance with CI: emoji is required; scope and breaking “!” should be allowed.
Docs show “type(scope): …” but CI requires an emoji and currently rejects scoped types. Update guidance to “emoji type(scope)!: …”.- echo -e "${YELLOW}💡 Valid commit message format:${NC}" - echo -e " ${GREEN}type(scope): description${NC}" + echo -e "${YELLOW}💡 Valid commit message format (emoji required):${NC}" + echo -e " ${GREEN}emoji type(scope)!: description${NC}"
115-119: Fix examples to include required emojis.- echo -e " ${GREEN}✅ feat: add user authentication${NC}" - echo -e " ${GREEN}✅ fix(core): resolve memory leak${NC}" - echo -e " ${GREEN}✅ docs: update API documentation${NC}" - echo -e " ${GREEN}✅ chore(deps): upgrade dependencies${NC}" + echo -e " ${GREEN}✅ ✨ feat: add user authentication${NC}" + echo -e " ${GREEN}✅ 🐛 fix(core): resolve memory leak${NC}" + echo -e " ${GREEN}✅ 📚 docs: update API documentation${NC}" + echo -e " ${GREEN}✅ 🧹 chore(deps): upgrade dependencies${NC}"
🧹 Nitpick comments (6)
.husky/hooks/install-hooks.sh (3)
56-57: Avoid double timestamp calls in backup path.
Use one timestamp for both cp and echo.- cp "$target_file" "${target_file}.backup.$(date +%Y%m%d_%H%M%S)" - echo -e "${YELLOW}📦 Backed up to: ${target_file}.backup.$(date +%Y%m%d_%H%M%S)${NC}" + ts="$(date +%Y%m%d_%H%M%S)" + cp "$target_file" "${target_file}.backup.$ts" + echo -e "${YELLOW}📦 Backed up to: ${target_file}.backup.$ts${NC}"
95-98: Update the “What happens now” bullets to include the new hook.echo -e "${CYAN}📋 What happens now:${NC}" echo -e "${BLUE}• commit-msg hook:${NC} Validates every commit message format" echo -e "${BLUE}• pre-commit hook:${NC} Runs checks before each commit" - echo -e "${BLUE}• .husky directory:${NC} Stores all git hooks (like JavaScript projects)" + echo -e "${BLUE}• prepare-commit-msg hook:${NC} Auto-inserts emoji for conventional commits" + echo -e "${BLUE}• .husky directory:${NC} Stores all git hooks (like JavaScript projects)"
121-124: Add uninstall step for prepare-commit-msg.echo -e " ${BLUE}rm ${GIT_HOOKS_DIR}/commit-msg${NC}" echo -e " ${BLUE}rm ${GIT_HOOKS_DIR}/pre-commit${NC}" + echo -e " ${BLUE}rm ${GIT_HOOKS_DIR}/prepare-commit-msg${NC}".husky/hooks/prepare-commit-msg (3)
38-53: Avoid drift: centralize the emoji map.
The mapping is duplicated in ci-check-commits.sh and scripts/test-emoji-validation.sh. Consider a shared .husky/lib/emoji.sh with get_emoji_for_type and source it here and in CI.
1-12: Hardening and portability nits.
- Add set -Eeuo pipefail and IFS=$'\n\t' near the top.
- Prefer printf over echo -e for colored output.
Example:#!/bin/bash + +set -Eeuo pipefail +IFS=$'\n\t'
35-65: Optional: auto-correct wrong emoji and handle git revert.
- If a commit already has an emoji but it doesn’t match the type, you could auto-correct it to reduce CI churn.
- Detect “^Revert\b” messages and rewrite to “⏪ revert: …” (or skip if you want to avoid surprises).
Would you like me to propose a minimal patch for these behaviors?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.husky/hooks/install-hooks.sh(1 hunks).husky/hooks/prepare-commit-msg(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
.husky/hooks/install-hooks.sh (3)
.husky/ci-check-commits.sh (3)
main(106-178)validate_commit(39-103)get_emoji_for_type(20-36).husky/check-hooks.sh (3)
main(44-67)auto_install_hooks(26-41)check_hooks_installed(15-23).github/scripts/release.sh (1)
commit_release_changes(112-131)
.husky/hooks/prepare-commit-msg (4)
.husky/ci-check-commits.sh (3)
main(106-178)validate_commit(39-103)get_emoji_for_type(20-36).github/scripts/release.sh (1)
commit_release_changes(112-131)scripts/hotfix.sh (1)
commit_hotfix_changes(180-194)scripts/test-emoji-validation.sh (1)
get_emoji_for_type(19-35)
🔇 Additional comments (2)
.husky/hooks/install-hooks.sh (1)
38-39: Hook added to installer — LGTM.
Including prepare-commit-msg in the HOOKS array looks good..husky/hooks/prepare-commit-msg (1)
57-61: BSD/macOS portability: replace ‘tail -n +2’.
tail -n +2 isn’t portable on BSD/macOS. Use sed to drop the first line.- tail -n +2 "$COMMIT_MSG_FILE" + sed -n '2,$p' "$COMMIT_MSG_FILE"Likely an incorrect or invalid review comment.
| HOOKS=( | ||
| "commit-msg:Validates commit message format (conventional commits)" | ||
| "pre-commit:Runs pre-commit checks (syntax, large files, etc.)" | ||
| "prepare-commit-msg:Auto-inserts emoji based on commit type" | ||
| ) |
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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| HOOKS=( | |
| "commit-msg:Validates commit message format (conventional commits)" | |
| "pre-commit:Runs pre-commit checks (syntax, large files, etc.)" | |
| "prepare-commit-msg:Auto-inserts emoji based on commit type" | |
| ) | |
| 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" ]] && [[ -f "$git_hooks_dir/prepare-commit-msg" ]]; then | |
| return 0 # Hooks are installed | |
| else | |
| return 1 # Hooks are missing | |
| fi | |
| } |
🤖 Prompt for AI Agents
In .husky/hooks/install-hooks.sh around lines 35 to 39, the HOOKS array includes
"prepare-commit-msg" but check-hooks.sh only checks for commit-msg and
pre-commit; update .husky/check-hooks.sh to treat prepare-commit-msg as an
installed hook by adding "prepare-commit-msg" to the list/array of recognized
installed hooks (or include it in the conditional checks) so existing clones
that have the other two hooks will detect the new prepare-commit-msg and
auto-install it.
| 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/') | ||
|
|
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
Support scoped and breaking-change commits.
Current regexes miss “type(scope): …” and “type(scope)!: …”, so the hook won’t add emojis for common Conventional Commits (e.g., chore(release): …). This will cause CI failures given your mandatory-emoji policy.
-# 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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 echo "$TRIMMED" | grep -qE '^[^[:space:]]+ [a-z]+(\([^)]+\))?(!)?: '; then | |
| exit 0 | |
| fi | |
| # 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/') |
🤖 Prompt for AI Agents
.husky/hooks/prepare-commit-msg around lines 30-37: the current grep and sed
only match plain "type: description" and miss Conventional Commits with scopes
and breaking-change bangs like "type(scope): ..." or "type(scope)!: ...". Update
the first and second grep -qE regexes to allow an optional scope group and
optional "!" before the colon (e.g. use a pattern that accepts
^[a-z]+(\([^)]+\))?(!)?: ), and update the sed used to extract TYPE to strip
optional scope and "!" (e.g. change the sed substitution to capture only the
leading type name while tolerating the optional "(...)" and "!" before the
colon).
| if echo "$TRIMMED" | grep -qE '^[a-z]+: .+'; then | ||
| TYPE=$(echo "$TRIMMED" | sed -E 's/^([a-z]+): .*/\1/') | ||
|
|
||
| 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 |
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
Keep CI in sync with scope/! support.
After updating this hook, adjust ci-check-commits.sh to accept scope and optional “!” and to extract type accordingly, or CI will still fail scoped commits.
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/')Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In .husky/hooks/prepare-commit-msg around lines 35 to 65, the hook now supports
scoped commit messages and optional "!" but CI still fails because
.husky/ci-check-commits.sh wasn't updated; modify ci-check-commits.sh to parse
commit type by allowing an optional scope and optional breaking-change "!" (e.g.
type(scope)!: message or type!: message), adjust the regex to capture the
leading type token before an optional "(" or "!" and ignore scope/! when
validating and mapping to emojis, and ensure tests/CI validation use the
extracted type rather than assuming no scope or "!" present.
🚀 Description
🔄 Type of Change
📝 Changes Made
🧪 Testing
Test Results
📖 Documentation
🔗 Related Issues
Fixes #
Closes #
Related to #
📸 Screenshots/Examples
✅ Checklist
🎯 Focus Areas for Review
🚨 Breaking Changes
📝 Additional Notes
Please ensure all checks pass before requesting review
Summary by CodeRabbit
New Features
Chores