-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(pr-name-check): integrates pr naming convention into workflow
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Pull Request Title Validation | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, edited] | ||
|
||
jobs: | ||
pull-request-title-validation: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check PR title format | ||
id: check_title | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const titleRegex = /^(Revert \")?(feat|build|chore|style|fix|update|ci)\((\w|\/|-)+\)\:.+/g; | ||
const title = context.payload.pull_request.title; | ||
const isValid = titleRegex.test(title); | ||
if (!isValid) { | ||
console.error(`PR title "${title}" doesn't match the required format.`); | ||
} | ||
return isValid; | ||
- name: Leave comment for OP | ||
if: steps.check_title.outputs.result == 'false' | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const prNumber = context.payload.pull_request.number; | ||
const author = context.payload.pull_request.user.login; | ||
const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our naming conventions (https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(<area>): <description>"`; | ||
github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: prNumber, | ||
body: message | ||
}); |