checks: -check:message regex:'^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)' error:"The commit message should be structured as follows:\n\n <type>[optional scope]: <description>\n [optional body]\n [optional footer(s)]\n\n More details please refer to https://www.conventionalcommits.org" suggest:Pleasecheckyourcommitmessageagainsttheaboveregex.
-check:branch regex:^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+) error:"Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/ chore/" suggest:Runcommand`gitcheckout-btype/branch_name`
-check:merge_base regex:main# it can be master, develop, devel etc. based on your project. error:Currentbranchisnotrebasedontotargetbranch suggest:Ensureyourbranchisrebasedwiththetargetbranch
用法
作为 GitHub Actions
name:CommitCheck
on: push: pull_request: branches:'main'
jobs: commit-check: runs-on:ubuntu-latest permissions:# use permissions because of pr-comments contents:read pull-requests:write steps: -uses:actions/checkout@v4 with: ref:${{github.event.pull_request.head.sha}}# checkout PR HEAD commit fetch-depth:0# required for merge-base check -uses:commit-check/commit-check-action@v1 env: GITHUB_TOKEN:${{secrets.GITHUB_TOKEN}}# required for pr-comments with: message:true branch:true author-name:true author-email:true commit-signoff:true merge-base:false job-summary:true pr-comments:${{github.event_name=='pull_request'}}
作为 pre-commit hook
将以下配置添加到 .pre-commit-config.yaml 文件:
-repo:https://github.com/commit-check/commit-check rev:thetagorrevision hooks: -id:check-message# requires hook prepare-commit-msg -id:check-branch -id:check-author-name -id:check-author-email -id:check-commit-signoff -id:check-merge-base# requires downloading all git history
作为 CLI 工具
从 PyPI 安装:
pip install commit-check
# example commit-check --message --branch --author-name --author-email --commit-signoff --merge-base