Module: Danger::Helpers::CommentsParsingHelper
- Included in:
- CommentsHelper
- Defined in:
- lib/danger/helpers/comments_parsing_helper.rb
Instance Method Summary collapse
- #parse_comment(comment) ⇒ Object
-
#parse_message_from_row(row) ⇒ Violation or Markdown
!@group Extension points Produces a message-like from a row in a comment table.
- #parse_tables_from_comment(comment) ⇒ Object
- #table_kind_from_title(title) ⇒ Object
- #violations_from_table(table) ⇒ Object
Instance Method Details
#parse_comment(comment) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 26 def parse_comment(comment) tables = parse_tables_from_comment(comment) violations = {} tables.each do |table| match = danger_table?(table) next unless match title = match[1] kind = table_kind_from_title(title) next unless kind violations[kind] = violations_from_table(table) end violations.reject { |_, v| v.empty? } end |
#parse_message_from_row(row) ⇒ Violation or Markdown
!@group Extension points Produces a message-like from a row in a comment table
11 12 13 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 11 def (row) Violation.new(row, true) end |
#parse_tables_from_comment(comment) ⇒ Object
15 16 17 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 15 def parse_tables_from_comment(comment) comment.split("</table>") end |
#table_kind_from_title(title) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 42 def table_kind_from_title(title) if title =~ /error/i :error elsif title =~ /warning/i :warning elsif title =~ /message/i :message end end |
#violations_from_table(table) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 19 def violations_from_table(table) row_regex = %r{<td data-sticky="true">(?:<del>)?(.*?)(?:</del>)?\s*</td>}im table.scan(row_regex).flatten.map do |row| (row.strip) end end |