Skip to content

chore: add action to check PR title prefix #5

chore: add action to check PR title prefix

chore: add action to check PR title prefix #5

Workflow file for this run

name: PR
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Check PR Title Prefix
id: title-check
uses: actions/github-script@v7
with:
script: |
const titlePrefixes = ["feat", "fix", "break", "chore"];
const title = context.payload.pull_request.title.toLowerCase();
const titleHasValidPrefix = titlePrefixes.some((prefix) => title.startsWith(`${prefix}:`));
const message = titleHasValidPrefix
? "🚨 PR title does not meet the requirements. It must start with one of the following prefixes: 'feat:', 'fix:', 'chore:', 'break:'."
: "✅ PR title meet the requirements";
return {
message,
titleHasValidPrefix,
};
- uses: thollander/actions-comment-pull-request@v2
with:
message: |
${{ steps.title-check.outputs.result.message }}
comment_tag: PR title check result
- uses: actions/github-script@v7
env:
SUCCESS: ${{ steps.title-check.outputs.result.titleHasValidPrefix }}
with:
script: |
const { SUCCESS } = process.env;
console.log(SUCCESS);
process.exit(-1);