-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add configurable emoji support for commit messages #74
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
base: main
Are you sure you want to change the base?
feat: add configurable emoji support for commit messages #74
Conversation
📝 WalkthroughWalkthroughThis PR implements configurable emoji support for commit messages. It adds an Changes
Sequence DiagramsequenceDiagram
participant User
participant CLI
participant Config
participant CommitGen
participant Sanitizer
rect rgba(100, 150, 200, 0.5)
Note over User,Config: User Toggles Emoji Support
User->>CLI: Run `git gpt emoji`
CLI->>Config: Read current allowEmojis setting
Config-->>CLI: Return setting state
CLI->>User: Show prompt (enable/disable)
User->>CLI: Select option
CLI->>Config: Save new allowEmojis value
Config-->>CLI: Confirm save
CLI->>User: Log result
end
rect rgba(150, 200, 100, 0.5)
Note over User,Sanitizer: Commit Message Generation
User->>CLI: Run commit command
CLI->>CommitGen: generateCommitMessage({allowEmojis: true/false, ...})
CommitGen->>Sanitizer: sanitizeCommitMessage(message, allowEmojis)
alt allowEmojis is true
Sanitizer->>Sanitizer: Remove quotes only, preserve emojis
else allowEmojis is false
Sanitizer->>Sanitizer: Remove quotes and emoji characters
end
Sanitizer-->>CommitGen: Return sanitized message
CommitGen-->>CLI: Return final message
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
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: 1
🤖 Fix all issues with AI agents
In `@src/utils/sanitizeCommitMessage.js`:
- Around line 16-21: The current emoji-strip in sanitizeCommitMessage (the block
using allowEmojis and result.replace) leaves behind zero-width joiners and
variation selectors; update the replacement to remove ZWJ (U+200D) and VS16
(U+FE0F) and to match emoji sequences so no invisible characters remain—i.e.,
refine the regex used in the result.replace call to include \u200D and \uFE0F
handling (or use a pattern that matches Extended_Pictographic sequences
including joiners/variation selectors) so the function fully strips emojis when
allowEmojis is false.
🧹 Nitpick comments (1)
src/cli/commands/emoji.js (1)
9-35: Clean implementation following established patterns.The command handler follows the dependency injection pattern and properly handles user cancellation via the
undefinedcheck. The logic is straightforward and readable.One minor defensive suggestion: if
config.get('allowEmojis')returnsundefined(e.g., fresh config before defaults apply), the initial selection would default to "Disable" (index 1), which contradicts the intended default oftrue. Consider using nullish coalescing for robustness:🛡️ Optional: Add defensive default for initial selection
export function createEmojiCommand({ config }) { return async function emojiAction() { - const currentEnabled = config.get('allowEmojis') + const currentEnabled = config.get('allowEmojis') ?? true console.log(
| // Strip emojis if disabled | ||
| if (!allowEmojis) { | ||
| result = result.replace( | ||
| /\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, | ||
| '', | ||
| ) |
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.
🧩 Analysis chain
🏁 Script executed:
git ls-files | grep -E "(sanitize|emoji)" | head -20Repository: laststance/git-gpt-commit
Length of output: 196
🏁 Script executed:
fd -t f "sanitizeCommitMessage" .Repository: laststance/git-gpt-commit
Length of output: 176
🏁 Script executed:
cat -n src/utils/sanitizeCommitMessage.jsRepository: laststance/git-gpt-commit
Length of output: 1036
🏁 Script executed:
cat -n utils/sanitizeCommitMessage.jsRepository: laststance/git-gpt-commit
Length of output: 218
🏁 Script executed:
cat -n utils/sanitizeCommitMessage.test.jsRepository: laststance/git-gpt-commit
Length of output: 3257
🏁 Script executed:
# Check Node.js version requirements and package.json
cat package.json | grep -A 5 -B 5 "engines"Repository: laststance/git-gpt-commit
Length of output: 51
🏁 Script executed:
# Test the emoji regex behavior to understand current vs suggested approach
node << 'EOF'
// Test if Unicode properties work
try {
const testStr = '🐛🔥💥';
const current = testStr.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
console.log('Current regex works:', current === '');
} catch (e) {
console.log('Current regex error:', e.message);
}
// Test ZWJ sequences (family emoji)
const familyEmoji = '👨👩👧👦'; // Man, ZWJ, Woman, ZWJ, Girl, ZWJ, Boy
console.log('Family emoji:', familyEmoji);
console.log('Family emoji length:', familyEmoji.length);
console.log('Family emoji codepoints:', [...familyEmoji].length);
// Test with variation selector
const emojiWithVS = '❤️'; // Heart with VS16
console.log('Heart with VS16:', emojiWithVS);
console.log('Heart with VS16 length:', emojiWithVS.length);
// Test current regex on complex emoji
try {
const result = familyEmoji.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
console.log('Family emoji after current regex:', result);
console.log('Family emoji after current regex length:', result.length);
console.log('Invisible characters remain:', result.length > 0);
} catch (e) {
console.log('Error testing family emoji:', e.message);
}
EOFRepository: laststance/git-gpt-commit
Length of output: 332
🏁 Script executed:
# Test the suggested fix
node << 'EOF'
// Test suggested regex with additional emoji components
const familyEmoji = '👨👩👧👦'; // Family emoji with ZWJ
const heartWithVS = '❤️'; // Heart with VS16
// Current regex
const currentResult = familyEmoji.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
console.log('Current regex leaves:', currentResult.length, 'chars');
// Suggested regex from review
try {
const suggestedResult = familyEmoji.replace(
/(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,
''
);
console.log('Suggested regex leaves:', suggestedResult.length, 'chars');
} catch (e) {
console.log('Suggested regex error:', e.message);
}
// Test with more comprehensive emoji patterns
const testCases = [
{ name: 'Basic emoji', text: '🐛' },
{ name: 'ZWJ family', text: '👨👩👧👦' },
{ name: 'Emoji with VS16', text: '❤️' },
{ name: 'Skin tone modifier', text: '👋🏽' },
];
console.log('\n--- Testing current regex ---');
testCases.forEach(({ name, text }) => {
const result = text.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
console.log(`${name}: left ${result.length} chars`);
});
console.log('\n--- Testing suggested regex ---');
testCases.forEach(({ name, text }) => {
try {
const result = text.replace(
/(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,
''
);
console.log(`${name}: left ${result.length} chars`);
} catch (e) {
console.log(`${name}: error - ${e.message}`);
}
});
EOFRepository: laststance/git-gpt-commit
Length of output: 422
🏁 Script executed:
# Check Node.js version and what Unicode property support is available
node << 'EOF'
console.log('Node.js version:', process.version);
// Check which Unicode properties are supported
const props = [
'Emoji_Presentation',
'Extended_Pictographic',
'Emoji_Modifier',
'Emoji_Component',
];
props.forEach(prop => {
try {
const regex = new RegExp(`\\p{${prop}}`, 'u');
console.log(`✓ ${prop} supported`);
} catch (e) {
console.log(`✗ ${prop} not supported`);
}
});
EOFRepository: laststance/git-gpt-commit
Length of output: 213
Remove ZWJ sequences and variation selectors to fully strip emojis.
The current regex leaves invisible characters behind when removing emojis:
- ZWJ sequences (e.g., family emojis like 👨👩👧👦) leave zero-width joiners (\u200D)
- Emoji with variation selectors (e.g., ❤️) leave VS16 (\uFE0F)
Apply the suggested regex to handle these components:
✅ Suggested regex refinement
- /\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu,
+ /(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,All required Unicode properties are supported in current Node.js versions.
📝 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.
| // Strip emojis if disabled | |
| if (!allowEmojis) { | |
| result = result.replace( | |
| /\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, | |
| '', | |
| ) | |
| // Strip emojis if disabled | |
| if (!allowEmojis) { | |
| result = result.replace( | |
| /(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu, | |
| '', | |
| ) |
🤖 Prompt for AI Agents
In `@src/utils/sanitizeCommitMessage.js` around lines 16 - 21, The current
emoji-strip in sanitizeCommitMessage (the block using allowEmojis and
result.replace) leaves behind zero-width joiners and variation selectors; update
the replacement to remove ZWJ (U+200D) and VS16 (U+FE0F) and to match emoji
sequences so no invisible characters remain—i.e., refine the regex used in the
result.replace call to include \u200D and \uFE0F handling (or use a pattern that
matches Extended_Pictographic sequences including joiners/variation selectors)
so the function fully strips emojis when allowEmojis is false.
Closes #71
Adds an \�llowEmojis\ config option (default: true) with a \git gpt emoji\ command to toggle it.
Changes:
Usage:
\\�ash
git gpt emoji # Toggle emoji support on/off
\\
When disabled, emojis like bug/fire/explosion get stripped from generated commit messages. Enabled by default to match modern conventions (gitmoji, etc).
All 59 tests passing.
Found this helpful? Buy me a coffee
Summary by CodeRabbit
Release Notes
New Features
emojicommand to toggle emoji usage in commit messages on or offTests