Skip to content
Open
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
21 changes: 21 additions & 0 deletions .github/workflows/lint-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint Commit Messages

on: [pull_request]

jobs:
lint-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: "npm"
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
- name: Lint commit messages
run: npm run lint:commit
54 changes: 54 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = {
plugins: [
{
rules: {
'headlamp-format': ({ header }) => {
if (!header) {
return [false, 'Commit message header must not be empty'];
}
if (/ :/.test(header)) {
return [false, 'There should be no space before ":"'];
}
const parts = header.split(':').map(p => p.trim());
if (parts.length < 2) {
return [
false,
'Commit message must follow format: <area>: <description>',
];
}
const [area, subOrDesc] = parts;
if (!area) {
return [false, 'Area must not be empty'];
}
if (!subOrDesc) {
return [false, 'Description or sub-area must not be empty'];
}
const strictAreas = ['app', 'frontend', 'backend'];
if (strictAreas.includes(area.toLowerCase()) && parts.length < 3) {
return [
false,
`Commits starting with "${area}" must follow format: ` +
`<${area}>: <sub-area>: <description>\n` +
`Example: "${area}: HomeButton: Fix navigation"`,
];
}
const description =
parts.length >= 3 ? parts.slice(2).join(': ') : parts[1];
if (!description) {
return [false, 'Description must not be empty'];
}
if (description[0] !== description[0].toUpperCase()) {
return [false, 'Description must start with a capitalized verb'];
}
return [true, ''];
},
},
},
],

rules: {
'headlamp-format': [2, 'always'],
'header-max-length': [2, 'always', 72],
'body-max-line-length': [2, 'always', 72],
},
};
7 changes: 7 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ dedicated [i18n docs](./development/i18n).
For general guidelines on making PRs/commits easier to review, please check
out Kinvolk's
[contribution guidelines on git](https://github.com/kinvolk/contribution/tree/master/topics/git.md).
We also use `commitlint` to enforce these guidelines automatically. You can check your commits locally by running:

```bash
npm run lint:commit
```

This command checks all commit messages that exist after origin/main against our guidelines. The same check runs in our CI system for every Pull Request.

## Testing

Expand Down
Loading
Loading