Class: MessageParser
- Inherits:
-
Object
- Object
- MessageParser
- Defined in:
- lib/message_parser.rb
Class Method Summary collapse
- .already_in_jira?(msg, msg_regex) ⇒ Boolean
- .commit_summary_and_body(message) ⇒ Object
- .listify_components(value) ⇒ Object
- .message ⇒ Object
- .parse(message) ⇒ Object
- .split_keys(message) ⇒ Object
Class Method Details
.already_in_jira?(msg, msg_regex) ⇒ Boolean
57 58 59 |
# File 'lib/message_parser.rb', line 57 def self.already_in_jira?( msg, msg_regex ) !!msg.match(msg_regex) end |
.commit_summary_and_body(message) ⇒ Object
27 28 29 30 |
# File 'lib/message_parser.rb', line 27 def self.commit_summary_and_body( ) = .split("\n") return .first.to_s, ([1..-1]).join("\n").split(/jira:/).first.to_s end |
.listify_components(value) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/message_parser.rb', line 38 def self.listify_components( value ) return [] if value.length == 0 value.split(',').map do | component_name | {:name => component_name.to_s} end end |
.message ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/message_parser.rb', line 61 def self. <<-eos this is the example commit message blah blah blah blah blah jira: components#Assignments sprint#15 Change-Id: 982374ujalskdfj eos end |
.parse(message) ⇒ Object
32 33 34 35 36 |
# File 'lib/message_parser.rb', line 32 def self.parse( ) summary, body = commit_summary_and_body( ) fields = split_keys (.split /jira:/).last.to_s.split( /Change-Id/ ).first.to_s.strip Message.new( summary, body, fields ) end |
.split_keys(message) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/message_parser.rb', line 45 def self.split_keys( ) .split( "\n" ).inject({}) do | memo, line | key, value = line.split( ":" ) key = key.to_s.strip.downcase; value = value.to_s.strip if key == 'components' value = listify_components value end memo[key] = value memo end end |