Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ commit_check.egg-info
__pycache__
.mypy_cache
.vscode
*.swp
venv
.venv
UNKNOWN.egg-info
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ For one-off checks or CI/CD pipelines, you can configure via CLI arguments or en
args:
- --subject-imperative=false
- --subject-max-length=100
- id: check-author-name
args:
- --no-banner
- --author-name
- --author-name-pattern=^[A-Z]+[-a-zA-Z0-9]+ [A-Z]+[-a-zA-Z0-9]+$

See the `Configuration documentation <https://commit-check.github.io/commit-check/configuration.html>`_ for all available options.

Expand Down
6 changes: 6 additions & 0 deletions commit_check/config_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def get_default_config() -> dict[str, Any]:
"require_signed_off_by": DEFAULT_BOOLEAN_RULES["require_signed_off_by"],
"ignore_authors": [],
"ai_attribution": DEFAULT_AI_ATTRIBUTION,
"author_email_pattern": "^.+@.+$",
"author_name_pattern": "",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
"branch": {
"conventional_branch": True,
Expand Down Expand Up @@ -123,6 +125,8 @@ class ConfigMerger:
"CCHK_REQUIRE_SIGNED_OFF_BY": ("commit", "require_signed_off_by", parse_bool),
"CCHK_IGNORE_AUTHORS": ("commit", "ignore_authors", parse_list),
"CCHK_AI_ATTRIBUTION": ("commit", "ai_attribution", str),
"CCHK_AUTHOR_EMAIL_PATTERN": ("commit", "author_email_pattern", str),
"CCHK_AUTHOR_NAME_PATTERN": ("commit", "author_name_pattern", str),
# Branch section
"CCHK_CONVENTIONAL_BRANCH": ("branch", "conventional_branch", parse_bool),
"CCHK_ALLOW_BRANCH_TYPES": ("branch", "allow_branch_types", parse_list),
Expand Down Expand Up @@ -151,6 +155,8 @@ class ConfigMerger:
"require_signed_off_by": ("commit", "require_signed_off_by"),
"ignore_authors": ("commit", "ignore_authors"),
"ai_attribution": ("commit", "ai_attribution"),
"author_email_pattern": ("commit", "author_email_pattern"),
"author_name_pattern": ("commit", "author_name_pattern"),
# Branch section
"conventional_branch": ("branch", "conventional_branch"),
"allow_branch_types": ("branch", "allow_branch_types"),
Expand Down
14 changes: 14 additions & 0 deletions commit_check/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ def _get_parser() -> argparse.ArgumentParser:
"'forbid' rejects commits with known AI tool signatures.",
)

commit_group.add_argument(
"--author-email-pattern",
type=str,
default=None,
help="regex to check author email",
)

commit_group.add_argument(
"--author-name-pattern",
type=str,
default=None,
help="regex to check author name",
)

# Branch configuration options
branch_group = parser.add_argument_group(
"branch options", "Configuration options for --branch validation"
Expand Down
21 changes: 21 additions & 0 deletions commit_check/rule_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def _build_single_rule(
return self._build_author_list_rule(catalog_entry, "ignore_authors")
elif check == "ai_attribution":
return self._build_ai_attribution_rule(catalog_entry)
elif check == "author_email":
return self._build_author_pattern_rule(
catalog_entry, "author_email_pattern"
)
elif check == "author_name":
return self._build_author_pattern_rule(catalog_entry, "author_name_pattern")
elif check == "merge_base":
return self._build_merge_base_rule(catalog_entry)
else:
Expand Down Expand Up @@ -236,6 +242,21 @@ def _build_author_list_rule(
return ValidationRule(check=catalog_entry.check, ignored=author_list)
return None

def _build_author_pattern_rule(
self, catalog_entry: RuleCatalogEntry, config_key: str
) -> ValidationRule | None:
"""Build author name or email validation rule."""
regex = catalog_entry.regex
if self.commit_config.get(config_key, ""):
regex = self.commit_config.get(config_key, "").strip()

return ValidationRule(
check=catalog_entry.check,
regex=regex,
error=catalog_entry.error,
suggest=catalog_entry.suggest,
)

Comment thread
coderabbitai[bot] marked this conversation as resolved.
def _build_merge_base_rule(
self, catalog_entry: RuleCatalogEntry
) -> ValidationRule | None:
Expand Down
16 changes: 16 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ Configuration can also be set via environment variables with the ``CCHK_`` prefi
* - ``ignore_authors = ["bot"]``
- ``CCHK_IGNORE_AUTHORS=bot,user``
- ``--ignore-authors=bot,user``
* - ``author_email_pattern=^[-a-zA-Z0-9]*\.[-a-zA-Z0-9]*@.*$``
- ``CCHK_AUTHOR_EMAIL_PATTERN=^[-a-zA-Z0-9]*\.[-a-zA-Z0-9]*@.*$``
- ``--author-email-pattern=^[-a-zA-Z0-9]*\.[-a-zA-Z0-9]*@.*$``
* - ``author_name_pattern=^[A-Z]+[-a-zA-Z0-9]+ [A-Z]+[-a-zA-Z0-9]+$``
- ``CCHK_AUTHOR_NAME_PATTERN=^[A-Z]+[-a-zA-Z0-9]+ [A-Z]+[-a-zA-Z0-9]+$``
- ``--author-name-pattern=^[A-Z]+[-a-zA-Z0-9]+ [A-Z]+[-a-zA-Z0-9]+$``
Comment thread
coderabbitai[bot] marked this conversation as resolved.
* - ``conventional_branch = true``
- ``CCHK_CONVENTIONAL_BRANCH=true``
- ``--conventional-branch=true``
Expand Down Expand Up @@ -397,6 +403,16 @@ Options Table Description
- list[str]
- [] (none ignored)
- List of commit authors **or co-authors** (``Co-authored-by:`` lines) to bypass all commit checks. Useful for bots (e.g., ``"dependabot[bot]"``, ``"coderabbitai[bot]"``).
* - commit
- author_email_pattern
- str
- ^.+@.+$
- Custom regex pattern for author email check
* - commit
- author_name_pattern
- str
- "" (disabled)
- Custom regex pattern for author name check
* - commit
- require_signed_off_by
- bool
Expand Down
Loading