Skip to content

Commit 7ebe0f8

Browse files
committed
chore: enforce conventional commit messages with husky and commitlint
- Add steps to bin/setup to install husky and the commitlint npm packages - Configure husky to run commitlint via the commit-msg hook - Add commitlint configuration based on my specific preferences - Add npm specific files (node_modules/, package-lock.json) to .gitignore
1 parent 3137426 commit 7ebe0f8

File tree

6 files changed

+99
-31
lines changed

6 files changed

+99
-31
lines changed

.commitlintrc.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
extends: '@commitlint/config-conventional'
3+
4+
rules:
5+
# See: https://commitlint.js.org/reference/rules.html
6+
#
7+
# Rules are made up by a name and a configuration array. The configuration
8+
# array contains:
9+
#
10+
# * Severity [0..2]: 0 disable rule, 1 warning if violated, or 2 error if
11+
# violated
12+
# * Applicability [always|never]: never inverts the rule
13+
# * Value: value to use for this rule (if applicable)
14+
#
15+
# Run `npx commitlint --print-config` to see the current setting for all
16+
# rules.
17+
#
18+
header-max-length: [2, always, 100] # Header can not exceed 100 chars
19+
20+
type-case: [2, always, lower-case] # Type must be lower case
21+
type-empty: [2, never] # Type must not be empty
22+
23+
# Supported conventional commit types
24+
type-enum: [2, always, [build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test]]
25+
26+
scope-case: [2, always, lower-case] # Scope must be lower case
27+
28+
# Error if subject is one of these cases (encourages lower-case)
29+
subject-case: [2, never, [sentence-case, start-case, pascal-case, upper-case]]
30+
subject-empty: [2, never] # Subject must not be empty
31+
subject-full-stop: [2, never, "."] # Subject must not end with a period
32+
33+
body-leading-blank: [2, always] # Body must have a blank line before it
34+
body-max-line-length: [2, always, 100] # Body lines can not exceed 100 chars
35+
36+
footer-leading-blank: [2, always] # Footer must have a blank line before it
37+
footer-max-line-length: [2, always, 100] # Footer lines can not exceed 100 chars
38+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ doc
88
pkg
99
rdoc
1010
Gemfile.lock
11+
node_modules
12+
package-lock.json

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no-install commitlint --edit "$1"

CONTRIBUTING.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55

66
# Contributing to the git gem
77

8-
* [Summary](#summary)
9-
* [How to contribute](#how-to-contribute)
10-
* [How to report an issue or request a feature](#how-to-report-an-issue-or-request-a-feature)
11-
* [How to submit a code or documentation change](#how-to-submit-a-code-or-documentation-change)
12-
* [Commit your changes to a fork of `ruby-git`](#commit-your-changes-to-a-fork-of-ruby-git)
13-
* [Create a pull request](#create-a-pull-request)
14-
* [Get your pull request reviewed](#get-your-pull-request-reviewed)
15-
* [Design philosophy](#design-philosophy)
16-
* [Direct mapping to git commands](#direct-mapping-to-git-commands)
17-
* [Parameter naming](#parameter-naming)
18-
* [Output processing](#output-processing)
19-
* [Coding standards](#coding-standards)
20-
* [1 PR = 1 Commit](#1-pr--1-commit)
21-
* [Unit tests](#unit-tests)
22-
* [Continuous integration](#continuous-integration)
23-
* [Documentation](#documentation)
24-
* [Building a specific version of the Git command-line](#building-a-specific-version-of-the-git-command-line)
25-
* [Install pre-requisites](#install-pre-requisites)
26-
* [Obtain Git source code](#obtain-git-source-code)
27-
* [Build git](#build-git)
28-
* [Use the new Git version](#use-the-new-git-version)
29-
* [Licensing](#licensing)
8+
- [Summary](#summary)
9+
- [How to contribute](#how-to-contribute)
10+
- [How to report an issue or request a feature](#how-to-report-an-issue-or-request-a-feature)
11+
- [How to submit a code or documentation change](#how-to-submit-a-code-or-documentation-change)
12+
- [Commit your changes to a fork of `ruby-git`](#commit-your-changes-to-a-fork-of-ruby-git)
13+
- [Create a pull request](#create-a-pull-request)
14+
- [Get your pull request reviewed](#get-your-pull-request-reviewed)
15+
- [Design philosophy](#design-philosophy)
16+
- [Direct mapping to git commands](#direct-mapping-to-git-commands)
17+
- [Parameter naming](#parameter-naming)
18+
- [Output processing](#output-processing)
19+
- [Coding standards](#coding-standards)
20+
- [Commit message guidelines](#commit-message-guidelines)
21+
- [Unit tests](#unit-tests)
22+
- [Continuous integration](#continuous-integration)
23+
- [Documentation](#documentation)
24+
- [Building a specific version of the Git command-line](#building-a-specific-version-of-the-git-command-line)
25+
- [Install pre-requisites](#install-pre-requisites)
26+
- [Obtain Git source code](#obtain-git-source-code)
27+
- [Build git](#build-git)
28+
- [Use the new Git version](#use-the-new-git-version)
29+
- [Licensing](#licensing)
3030

3131
## Summary
3232

@@ -153,18 +153,30 @@ behavior.
153153
To ensure high-quality contributions, all pull requests must meet the following
154154
requirements:
155155

156-
### 1 PR = 1 Commit
156+
### Commit message guidelines
157157

158-
* All commits for a PR must be squashed into a single commit.
159-
* To avoid an extra merge commit, the PR must be able to be merged as [a fast-forward
160-
merge](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging).
161-
* The easiest way to ensure a fast-forward merge is to rebase your local branch to
162-
the `ruby-git` master branch.
158+
All commit messages must follow the [Conventional Commits
159+
standard](https://www.conventionalcommits.org/en/v1.0.0/). This helps us maintain a
160+
clear and structured commit history, automate versioning, and generate changelogs
161+
effectively.
162+
163+
To ensure compliance, this project includes:
164+
165+
- A git commit-msg hook that validates your commit messages before they are accepted.
166+
167+
To activate the hook, you must have node installed and run `bin/setup` or
168+
`npm install`.
169+
170+
- A GitHub Actions workflow that will enforce the Conventional Commit standard as
171+
part of the continuous integration pipeline.
172+
173+
Any commit message that does not conform to the Conventional Commits standard will
174+
cause the workflow to fail and not allow the PR to be merged.
163175

164176
### Unit tests
165177

166-
* All changes must be accompanied by new or modified unit tests.
167-
* The entire test suite must pass when `bundle exec rake default` is run from the
178+
- All changes must be accompanied by new or modified unit tests.
179+
- The entire test suite must pass when `bundle exec rake default` is run from the
168180
project's local working copy.
169181

170182
While working on specific features, you can run individual test files or a group of

bin/setup

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ set -vx
55

66
bundle install
77

8-
# Do any other automated setup that you need to do here
8+
if [ -x "$(command -v npm)" ]; then
9+
npm install
10+
else
11+
echo "npm is not installed"
12+
echo "Install npm then re-run this script to enable the conventional commit git hook."
13+
fi

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"devDependencies": {
3+
"@commitlint/cli": "^19.8.0",
4+
"@commitlint/config-conventional": "^19.8.0",
5+
"husky": "^9.1.7"
6+
},
7+
"scripts": {
8+
"prepare": "husky"
9+
}
10+
}

0 commit comments

Comments
 (0)