forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.ts
47 lines (39 loc) · 962 Bytes
/
read.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import minimist from 'minimist';
import type {GitOptions} from 'git-raw-commits';
import {getHistoryCommits} from './get-history-commits.js';
import {getEditCommit} from './get-edit-commit.js';
import {execa} from 'execa';
interface GetCommitMessageOptions {
cwd?: string;
from?: string;
to?: string;
last?: boolean;
edit?: boolean | string;
gitLogArgs?: string;
}
// Get commit messages
export default async function getCommitMessages(
settings: GetCommitMessageOptions
): Promise<string[]> {
const {cwd, from, to, last, edit, gitLogArgs} = settings;
if (edit) {
return getEditCommit(cwd, edit);
}
if (last) {
const executeGitCommand = await execa('git', [
'log',
'-1',
'--pretty=format:"%B"',
]);
return [executeGitCommand.stdout];
}
let gitOptions: GitOptions = {from, to};
if (gitLogArgs) {
gitOptions = {
...minimist(gitLogArgs.split(' ')),
from,
to,
};
}
return getHistoryCommits(gitOptions, {cwd});
}