Skip to content
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

fix: use git.log command from simple-git #4

Merged
merged 1 commit into from
Apr 7, 2024
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
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;
}