-
-
Notifications
You must be signed in to change notification settings - Fork 16
fix: remove allow_authors and add ignore_authors to branch section
#292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from abc import ABC, abstractmethod | ||
| from dataclasses import dataclass | ||
| from enum import IntEnum | ||
| from dataclasses import field | ||
|
|
||
| from commit_check.rule_builder import ValidationRule | ||
| from commit_check.util import ( | ||
|
|
@@ -28,6 +29,7 @@ class ValidationContext: | |
|
|
||
| stdin_text: Optional[str] = None | ||
| commit_file: Optional[str] = None | ||
| config: Dict = field(default_factory=dict) | ||
|
|
||
|
|
||
| class BaseValidator(ABC): | ||
|
|
@@ -42,7 +44,45 @@ def validate(self, context: ValidationContext) -> ValidationResult: | |
| pass | ||
|
|
||
| def _should_skip_validation(self, context: ValidationContext) -> bool: | ||
| """Determine if validation should be skipped.""" | ||
| """ | ||
| Determine if validation should be skipped. | ||
|
|
||
| Skip only when there is no stdin_text, no commit_file, and no commits. | ||
| """ | ||
| return ( | ||
| context.stdin_text is None | ||
| and context.commit_file is None | ||
| and not has_commits() | ||
| ) | ||
|
|
||
| def _should_skip_commit_validation(self, context: ValidationContext) -> bool: | ||
| """ | ||
| Determine if commit validation should be skipped. | ||
|
|
||
| Skip if the current author is in the ignore_authors list for commits, | ||
| or if no stdin_text, no commit_file, and no commits exist. | ||
| """ | ||
| ignore_authors = context.config.get("commit", {}).get("ignore_authors", []) | ||
| current_author = get_commit_info("an") | ||
| if current_author and current_author in ignore_authors: | ||
| return True | ||
| return ( | ||
| context.stdin_text is None | ||
| and context.commit_file is None | ||
| and not has_commits() | ||
| ) | ||
|
|
||
| def _should_skip_branch_validation(self, context: ValidationContext) -> bool: | ||
| """ | ||
| Determine if branch validation should be skipped. | ||
|
|
||
| Skip if the current author is in the ignore_authors list for branches, | ||
| or if no stdin_text and no commits exist. | ||
| """ | ||
| ignore_authors = context.config.get("branch", {}).get("ignore_authors", []) | ||
| current_author = get_commit_info("an") | ||
| if current_author and current_author in ignore_authors: | ||
| return True | ||
| return context.stdin_text is None and not has_commits() | ||
|
|
||
| def _print_failure(self, actual_value: str, regex_or_constraint: str = "") -> None: | ||
|
|
@@ -58,7 +98,7 @@ class CommitMessageValidator(BaseValidator): | |
| """Validates commit messages against conventional commit standards.""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if self._should_skip_validation(context): | ||
| if self._should_skip_commit_validation(context): | ||
| return ValidationResult.PASS | ||
|
|
||
| message = self._get_commit_message(context) | ||
|
|
@@ -95,7 +135,7 @@ class SubjectValidator(BaseValidator): | |
| """Validates commit subject lines.""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if self._should_skip_validation(context): | ||
| if self._should_skip_commit_validation(context): | ||
| return ValidationResult.PASS | ||
|
|
||
| subject = self._get_subject(context) | ||
|
|
@@ -198,7 +238,8 @@ class AuthorValidator(BaseValidator): | |
| """Validates author information.""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if self._should_skip_validation(context): | ||
| # Use commit skip logic for ignore_authors | ||
| if self._should_skip_commit_validation(context): | ||
| return ValidationResult.PASS | ||
|
|
||
| author_value = self._get_author_value(context) | ||
|
|
@@ -243,6 +284,8 @@ class BranchValidator(BaseValidator): | |
| """Validates branch names.""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if self._should_skip_branch_validation(context): | ||
| return ValidationResult.PASS | ||
| branch_name = ( | ||
| context.stdin_text.strip() if context.stdin_text else get_branch_name() | ||
| ) | ||
|
|
@@ -263,7 +306,7 @@ class MergeBaseValidator(BaseValidator): | |
| """Validates merge base ancestry.""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if not has_commits(): | ||
| if self._should_skip_branch_validation(context): | ||
| return ValidationResult.PASS | ||
|
|
||
| current_branch = get_branch_name() | ||
|
|
@@ -347,7 +390,7 @@ class BodyValidator(BaseValidator): | |
| """Validates that commit messages contain a body when required.""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if self._should_skip_validation(context): | ||
| if self._should_skip_commit_validation(context): | ||
| return ValidationResult.PASS | ||
|
|
||
| message = self._get_commit_message(context) | ||
|
|
@@ -395,7 +438,7 @@ class CommitTypeValidator(BaseValidator): | |
| """Base validator for special commit types (merge, revert, fixup, WIP, empty).""" | ||
|
|
||
| def validate(self, context: ValidationContext) -> ValidationResult: | ||
| if self._should_skip_validation(context): | ||
| if self._should_skip_commit_validation(context): | ||
| return ValidationResult.PASS | ||
|
|
||
| message = self._get_commit_message(context) | ||
|
|
@@ -483,8 +526,6 @@ class ValidationEngine: | |
| "subject_min_length": SubjectLengthValidator, | ||
| "author_name": AuthorValidator, | ||
| "author_email": AuthorValidator, | ||
| "allow_authors": AuthorValidator, | ||
| "ignore_authors": AuthorValidator, | ||
| "branch": BranchValidator, | ||
| "merge_base": MergeBaseValidator, | ||
| "require_signed_off_by": SignoffValidator, | ||
|
|
@@ -494,6 +535,7 @@ class ValidationEngine: | |
| "allow_empty_commits": CommitTypeValidator, | ||
| "allow_fixup_commits": CommitTypeValidator, | ||
| "allow_wip_commits": CommitTypeValidator, | ||
| "ignore_authors": CommitTypeValidator, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify the "ignore_authors" validator mapping. This mapping suggests Run this script to check if 🏁 Script executed: #!/bin/bash
# Search for ignore_authors used as a validation check in rules
# Check rule_builder.py for ignore_authors handling
echo "=== Checking rule_builder.py for ignore_authors ==="
ast-grep --pattern $'def build_rules($$$) {
$$$
ignore_authors
$$$
}'
# Check rules_catalog.py for ignore_authors rules
echo -e "\n=== Checking rules_catalog.py for ignore_authors ==="
rg -nP --type=py 'ignore_authors.*:.*ValidationRule|ValidationRule.*ignore_authors' commit_check/rules_catalog.py
# Check TOML config for ignore_authors usage
echo -e "\n=== Checking TOML for ignore_authors ==="
rg -nP 'ignore_authors' --glob='*.toml'
# Check tests for ignore_authors as a validation rule (not config)
echo -e "\n=== Checking tests for ignore_authors as a rule check ==="
rg -nP 'ValidationRule.*check.*ignore_authors|ignore_authors.*ValidationRule' tests/Length of output: 338 Remove 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| def __init__(self, rules: List[ValidationRule]): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Branch skip logic omits commit_file check.
The method only checks
stdin_textandhas_commits()(line 86), but omitscommit_fileunlike the other skip methods. This inconsistency means branch validation may incorrectly skip when a commit message file is present.Apply this diff to align with the other skip methods:
def _should_skip_branch_validation(self, context: ValidationContext) -> bool: """ Determine if branch validation should be skipped. Skip if the current author is in the ignore_authors list for branches, - or if no stdin_text and no commits exist. + or if no stdin_text, no commit_file, and no commits exist. """ ignore_authors = context.config.get("branch", {}).get("ignore_authors", []) current_author = get_commit_info("an") if current_author and current_author in ignore_authors: return True - return context.stdin_text is None and not has_commits() + return ( + context.stdin_text is None + and context.commit_file is None + and not has_commits() + )📝 Committable suggestion
🤖 Prompt for AI Agents