ci: add PR title linting against Conventional Commits (#988)

Lint PR titles

Reviewed-on: https://gitea.com/gitea/runner/pulls/988
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Nicolas
2026-05-21 19:13:43 +00:00
parent b30204aa94
commit d6fbe75721
3 changed files with 50 additions and 0 deletions

19
tools/lint-pr-title.ts Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env node
import {env, exit} from 'node:process';
const allowedTypes = 'build, chore, ci, docs, enhance, feat, fix, perf, refactor, revert, style, test';
const title = env.PR_TITLE;
if (!title) {
console.error('Missing PR_TITLE');
exit(1);
}
const validTitlePattern = new RegExp(`^(${allowedTypes.replaceAll(', ', '|')})(\\([\\w.-]+\\))?(!)?: .+$`);
if (!validTitlePattern.test(title)) {
console.error(`Invalid PR title: ${title}`);
console.error('Expected format: type(scope): subject');
console.error(`Allowed types: ${allowedTypes}`);
exit(1);
}