Skip to content

Commit

Permalink
Merge pull request #4 from mcarvin8/refactor-log-cmd
Browse files Browse the repository at this point in the history
fix: use git.log command from simple-git
  • Loading branch information
mcarvin8 authored Apr 7, 2024
2 parents 4b2657a + db961db commit ac70137
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/service/retrieveCommitMessages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { readFileSync } from 'node:fs';
import { simpleGit, SimpleGit, SimpleGitOptions } from 'simple-git';
import { simpleGit, SimpleGit, SimpleGitOptions, DefaultLogFields, LogResult } from 'simple-git';

export async function retrieveCommitMessages(
fromCommit: string,
Expand All @@ -14,7 +14,10 @@ export async function retrieveCommitMessages(
trimmed: false,
};
const git: SimpleGit = simpleGit(options);
const commitMessages = await git.raw('log', '--format=%s', `${fromCommit}..${toCommit}`);
const result: LogResult<string | DefaultLogFields> = await git.log({ from: fromCommit, to: toCommit, format: '%s' });

// Filter only entries that match the DefaultLogFields type
const commitMessages: string[] = (result.all as DefaultLogFields[]).map((commit) => commit.message);

let regex: RegExp;
let regexPattern = '';
Expand All @@ -26,12 +29,14 @@ export async function retrieveCommitMessages(
}

const matchedMessages: string[] = [];
let match;
while ((match = regex.exec(commitMessages)) !== null) {
if (match[1]) {
matchedMessages.push(match[1]);
commitMessages.forEach((message) => {
let match;
while ((match = regex.exec(message)) !== null) {
if (match[1]) {
matchedMessages.push(match[1]);
}
}
}
});

return matchedMessages;
}

0 comments on commit ac70137

Please sign in to comment.