-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed old `commitlint.py`. - Added new module `linter` for linting and validation. - Added detailed validation on `linter` for message enhancement. - Added new error messages. - Added option `--quick` for quick linting. - Moved old validation to quick linting. - Added `pytest.ini` for adding src as a python path. - Updated test for both detailed and quick with same test data.
- Loading branch information
Showing
22 changed files
with
740 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
pythonpath = src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"""Main module for commitlint""" | ||
"""Main module for commitlint.""" | ||
|
||
from .commitlint import check_commit_message | ||
from .linter import lint_commit_message | ||
|
||
__all__ = ["check_commit_message"] | ||
__all__ = ["lint_commit_message"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
"""This module defines constants used throughout the application.""" | ||
|
||
COMMIT_HEADER_MAX_LENGTH = 72 | ||
|
||
COMMIT_TYPES = ( | ||
"build", | ||
"ci", | ||
"docs", | ||
"feat", | ||
"fix", | ||
"perf", | ||
"refactor", | ||
"style", | ||
"test", | ||
"chore", | ||
"revert", | ||
"bump", | ||
) | ||
|
||
IGNORE_COMMIT_PATTERNS = ( | ||
r"^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)|" | ||
r"^(Merge tag (.*?))(?:\r?\n)*$|" | ||
r"^(R|r)evert (.*)|" | ||
r"^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))$|" | ||
r"^Merge remote-tracking branch(\s*)(.*)$|" | ||
r"^Automatic merge(.*)$|" | ||
r"^Auto-merged (.*?) into (.*)$" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
""" | ||
This module contains the git related helper functions. | ||
""" | ||
|
||
import subprocess | ||
from typing import List | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"""Main module for commit linters and validators""" | ||
|
||
from ._linter import lint_commit_message | ||
|
||
__all__ = [ | ||
"lint_commit_message", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
This module provides detailed functionality for linting commit messages according | ||
to conventional commit standards. | ||
""" | ||
|
||
from typing import List, Tuple | ||
|
||
from .utils import is_ignored, remove_comments | ||
from .validators import ( | ||
HeaderLengthValidator, | ||
PatternValidator, | ||
QuickPatternValidator, | ||
run_validators, | ||
) | ||
|
||
|
||
def lint_commit_message( | ||
commit_message: str, quick: bool = False | ||
) -> Tuple[bool, List[str]]: | ||
""" | ||
Lints a commit message. | ||
Args: | ||
commit_message (str): The commit message to be linted. | ||
quick (bool, optional): Whether to perform a quick linting (default is False). | ||
Returns: | ||
Tuple[bool, List[str]]: Returns success as a first element and list of errors | ||
on the second elements. If success is true, errors will be empty. | ||
""" | ||
|
||
# perform processing and pre checks | ||
# removing unnecessary commit comments | ||
commit_message = remove_comments(commit_message) | ||
|
||
# checking if commit message should be ignored | ||
if is_ignored(commit_message): | ||
return True, [] | ||
|
||
# for quick check | ||
if quick: | ||
return run_validators( | ||
commit_message, | ||
validator_classes=[HeaderLengthValidator, QuickPatternValidator], | ||
fail_fast=True, | ||
) | ||
|
||
return run_validators( | ||
commit_message, validator_classes=[HeaderLengthValidator, PatternValidator] | ||
) |
Oops, something went wrong.