Skip to content

Commit

Permalink
refactor: use git.log command from simple-git and map result to strin…
Browse files Browse the repository at this point in the history
…g array
  • Loading branch information
mcarvin8 committed Apr 7, 2024
1 parent 4b2657a commit 40ad90b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 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 } from 'simple-git';

export async function retrieveCommitMessages(
fromCommit: string,
Expand All @@ -14,7 +14,8 @@ export async function retrieveCommitMessages(
trimmed: false,
};
const git: SimpleGit = simpleGit(options);
const commitMessages = await git.raw('log', '--format=%s', `${fromCommit}..${toCommit}`);
const result = await git.log({ from: fromCommit, to: toCommit, format: '%s' });
const commitMessages = (result.all as unknown as DefaultLogFields[]).map((commit) => commit.message);

let regex: RegExp;
let regexPattern = '';
Expand All @@ -26,12 +27,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 40ad90b

Please sign in to comment.