Class: Renegade::CommitMessage
- Inherits:
-
Object
- Object
- Renegade::CommitMessage
- Defined in:
- lib/renegade/commit_message.rb
Overview
Check commit messages meet certain criteria
Constant Summary collapse
- COMMIT_FORMAT =
/^(?:(?:BugId: |Story: B+-|Epic: E-0)[1-9]\d* \| )(.*)/
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#check_commit_message_format(message) ⇒ Object
Check commit message contains no non-ASCII characters.
- #check_commit_message_format_error ⇒ Object
-
#check_commit_message_length(message) ⇒ Object
Check message length.
-
#check_commit_message_non_ascii(message) ⇒ Object
Check commit message contains no non-ASCII characters.
-
#initialize ⇒ CommitMessage
constructor
A new instance of CommitMessage.
- #run(message) ⇒ Object
Constructor Details
#initialize ⇒ CommitMessage
Returns a new instance of CommitMessage.
10 11 12 13 14 15 16 17 |
# File 'lib/renegade/commit_message.rb', line 10 def initialize # Instance variables @warnings = [] @errors = [] @min_length = 7 @max_length = 50 end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/renegade/commit_message.rb', line 6 def errors @errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
6 7 8 |
# File 'lib/renegade/commit_message.rb', line 6 def warnings @warnings end |
Instance Method Details
#check_commit_message_format(message) ⇒ Object
Check commit message contains no non-ASCII characters
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/renegade/commit_message.rb', line 58 def () check_label = 'Includes a valid BugId, Story or Epic number' matches = COMMIT_FORMAT.match() if matches Status.report(check_label, true) (matches[1]) else Status.report(check_label, false) () @errors.push() end end |
#check_commit_message_format_error ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/renegade/commit_message.rb', line 49 def "You must include a valid BugId, Story or Epic number.\n"\ " Examples:\n"\ " - BugId: 12345 | Helpful comment describing bug fix\n"\ " - Story: B-12345 | Helpful comment describing story\n"\ ' - Epic: E-12345 | Epic comment' end |
#check_commit_message_length(message) ⇒ Object
Check message length
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/renegade/commit_message.rb', line 25 def () check_label = 'Commit message length' if .length >= @min_length && .length <= @max_length Status.report(check_label, true) else @errors.push "Commit messages should be between #{@min_length} "\ "and #{@max_length} characters." Status.report(check_label, false) end end |
#check_commit_message_non_ascii(message) ⇒ Object
Check commit message contains no non-ASCII characters
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/renegade/commit_message.rb', line 38 def () check_label = 'Only ASCII characters' if .ascii_only? Status.report(check_label, true) else Status.report(check_label, false) @errors.push('Commit messages may not contain non-ASCII characters') end end |
#run(message) ⇒ Object
19 20 21 22 |
# File 'lib/renegade/commit_message.rb', line 19 def run() () () end |