Improved handling of multiline commits.#15
Conversation
WalkthroughgetRecentCommits in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #15 +/- ##
========================================
+ Coverage 8.52% 8.66% +0.13%
========================================
Files 1 1
Lines 129 127 -2
========================================
Hits 11 11
+ Misses 118 116 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
index.js (1)
242-244: Remove dead code.The
commit.bodyfield is no longer returned bygetRecentCommits()(line 29), so this code block will never execute.Apply this diff to remove the dead code:
for (const commit of commits) { console.log(`\n${commit.hash} ${commit.subject}`); - if (commit.body) { - console.log(`${commit.body}`); - } const includeCommit = await confirm({ message: '🔄 Include this commit in PR description?'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
index.js(1 hunks)
🔇 Additional comments (1)
index.js (1)
27-30: LGTM: Simplified return structure.Removing the body field simplifies the commit data structure and aligns with the PR objective to fix multiline commit handling.
| // Use %x00 (null byte) as commit separator to handle multi-line messages | ||
| const format = '--pretty=format:%h\\|\\|\\|%s%x00'; | ||
| const output = execSync(`git log -${count} ${format}`).toString().trim(); | ||
|
|
||
| return output.split('\n').map(line => { | ||
| const [hash, subject, body] = line.split('|||'); | ||
| return output.split('\x00').filter(Boolean).map(line => { | ||
| const [hash, subject] = line.split('|||'); |
There was a problem hiding this comment.
Good approach with null byte separator, but consider edge case.
The use of %x00 (null byte) as a separator is a robust solution for handling multi-line commit messages. However, the ||| delimiter could theoretically appear in commit subjects, causing incorrect parsing.
Consider using a more unique delimiter or using different format specifiers. For example:
- // Use %x00 (null byte) as commit separator to handle multi-line messages
- const format = '--pretty=format:%h\\|\\|\\|%s%x00';
+ // Use %x00 (null byte) as both field and commit separator to handle multi-line messages
+ const format = '--pretty=format:%h%x00%s%x00%x00';
const output = execSync(`git log -${count} ${format}`).toString().trim();
- return output.split('\x00').filter(Boolean).map(line => {
- const [hash, subject] = line.split('|||');
+ return output.split('\x00\x00').filter(Boolean).map(line => {
+ const [hash, subject] = line.split('\x00');
return {
hash,
subject
};
});Testing no multiline commit messages.
7fa9e12 to
5c4712a
Compare
Checklist before requesting a review
Changed
Screenshots
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.