feat(ci): add PR title check workflow #31
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] | |
permissions: | |
pull-requests: write | |
jobs: | |
check-pr-title: | |
name: Check PR Title | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check PR Title and Manage Review | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const title = context.payload.pull_request.title; | |
const pattern = /^(\[skip changelog\]\s)?(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?:?\s(\w+:)?\s[a-z].+$/; | |
if (!pattern.test(title)) { | |
await github.rest.pulls.createReview({ | |
...context.repo, | |
pull_number: context.payload.pull_request.number, | |
body: 'Please update the PR title to match one of the required formats:\n\n1. `<type>: <scope>: <subject>`\n2. `<type>(<scope>): <subject>`\n\nTypes: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test\nArea/Scope: api, chain, state, mempool, multisig, networking, paych, proving, sealing, wallet, deps\nSubject: start with lowercase\n\nOptionally, you can add "[skip changelog]" at the start of the title if the change does not require a CHANGELOG.md entry.', | |
event: 'REQUEST_CHANGES' | |
}); | |
core.setFailed('PR title does not match the required format'); | |
} else { | |
const reviews = await github.rest.pulls.listReviews({ | |
...context.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
const botReview = reviews.data.find(review => | |
review.user.type === 'Bot' && | |
review.state === 'CHANGES_REQUESTED' | |
); | |
if (botReview) { | |
await github.rest.pulls.dismissReview({ | |
...context.repo, | |
pull_number: context.payload.pull_request.number, | |
review_id: botReview.id, | |
message: 'PR title now matches the required format.' | |
}); | |
} | |
} |