feat: ci: Add PR title check workflow #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Title Check | |
on: | |
pull_request: | |
types: [opened, edited, synchronize, reopened] | |
defaults: | |
run: | |
shell: bash | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
check-pr-title: | |
name: Check PR Title | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Check PR Title | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const title = context.payload.pull_request.title; | |
const pattern = /^(feat|fix|docs|style|refactor|test|chore):\s\w+:\s.+/; | |
if (!pattern.test(title)) { | |
core.setFailed('PR title does not match the required format: <type>: <scope>: <subject>'); | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'Your PR title does not match the required format. Please update it to follow this convention: `<type>: <scope>: <subject>`\n\nTypes: feat, fix, docs, style, refactor, test, chore\nScope: required\nSubject: start with lowercase' | |
}); | |
} | |
- name: Request changes | |
if: failure() | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
github.rest.pulls.createReview({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number, | |
body: 'Please update the PR title to match the required format.', | |
event: 'REQUEST_CHANGES' | |
}) |