Class: GitAuto::Validators::CommitMessageValidator
- Inherits:
-
Object
- Object
- GitAuto::Validators::CommitMessageValidator
- Defined in:
- lib/git_auto/validators/commit_message_validator.rb
Constant Summary collapse
- HEADER_MAX_LENGTH =
72
- TYPES =
Conventional commit types and their descriptions
{ "feat" => "A new feature", "fix" => "A bug fix", "docs" => "Documentation only changes", "style" => "Changes that do not affect the meaning of the code", "refactor" => "A code change that neither fixes a bug nor adds a feature", "test" => "Adding missing tests or correcting existing tests", "chore" => "Changes to the build process or auxiliary tools", "perf" => "A code change that improves performance", "ci" => "Changes to CI configuration files and scripts", "build" => "Changes that affect the build system or external dependencies", "revert" => "Reverts a previous commit" }.freeze
- MINIMAL_COMMIT_PATTERN =
/ ^(?<type>#{TYPES.keys.join("|")}) # Commit type :\s # Colon and space separator (?<description>.+) # Commit description /x
- CONVENTIONAL_COMMIT_PATTERN =
%r{ ^(?<type>#{TYPES.keys.join("|")}) # Commit type (\((?<scope>[a-z0-9/_-]+)\))? # Optional scope in parentheses :\s # Colon and space separator (?<description>.+) # Commit description }x
Instance Method Summary collapse
- #format_error(error) ⇒ Object
- #format_warning(warning) ⇒ Object
- #valid?(message) ⇒ Boolean
- #validate(message) ⇒ Object
Instance Method Details
#format_error(error) ⇒ Object
55 56 57 |
# File 'lib/git_auto/validators/commit_message_validator.rb', line 55 def format_error(error) "❌ #{error}".red end |
#format_warning(warning) ⇒ Object
59 60 61 |
# File 'lib/git_auto/validators/commit_message_validator.rb', line 59 def format_warning(warning) "⚠️ #{warning}".yellow end |
#valid?(message) ⇒ Boolean
50 51 52 53 |
# File 'lib/git_auto/validators/commit_message_validator.rb', line 50 def valid?() result = validate() result[:errors].empty? end |
#validate(message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/git_auto/validators/commit_message_validator.rb', line 36 def validate() errors = [] warnings = [] # Skip validation if message is empty return { errors: ["Commit message cannot be empty"], warnings: [] } if .nil? || .strip.empty? header_result = validate_header() errors.concat(header_result[:errors]) warnings.concat(header_result[:warnings]) { errors: errors, warnings: warnings } end |