ci: 对PR提交的commit名进行检查 (#7414)

合并后在rule里面添加这个检查就能达成效果

- link to #7296
This commit is contained in:
status102
2023-11-30 17:51:24 +08:00
committed by GitHub
parent 750ff40b75
commit 4d2a8079a4

31
.github/workflows/pr-checker.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: PR Checker
on:
pull_request:
types: [opened, ready_for_review, reopened, synchronize]
jobs:
check_commit_name_in_pr:
runs-on: ubuntu-latest
steps:
- name: Check Commits
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const regex = /^((build|chore|ci|docs?|feat|fix|perf|refactor|rft|style|test)[\:\.\(\,]|[Rr]evert|[Rr]elease)/;
const invalidCommits = commits.filter(commit => !regex.test(commit.commit.message));
console.log(`check ${commits.length} commit(s)`);
if (invalidCommits.length > 0) {
const invalidCommitNames = invalidCommits.map(commit => commit.commit.message);
core.setFailed(`Invalid commit names found: ${invalidCommitNames.join(", ")}`);
}