Skip to content

Commit 58d4452

Browse files
committed
Enforce conventional commit linting on the PR name.
1 parent 73c675b commit 58d4452

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.config/commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-conventional']}

.github/workflows/pr-name.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: pr-name
2+
permissions:
3+
pull-requests : read
4+
contents: read
5+
on:
6+
pull_request:
7+
types: ['opened', 'edited', 'reopened', 'synchronize']
8+
branches-ignore:
9+
- "v[0-9]+.[0-9]+.[0-9]+"
10+
- release
11+
12+
jobs:
13+
pr_name_lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
persist-credentials: false
19+
fetch-depth: 0
20+
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
21+
name: Install Node.js
22+
with:
23+
node-version: 16
24+
- name: Install dependencies
25+
run: |
26+
npm install @commitlint/[email protected] @commitlint/[email protected] @commitlint/[email protected] @actions/core
27+
- name: Lint PR name
28+
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
29+
with:
30+
script: |
31+
const load = require('@commitlint/load').default;
32+
const lint = require('@commitlint/lint').default;
33+
34+
const CONFIG = {
35+
extends: ['./.config/commitlint.config.js'],
36+
};
37+
38+
const title = context.payload.pull_request.title;
39+
40+
core.info(`Linting: ${title}`);
41+
42+
load(CONFIG)
43+
.then((opts) => {
44+
lint(
45+
title,
46+
opts.rules,
47+
opts.parserPreset ? {parserOpts: opts.parserPreset.parserOpts} : {}
48+
).then((report) => {
49+
report.warnings.forEach((warning) => {
50+
core.warning(warning.message);
51+
});
52+
53+
report.errors.forEach((error) => {
54+
core.error(error.message);
55+
});
56+
57+
if (!report.valid) {
58+
core.setFailed("PR title linting failed");
59+
}
60+
});
61+
});

0 commit comments

Comments
 (0)