Skip to content

Commit d97bade

Browse files
committed
build(hooks): add commitlint hook
This change adds a configuration for commitlint - a tool designed to enforce a particular commit message style - and run it as part of Git's commit-msg hook. This validates commits immediately after the editor has been exited, and the configuration is derived from the configuration we provide to Commitizen. While the configuration provided suggests a maximum header and body length, neither of these are hard errors. This is to accommodate the occasional commit where it may be difficult or impossible to comply with the length requirements (for example, with a particularly long scope, or a long URL in the message body). Change-Id: Ib5e90472fd1f1da9c2bff47703c9682232ee5679 Signed-off-by: Chris Kay <chris.kay@arm.com>
1 parent c75ce06 commit d97bade

6 files changed

Lines changed: 3873 additions & 956 deletions

File tree

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
. "$(dirname "$0")/_/husky.sh"
55

66
"$(dirname "$0")/commit-msg.gerrit" "$@"
7+
"$(dirname "$0")/commit-msg.commitlint" "$@"

.husky/commit-msg.commitlint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
npx --no-install commitlint --edit "$1"

commitlint.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-env node */
2+
3+
"use strict";
4+
5+
const config = require("./.cz.json");
6+
7+
module.exports = {
8+
extends: ["@commitlint/config-conventional"],
9+
rules: {
10+
"header-max-length": [1, "always", config.maxHeaderWidth], /* Warning */
11+
"body-max-line-length": [1, "always", config.maxLineWidth], /* Warning */
12+
"signed-off-by": [2, "always", "Signed-off-by:"] /* Error */
13+
}
14+
};

docs/process/contributing.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ Making Changes
2929
- Make commits of logical units. See these general `Git guidelines`_ for
3030
contributing to a project.
3131

32+
- Ensure your commit messages comply with the `Conventional Commits`_
33+
specification:
34+
35+
.. code::
36+
37+
<type>[optional scope]: <description>
38+
39+
[optional body]
40+
41+
[optional footer(s)]
42+
43+
You can use the tooling installed by the optional steps in the
44+
:ref:`prerequisites <Prerequisites>` guide to validate this locally.
45+
3246
- Keep the commits on topic. If you need to fix another bug or make another
3347
enhancement, please address it on a separate topic branch.
3448

@@ -216,6 +230,7 @@ Binary Components
216230

217231
*Copyright (c) 2013-2020, Arm Limited and Contributors. All rights reserved.*
218232

233+
.. _Conventional Commits: https://www.conventionalcommits.org/en/v1.0.0
219234
.. _developer.trustedfirmware.org: https://developer.trustedfirmware.org
220235
.. _review.trustedfirmware.org: https://review.trustedfirmware.org
221236
.. _issue: https://developer.trustedfirmware.org/project/board/1/

0 commit comments

Comments
 (0)