feat: add conventional commit message validation
This commit is contained in:
@@ -52,7 +52,25 @@ export async function pull(repoPath: string) {
|
||||
return g.pull();
|
||||
}
|
||||
|
||||
const COMMIT_PATTERN = /^(feat|fix|refactor|docs|chore|test|style|perf|ci|build|revert)(\(.+\))?: .{1,100}$/;
|
||||
|
||||
export function validateCommitMessage(message: string): { valid: boolean; error?: string } {
|
||||
const firstLine = message.split("\n")[0];
|
||||
if (!COMMIT_PATTERN.test(firstLine)) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Invalid format. Expected: type(scope): description. Valid types: feat, fix, refactor, docs, chore, test, style, perf, ci, build, revert`,
|
||||
};
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
export async function commitFiles(repoPath: string, message: string, files?: string[]) {
|
||||
const validation = validateCommitMessage(message);
|
||||
if (!validation.valid) {
|
||||
throw new Error(validation.error);
|
||||
}
|
||||
|
||||
const g = git(repoPath);
|
||||
if (files && files.length > 0) {
|
||||
await g.add(files);
|
||||
|
||||
Reference in New Issue
Block a user