Skip to content

Commit 9f90bbd

Browse files
authored
feat: Breaking Changes & Configuration Migration (v2 version) (#280)
* docs: add new configuration docs * feat: remove .commit-check.yml and move config to rules * chore: code cleanup * feat(breaking): update commit-check commands * ci: update ci to pass failure * fix: update rules.py and cchk.toml * fix: code cleanup and fix tests * style: format code with ruff * chore: change error output style * fix: skip if merge commit * fix: bypass when branch is HEAD * fix: update main_test.py * fix: update args and tests * fix: revert noxfile.py to commit-check session * refactor: save progress * refactor: remove legacy files * test: add more tests * chore: update conf.py * fix: update main.py to support stdin for other checks * fix: update tests * fix: checkout branch name * fix: pint action to commit hash * fix: checkout branch name * fix: add checkout branch name * fix: update session name * fix: update per code review
1 parent 48de738 commit 9f90bbd

37 files changed

+3251
-2151
lines changed

.commit-check.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ nox -s build
2727
python3 -m pip wheel --no-deps -w dist . # NETWORK ISSUES: Also fails due to build dependencies
2828

2929
# Install wheel (depends on build)
30-
nox -s install-wheel # NETWORK ISSUES: Often fails due to PyPI timeouts in CI environments
30+
nox -s install # NETWORK ISSUES: Often fails due to PyPI timeouts in CI environments
3131
```
3232

3333
### Testing

.github/workflows/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
runs-on: ubuntu-24.04
2222
steps:
2323
- uses: actions/checkout@v5
24+
with:
25+
ref: ${{ github.head_ref }} # get current branch name
2426
- uses: actions/setup-python@v6
2527
with:
2628
python-version: '3.x'
@@ -48,7 +50,7 @@ jobs:
4850
- name: Collect Coverage
4951
run: nox -s coverage
5052

51-
- uses: codecov/[email protected]
53+
- uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
5254
with:
5355
token: ${{ secrets.CODECOV_TOKEN }}
5456
files: ./coverage.xml
@@ -81,7 +83,7 @@ jobs:
8183
- name: Install test
8284
# using a wildcard as filename on Windows requires a bash shell
8385
shell: bash
84-
run: nox -s install-wheel
86+
run: nox -s install
8587

8688
docs:
8789
runs-on: ubuntu-24.04
@@ -110,7 +112,7 @@ jobs:
110112
- name: Upload docs to github pages
111113
# only publish doc changes from main branch
112114
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
113-
uses: peaceiris/actions-gh-pages@v4
115+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
114116
with:
115117
github_token: ${{ secrets.GITHUB_TOKEN }}
116118
publish_dir: ./_build/html

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ repos:
1717
- id: trailing-whitespace
1818
- id: name-tests-test
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
# Ruff version.
21-
rev: v0.12.12
20+
rev: v0.13.2
2221
hooks:
23-
# Run the linter.
24-
- id: ruff
22+
- id: ruff-check
2523
args: [ --fix ]
24+
- id: ruff-format
2625
- repo: https://github.com/pre-commit/mirrors-mypy
2726
rev: v1.17.1
2827
hooks:

.pre-commit-hooks.yaml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
language: python
88
stages: [commit-msg]
99
- id: check-branch
10-
name: check branch naming
11-
description: ensures branch naming to match regex
10+
name: check branch name
11+
description: ensures branch name to match regex
1212
entry: commit-check
1313
args: [--branch]
1414
pass_filenames: false
@@ -27,24 +27,3 @@
2727
args: [--author-email]
2828
pass_filenames: false
2929
language: python
30-
- id: check-commit-signoff
31-
name: check committer signoff
32-
description: ensures committer to add a Signed-off-by trailer
33-
entry: commit-check
34-
args: [--commit-signoff]
35-
pass_filenames: false
36-
language: python
37-
- id: check-merge-base
38-
name: check merge base
39-
description: ensures current branch is rebased onto target branch
40-
entry: commit-check
41-
args: [--merge-base]
42-
pass_filenames: false
43-
language: python
44-
- id: check-imperative
45-
name: check imperative mood
46-
description: ensures commit message uses imperative mood
47-
entry: commit-check
48-
args: [--imperative]
49-
pass_filenames: true
50-
language: python

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Check Commit Signature Failed
193193
194194
Commit rejected.
195195
196-
Type commit_signoff check failed => c92ce259ff041c91859c7fb61afdbb391e769d0f
196+
Type signoff check failed => c92ce259ff041c91859c7fb61afdbb391e769d0f
197197
It doesn't match regex: Signed-off-by:.*[A-Za-z0-9]\s+<.+@.+>
198198
Signed-off-by not found in latest commit
199199
Suggest: run command `git commit -m "conventional commit message" --signoff`

cchk.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[commit]
2+
# https://www.conventionalcommits.org
3+
conventional_commits = true
4+
subject_capitalized = false
5+
subject_imperative = true
6+
subject_max_length = 50
7+
subject_min_length = 5
8+
allow_commit_types = ["feat", "fix", "docs", "style", "refactor", "test", "chore", "ci"]
9+
allow_merge_commits = true
10+
allow_revert_commits = true
11+
allow_empty_commits = false
12+
allow_fixup_commits = true
13+
allow_wip_commits = false
14+
require_body = false
15+
require_signed_off_by = false
16+
allow_authors = []
17+
ignore_authors = ["dependabot[bot]", "copilot[bot]"]
18+
19+
[branch]
20+
# https://conventional-branch.github.io/
21+
conventional_branch = true
22+
allow_branch_types = ["feature", "bugfix", "hotfix", "release", "chore", "feat", "fix"]
23+
require_rebase_target = "main"

commit_check/__init__.py

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,29 @@
1-
"""The commit-check package's base module."""
2-
from importlib.metadata import version
1+
"""The commit-check package's base module.
32
4-
RED = '\033[0;31m'
5-
GREEN = "\033[32m"
6-
YELLOW = '\033[93m'
7-
RESET_COLOR = '\033[0m'
3+
Exports:
4+
PASS / FAIL exit codes
5+
DEFAULT_CONFIG: minimal default rule set used when no config found
6+
ANSI color constants
7+
__version__ (package version)
8+
"""
89

10+
from importlib.metadata import version
11+
from commit_check.rule_builder import RuleBuilder
12+
13+
# Exit codes used across the package
914
PASS = 0
1015
FAIL = 1
1116

12-
"""
13-
Use default config if .commit-check.yml not exist.
14-
"""
15-
DEFAULT_CONFIG = {
16-
'checks': [
17-
{
18-
'check': 'message',
19-
'regex': r'^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)',
20-
'error': 'The commit message should be structured as follows:\n\n'
21-
'<type>[optional scope]: <description>\n'
22-
'[optional body]\n'
23-
'[optional footer(s)]\n\n'
24-
'More details please refer to https://www.conventionalcommits.org',
25-
'suggest': 'please check your commit message whether matches above regex'
26-
},
27-
{
28-
'check': 'branch',
29-
'regex': r'^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+)',
30-
'error': 'Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/ chore/',
31-
'suggest': 'run command `git checkout -b type/branch_name`',
32-
},
33-
{
34-
'check': 'author_name',
35-
'regex': r'^[A-Za-zÀ-ÖØ-öø-ÿ\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])',
36-
'error': 'The committer name seems invalid',
37-
'suggest': 'run command `git config user.name "Your Name"`',
38-
},
39-
{
40-
'check': 'author_email',
41-
'regex': r'^.+@.+$',
42-
'error': 'The committer\'s email seems invalid',
43-
'suggest': 'run command `git config user.email [email protected]`',
44-
},
45-
{
46-
'check': 'commit_signoff',
47-
'regex': r'Signed-off-by:.*[A-Za-z0-9]\s+<.+@.+>',
48-
'error': 'Signed-off-by not found in latest commit',
49-
'suggest': 'run command `git commit -m "conventional commit message" --signoff`',
50-
},
51-
{
52-
'check': 'merge_base',
53-
'regex': r'main', # it can be master, develop, devel etc based on your project.
54-
'error': 'Current branch is not rebased onto target branch',
55-
'suggest': 'Please ensure your branch is rebased with the target branch',
56-
},
57-
{
58-
'check': 'imperative',
59-
'regex': r'', # Not used for imperative mood check
60-
'error': 'Commit message should use imperative mood (e.g., "Add feature" not "Added feature")',
61-
'suggest': 'Use imperative mood in commit message like "Add", "Fix", "Update", "Remove"',
62-
},
63-
],
64-
}
65-
66-
67-
"""
68-
Overwrite DEFAULT_CONFIG if `.commit-check.yml` exist.
69-
"""
17+
# ANSI color codes used for CLI output
18+
RED = "\033[91m"
19+
GREEN = "\033[92m"
20+
YELLOW = "\033[93m"
21+
RESET_COLOR = "\033[0m"
7022

71-
CONFIG_FILE = '.commit-check.yml'
23+
# Default (empty) configuration translated into internal checks structure
24+
_rule_builder = RuleBuilder({})
25+
_default_rules = _rule_builder.build_all_rules()
26+
DEFAULT_CONFIG = {"checks": [rule.to_dict() for rule in _default_rules]}
7227

28+
CONFIG_FILE = "." # Search current directory for commit-check.toml or cchk.toml
7329
__version__ = version("commit-check")

commit_check/author.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

commit_check/branch.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)