Skip to content

Commit 75981a0

Browse files
Merge pull request #56 from youwe-petervanderwal/feat/conventional-commit-message
feat: validate commit messages are according conventional commits guidelines
2 parents 326e7cf + 6168772 commit 75981a0

File tree

10 files changed

+112
-3
lines changed

10 files changed

+112
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Pimcore PHPStan default config.
2222
- Pimcore PHP Mess Detector default config.
2323
- Added constraint for `PHPMD`, since Magento 2.4.8 requires version `3.x-dev`.
24+
- Commit Message validator to validate the commit message adheres to the
25+
[Conventional Commit Message structure](https://cheatography.com/albelop/cheat-sheets/conventional-commits/)
26+
and that the commit message contains a Jira ticket number it relates to.
2427

2528
### Changed
2629
- [BREAKING] The composer.json configurations `config.youwe-testing-suite.type` and `config.mediact-testing-suite.type`

MIGRATION.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,21 @@ As alternative, you can revert your project to the old behaviour by setting the
8080
parameter in your `grumphp.yml`. Please read [Why you should always analyse the whole project](https://phpstan.org/blog/why-you-should-always-analyse-whole-project)
8181
before reverting to the old behaviour.
8282

83-
### 4. Sanity checks
83+
### 4. Commit Message Jira project configuration
84+
85+
Configure the Jira project(s) for which ticket numbers should be included in your commit messages.
86+
Add the following configuration to the `grumphp.yml`:
87+
88+
```yaml
89+
parameters:
90+
# Configure your Jira Project codes as pipe-separated value:
91+
git_commit_message.jira_projects: 'PIMBBBBABC|MAGBBBBDEF|P012345'
92+
93+
# Or to disable the requirement for a Jira ticket number in the commit message:
94+
# git_commit_message.jira_matcher: '/.*/'
95+
```
96+
97+
### 5. Sanity checks
8498
Check the following
8599

86100
1. The PHPCS file exists in your project root and points to the correct ruleset
@@ -90,7 +104,7 @@ configuration in youwe/testing-suite
90104
3. Run `ddev exec grumphp run` or `vendor/bin/grumphp run`
91105
4. Your git commit hook still functions as expected
92106

93-
### 5. Refactor and/or update/regenerate exclusion rules
107+
### 6. Refactor and/or update/regenerate exclusion rules
94108
Some rulesets will have changed. In a general sense, the rulesets are less
95109
strict compared to what they were before.
96110

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ or if no explicit setting was found for the Testing Suite, via
4646
## Included analysis tools
4747

4848
- [Git blacklist](docs/components/git-blacklist.md)
49+
- [Git commit message](docs/components/git-commit-message.md)
4950
- [Composer file validation](docs/components/composer.md)
5051
- [JSON Lint](docs/components/jsonlint.md)
5152
- [YamlLint](docs/components/yamllint.md)

config/default/grumphp.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ parameters:
7979
git_blacklist.match_word: true
8080
git_blacklist.ignore_patterns: []
8181

82+
git_commit_message.type_scope_conventions:
83+
types:
84+
- build
85+
- chore
86+
- ci
87+
- cleanup
88+
- config
89+
- docs
90+
- feat
91+
- fix
92+
- merge
93+
- perf
94+
- refactor
95+
- release
96+
- revert
97+
- style
98+
- test
99+
git_commit_message.enforce_capitalized_subject: false # Not to be used in combination with type_scope_conventions
100+
git_commit_message.max_body_width: 72 # To disable this setting, use a value of 0
101+
git_commit_message.max_subject_width: 72
102+
# The available Jira Projects should be configured in your project repository. Multiple projects can be configured pipe-separated
103+
git_commit_message.jira_projects: 'YOU_SHOULD_CONFIGURE_YOUR|JIRA_PROJECT_CODES|IN_YOUR_GRUMP_YML'
104+
git_commit_message.jira_matcher: '/\n.+ (%git_commit_message.jira_projects%)-\d+/'
105+
git_commit_message.matchers:
106+
'Must contain JIRA issue number within the message body (e.g. "Resolves PROJECT-1234")': '%git_commit_message.jira_matcher%'
107+
git_commit_message.case_insensitive: false
108+
82109
grumphp:
83110
ascii:
84111
failed: ~
@@ -107,6 +134,14 @@ grumphp:
107134
match_word: '%git_blacklist.match_word%'
108135
ignore_patterns: '%git_blacklist.ignore_patterns%'
109136

137+
git_commit_message:
138+
enforce_capitalized_subject: '%git_commit_message.enforce_capitalized_subject%'
139+
type_scope_conventions: '%git_commit_message.type_scope_conventions%'
140+
max_body_width: '%git_commit_message.max_body_width%'
141+
max_subject_width: '%git_commit_message.max_subject_width%'
142+
matchers: '%git_commit_message.matchers%'
143+
case_insensitive: '%git_commit_message.case_insensitive%'
144+
110145
xmllint:
111146
load_from_net: '%xmllint.load_from_net%'
112147
x_include: '%xmllint.x_include%'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Git Commit Message
2+
3+
The default configuration will validate the commit message adheres to the [Conventional Commit Message structure](https://cheatography.com/albelop/cheat-sheets/conventional-commits/)
4+
and that the commit message body contains a Jira ticket number it relates to.
5+
6+
## Available configuration
7+
8+
The following configuration can be changed in your project's `grumphp.yml`:
9+
10+
```yaml
11+
parameters:
12+
git_commit_message.type_scope_conventions:
13+
# Change list of allowed types, use `git_commit_message.type_scope_conventions: {}` to disable this feature
14+
types:
15+
- build
16+
- chore
17+
- feat
18+
git_commit_message.enforce_capitalized_subject: false
19+
git_commit_message.max_body_width: 72 # To disable this setting, use a value of 0
20+
git_commit_message.max_subject_width: 72
21+
# Configure your Jira Project codes as pipe-separated value
22+
git_commit_message.jira_projects: 'JIRAPROJ|OTHERPROJ'
23+
# Override if you want to change the Jira matcher, use `git_commit_message.jira_matcher: '/.*/` to disable it completely
24+
git_commit_message.jira_matcher: '/\n.+ (%git_commit_message.jira_projects%)-\d+/'
25+
# Configure custom matchers, make sure to include the Jira matcher if you want to add more custom matchers
26+
git_commit_message.matchers:
27+
'Must contain JIRA issue number within the message body (e.g. "Resolves PROJECT-1234")': '%git_commit_message.jira_matcher%'
28+
git_commit_message.case_insensitive: false
29+
30+
```

grumphp.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ parameters:
1010
- /^pdepend.xml$/
1111
- /^templates/
1212

13+
# Disable requirement for Jira ticket number in the commit message
14+
git_commit_message.jira_matcher: '/.*/'
15+
1316
grumphp:
1417
# Disable ddev wrapper when running grumphp of testing-suite itself.
1518
# Temp until testing-suite development is also wrapped by ddev, which is on the roadmap
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
imports:
2-
- resource: 'vendor/youwe/testing-suite/config/default/grumphp.yml'
2+
- resource: 'vendor/youwe/testing-suite/config/default/grumphp.yml'
3+
4+
parameters:
5+
# Configure your Jira Project codes as pipe-separated value:
6+
# git_commit_message.jira_projects: 'PIMBBBBABC|MAGBBBBDEF|P012345'
7+
8+
# Or to disable the requirement for a Jira ticket number in the commit message:
9+
# git_commit_message.jira_matcher: '/.*/'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
imports:
2+
- resource: 'vendor/youwe/testing-suite/config/magento2/grumphp.yml'
3+
4+
parameters:
5+
# Configure your Jira Project codes as pipe-separated value:
6+
# git_commit_message.jira_projects: 'PIMBBBBABC|MAGBBBBDEF|P012345'
7+
8+
# Or to disable the requirement for a Jira ticket number in the commit message:
9+
# git_commit_message.jira_matcher: '/.*/'

templates/files/pimcore/grumphp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ parameters:
88
# - For Pimcore 10.4 till 10.x: suggest to use level 5 maximum
99
# - For Pimcore 10.0 till 10.3.x: suggest to use level 4 maximum
1010

11+
# Configure your Jira Project codes as pipe-separated value:
12+
# git_commit_message.jira_projects: 'PIMBBBBABC|MAGBBBBDEF|P012345'
13+
14+
# Or to disable the requirement for a Jira ticket number in the commit message:
15+
# git_commit_message.jira_matcher: '/.*/'
16+
1117
# securitychecker.allow_list:
1218
# - CVE-2002-0121 # Add a jira ticket indicating when this vulnerability will be fixed (update/upgrade will be
1319
# performed). Within that ticket explain this (new) vulnerability.

templates/mapping/project/magento2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{magento2/,}grumphp.yml
12
{magento2/,}phpcs.xml
23
{magento2/,}phpmd.xml
34
{magento2/,}phpstan.neon

0 commit comments

Comments
 (0)