Module: Danger::Helpers::CommentsParsingHelper
- Included in:
- CommentsHelper
- Defined in:
- lib/danger/helpers/comments_parsing_helper.rb
Extension points collapse
-
#parse_message_from_row(row) ⇒ Violation or Markdown
Produces a message-like from a row in a comment table.
Instance Method Summary collapse
- #parse_comment(comment) ⇒ Object
- #parse_tables_from_comment(comment) ⇒ Object
- #table_kind_from_title(title) ⇒ Object
- #violations_from_table(table) ⇒ Object
Instance Method Details
#parse_comment(comment) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 30 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
Produces a message-like from a row in a comment table
13 14 15 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 13 def (row) Violation.new(row, true) end |
#parse_tables_from_comment(comment) ⇒ Object
19 20 21 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 19 def parse_tables_from_comment(comment) comment.split("</table>") end |
#table_kind_from_title(title) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 47 def table_kind_from_title(title) case title when /error/i :error when /warning/i :warning when /message/i :message end end |
#violations_from_table(table) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/danger/helpers/comments_parsing_helper.rb', line 23 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 |