Sha256: 2e2d5a0c210ea241d157cf796beb37f0cfc2d3d976a3a047b5a8b15cf703ddb7

Contents?: true

Size: 1.37 KB

Versions: 23

Compression:

Stored size: 1.37 KB

Contents

module Danger
  module Helpers
    module CommentsParsingHelper
      # !@group Extension points
      # Produces a message-like from a row in a comment table
      #
      # @param [String] row
      #        The content of the row in the table
      #
      # @return [Violation or Markdown] the extracted message
      def parse_message_from_row(row)
        Violation.new(row, true)
      end

      def parse_tables_from_comment(comment)
        comment.split("</table>")
      end

      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|
          parse_message_from_row(row.strip)
        end
      end

      def parse_comment(comment)
        tables = parse_tables_from_comment(comment)
        violations = {}
        tables.each do |table|
          next unless table =~ %r{<th width="100%"(.*?)</th>}im
          title = Regexp.last_match(1)
          kind = table_kind_from_title(title)
          next unless kind

          violations[kind] = violations_from_table(table)
        end

        violations.reject { |_, v| v.empty? }
      end

      def table_kind_from_title(title)
        if title =~ /error/i
          :error
        elsif title =~ /warning/i
          :warning
        elsif title =~ /message/i
          :message
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
danger-4.2.1 lib/danger/helpers/comments_parsing_helper.rb
danger-4.2.0 lib/danger/helpers/comments_parsing_helper.rb
danger-4.1.1 lib/danger/helpers/comments_parsing_helper.rb
danger-4.1.0 lib/danger/helpers/comments_parsing_helper.rb
danger-4.0.5 lib/danger/helpers/comments_parsing_helper.rb
danger-4.0.4 lib/danger/helpers/comments_parsing_helper.rb
danger-4.0.3 lib/danger/helpers/comments_parsing_helper.rb
danger-4.0.2 lib/danger/helpers/comments_parsing_helper.rb
danger-4.0.1 lib/danger/helpers/comments_parsing_helper.rb
danger-4.0.0 lib/danger/helpers/comments_parsing_helper.rb
danger-3.6.0 lib/danger/helpers/comments_parsing_helper.rb
danger-3.5.5 lib/danger/helpers/comments_parsing_helper.rb
danger-3.5.4 lib/danger/helpers/comments_parsing_helper.rb
danger-3.5.3 lib/danger/helpers/comments_parsing_helper.rb
danger-3.5.2 lib/danger/helpers/comments_parsing_helper.rb
danger-3.5.1 lib/danger/helpers/comments_parsing_helper.rb
danger-3.5.0 lib/danger/helpers/comments_parsing_helper.rb
danger-3.4.2 lib/danger/helpers/comments_parsing_helper.rb
danger-3.4.1 lib/danger/helpers/comments_parsing_helper.rb
danger-3.4.0 lib/danger/helpers/comments_parsing_helper.rb