Skip to content

Commit 958d0ba

Browse files
committed
feat(packages): @sa/scripts: add ignore pattern list for command gitCommitVerify. close #504
1 parent 0206969 commit 958d0ba

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

packages/scripts/src/commands/git-commit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ export async function gitCommit(lang: Lang = 'en-us') {
6565
}
6666

6767
/** Git commit message verify */
68-
export async function gitCommitVerify(lang: Lang = 'en-us') {
68+
export async function gitCommitVerify(lang: Lang = 'en-us', ignores: RegExp[] = []) {
6969
const gitPath = await execCommand('git', ['rev-parse', '--show-toplevel']);
7070

7171
const gitMsgPath = path.join(gitPath, '.git', 'COMMIT_EDITMSG');
7272

7373
const commitMsg = readFileSync(gitMsgPath, 'utf8').trim();
7474

75+
if (ignores.some(regExp => regExp.test(commitMsg))) return;
76+
7577
const REG_EXP = /(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
7678

7779
if (!REG_EXP.test(commitMsg)) {

packages/scripts/src/config/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ const defaultOptions: CliOption = {
1313
'!node_modules/**'
1414
],
1515
ncuCommandArgs: ['--deep', '-u'],
16-
changelogOptions: {}
16+
changelogOptions: {},
17+
gitCommitVerifyIgnores: [
18+
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m,
19+
/^(Merge tag (.*?))(?:\r?\n)*$/m,
20+
/^(R|r)evert (.*)/,
21+
/^(amend|fixup|squash)!/,
22+
/^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))/,
23+
/^Merge remote-tracking branch(\s*)(.*)/,
24+
/^Automatic merge(.*)/,
25+
/^Auto-merged (.*?) into (.*)/
26+
]
1727
};
1828

1929
export async function loadCliOptions(overrides?: Partial<CliOption>, cwd = process.cwd()) {

packages/scripts/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export async function setupCli() {
7575
},
7676
'git-commit-verify': {
7777
desc: 'verify git commit message, make sure it match Conventional Commits standard',
78-
action: async () => {
79-
await gitCommitVerify();
78+
action: async args => {
79+
await gitCommitVerify(args?.lang, cliOptions.gitCommitVerifyIgnores);
8080
}
8181
},
8282
changelog: {

packages/scripts/src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ export interface CliOption {
2626
* @link https://github.com/soybeanjs/changelog
2727
*/
2828
changelogOptions: Partial<ChangelogOption>;
29+
/** The ignore pattern list of git commit verify */
30+
gitCommitVerifyIgnores: RegExp[];
2931
}

0 commit comments

Comments
 (0)