Skip to content

Commit 04d10ef

Browse files
authored
chore: Add action to validate PR titles (#8614)
1 parent d7757d8 commit 04d10ef

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.github/actions/pr-titles.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
4+
(async function run() {
5+
const title = github.context.payload.pull_request?.title;
6+
const titleRegex = /^(chore|ci|docs|feat|fix|refactor|revert|test)(\(.+\))?!?: (.+)/;
7+
8+
if (!!title.match(titleRegex)) {
9+
core.info('Pull request title is OK');
10+
} else {
11+
core.setFailed('Please use conventional commit style for the PR title so the merged change appears in the changelog. See https://www.conventionalcommits.org/.');
12+
}
13+
})();

.github/workflows/pr-titles.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: PR title check
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, edited, synchronize]
6+
branches: [main]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.number }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
pr-title-lint:
14+
name: Should follow conventional commit spec
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
- run: npm i @actions/core @actions/github
22+
- run: node .github/actions/pr-titles.js

0 commit comments

Comments
 (0)