Files
MaaAssistantArknights/.github/workflows/pr-checker.yml

33 lines
1.2 KiB
YAML

name: PR Checker
on:
pull_request:
types: [opened, edited, ready_for_review, reopened, synchronize]
jobs:
check_commit_name_in_pr:
if: github.head_ref != 'dev'
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|i18n)[\:\.\(\,]|[Rr]evert|[Rr]elease)/;
const invalidCommits = commits.filter(commit => !regex.test(commit.commit.message) || commit.parents.length > 1);
console.log(`check ${commits.length} commit(s)`);
if (invalidCommits.length > 0) {
const invalidCommitNames = invalidCommits.map(commit => commit.commit.message);
core.setFailed(`Invalid commit found: ${invalidCommitNames.join(", ")}`);
}