Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ const renderFileAsync = promisify(twig.renderFile);
// Get the three most recent commits
export function getRecentCommits(count = 3) {
try {
const format = '--pretty=format:%h\\|\\|\\|%s\\|\\|\\|%b';
// 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('|||');
Comment on lines +21 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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
       };
     });

return {
hash,
subject,
body: body ? body.trim() : ''
subject
};
});
} catch (error) {
Expand Down Expand Up @@ -239,9 +239,6 @@ export async function main() {

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?'
Expand Down