Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add action to validate PR titles #8614

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/actions/pr-titles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const core = require('@actions/core');
const github = require('@actions/github');

(async function run() {
const title = github.context.payload.pull_request?.title;
const titleRegex = /^(chore|ci|docs|feat|fix|refactor|revert|test)(\(.+\))?!?: (.+)/;

if (!!title.match(titleRegex)) {
core.info('Pull request title is OK');
} else {
core.setFailed('Please use conventional commit style for the PR title so the merged change appears in the changelog. See https://www.conventionalcommits.org/.');
}
})();
22 changes: 22 additions & 0 deletions .github/workflows/pr-titles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: PR title check

on:
pull_request:
types: [opened, reopened, edited, synchronize]
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

jobs:
pr-title-lint:
name: Should follow conventional commit spec
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm i @actions/core @actions/github
- run: node .github/actions/pr-titles.js
Loading