Skip to content

Commit

Permalink
ci(pr-name-check): integrates pr naming convention into workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkarry committed Apr 13, 2024
1 parent dc82f90 commit 90fed18
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pr-naming-check.yml
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
});

0 comments on commit 90fed18

Please sign in to comment.