Skip to content

Conversation

@hoangsinh0601
Copy link
Collaborator

@hoangsinh0601 hoangsinh0601 commented Sep 12, 2025

🚀 Description

🔄 Type of Change

  • feat: A new feature
  • 🐛 fix: A bug fix
  • 📚 docs: Documentation only changes
  • 🎨 style: Changes that do not affect the meaning of the code
  • ♻️ refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • 🧪 test: Adding missing tests or correcting existing tests
  • 🔧 build: Changes that affect the build system or external dependencies
  • 🔄 ci: Changes to our CI configuration files and scripts
  • 🏠 chore: Other changes that don't modify src or test files

📝 Changes Made

🧪 Testing

  • Tests pass locally
  • New tests added for new functionality
  • Existing tests updated as needed
  • Manual testing completed

Test Results

📖 Documentation

  • README updated if needed
  • CHANGELOG.md updated
  • Code comments added/updated
  • API documentation updated

🔗 Related Issues

Fixes #
Closes #
Related to #

📸 Screenshots/Examples

✅ Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

🎯 Focus Areas for Review

🚨 Breaking Changes

📝 Additional Notes


Please ensure all checks pass before requesting review

Summary by CodeRabbit

  • New Features

    • Automatically prefixes commit messages with an emoji based on conventional commit types (e.g., feat ✨, fix 🐛, docs 📚, refactor ♻️, perf ⚡, test 🧪, build 🛠️, ci 🔄, chore 🧹, style 🎨, revert ⏪, release 🚀).
    • Skips merges, squashes, and messages already containing an emoji; leaves unmatched types unchanged.
  • Chores

    • Updated commit hook installer to include the new auto-emoji commit message hook.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 12, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Hook installer update
.husky/hooks/install-hooks.sh
Adds "prepare-commit-msg:Auto-inserts emoji based on commit type" to the HOOKS array; installer iterates over the new entry with existing logic (presence check, optional backup, copy, chmod, per-hook reporting).
New prepare-commit-msg hook
.husky/hooks/prepare-commit-msg
Introduces a Bash hook: skips merge/squash/template commits; detects existing emoji-prefixed messages; maps conventional types (feat, fix, docs, refactor, perf, test, build, ci, chore, style, revert, release) to emojis; prefixes first line and rewrites the message; outputs colored status.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description is just the repository template with placeholders left empty and unchecked; it lacks a concise summary of the change, the "Changes Made" entries, the Type of Change selection, testing results, documentation notes, and related issue links, so reviewers cannot assess scope or readiness. Populate the Description with a short summary of the change (e.g., adding a prepare-commit-msg hook that auto-inserts emojis and updating the installer), mark the correct Type of Change (✨ feat), list the modified files/changes, provide testing steps and results, update documentation if needed, link related issues, and complete the checklist before requesting review.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The current title references the introduced feature (automatic commit icon/emoji) so it is related to the changeset, but it includes an emoji and is phrased awkwardly ("auto update icon for commit"), which reduces clarity for reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I tap my paws on the commit log line,
Sprinkle a ✨ or 🐛 to make it shine.
From chores 🧹 to rockets 🚀 in flight,
I stamp each type with just the right light.
Hippity-hop—emoji in place,
Now every commit has a smiling face! 🐇

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/auto-update-icon-for-comit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

✅ Commit Validation Passed

All commits follow the conventional commit format! 🎉

Thank you for following our commit standards. This helps with:

  • 📝 Automated changelog generation
  • 🏷️ Automatic PR labeling
  • 🚀 Better release notes
  • 📊 Project history tracking

@github-actions github-actions bot added ✨ Enhancement New feature or request ❓ Needs Review Requires manual review and labeling labels Sep 12, 2025
@github-actions
Copy link

🚨 Emergency Labeling Applied

This PR was automatically labeled as "❓ Needs Review" because no other labels could be applied.

Please:

  1. Update the PR title to follow conventional commit format
  2. Or manually apply appropriate labels

This ensures proper organization and searchability of PRs.

1 similar comment
@github-actions
Copy link

🚨 Emergency Labeling Applied

This PR was automatically labeled as "❓ Needs Review" because no other labels could be applied.

Please:

  1. Update the PR title to follow conventional commit format
  2. Or manually apply appropriate labels

This ensures proper organization and searchability of PRs.

@hoangsinh0601 hoangsinh0601 merged commit 861477a into develop Sep 12, 2025
17 of 18 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d4f268 and 1fd6a2b.

📒 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.

Comment on lines 35 to 39
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"
)
Copy link
Contributor

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.

Suggested change
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.

Comment on lines +30 to +37
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/')

Copy link
Contributor

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.

Suggested change
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).

Comment on lines +35 to +65
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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ Enhancement New feature or request ❓ Needs Review Requires manual review and labeling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants