Skip to content

Commit 2cbd338

Browse files
committed
refactor: restructure commit message validation pattern for clarity and maintainability
1 parent c4cc0bc commit 2cbd338

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

commit-message-validator.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ async function run() {
55
try {
66
// Get inputs from workflow
77
const token = core.getInput('github-token', { required: true });
8-
const pattern = core.getInput('pattern') || '^(Merge branch \'[^\']+\' into [^\s]+|Revert ".*"|Create PR for #\d+|(?:(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z0-9\-]+\))?: .*))$';
8+
9+
const mergeBranchPattern = "Merge branch '[^']+' into [^\\s]+";
10+
const revertPattern = 'Revert ".*"';
11+
const createPrPattern = 'Create PR for #\\d+';
12+
const types = [
13+
'feat', 'fix', 'chore', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'revert'
14+
].join('|');
15+
const conventionalPattern = `(?:(${types})(\\([a-z0-9\\-]+\\))?: .*)`;
16+
17+
const defaultPattern = `^(${mergeBranchPattern}|${revertPattern}|${createPrPattern}|${conventionalPattern})$`;
18+
const pattern = core.getInput('pattern') || defaultPattern;
919
const regexPattern = new RegExp(pattern);
1020

1121
// Create octokit client

0 commit comments

Comments
 (0)