Module: Saddler::Reporter::Github::Helper

Included in:
CommitComment, CommitReviewComment, PullRequestComment, PullRequestReviewComment
Defined in:
lib/saddler/reporter/github/helper.rb

Overview

Helper for saddler-reporter-github

Instance Method Summary collapse

Instance Method Details

#build_comments_with_patches(data, patches) ⇒ Array<Comment>

Build comment objects by parsed errors and patches



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/saddler/reporter/github/helper.rb', line 33

def build_comments_with_patches(data, patches)
  comments = []
  files = data.dig('checkstyle', 'file') || []
  files = [files] if files.is_a?(Hash)
  files.each do |file|
    errors = file['error'] ||= []
    errors = [file['error']] if errors.is_a?(Hash)
    file_name = file['@name'] ||= ''
    patch = patches.find_patch_by_file(file_relative_path_string(file_name))
    next unless patch

    errors.each do |error|
      line_no = error['@line'] && error['@line'].to_i
      next unless patch.changed_line_numbers.include?(line_no)

      severity = error['@severity'] && error['@severity'].upcase
      message = error['@message']
      position = patch.(line_no)

      comments << Comment.new(patch.secure_hash, [severity, message].compact.join(': '), patch.file, position)
    end
  end
  comments
end

#concat_body(data) ⇒ String

Concatenate parsed errors



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/saddler/reporter/github/helper.rb', line 11

def concat_body(data)
  buffer = []
  files = data.dig('checkstyle', 'file') || []
  files = [files] if files.is_a?(Hash)
  files.each do |file|
    errors = file['error'] ||= []
    errors = [file['error']] if errors.is_a?(Hash)
    errors.each do |error|
      severity = error['@severity'] && error['@severity'].upcase
      message = error['@message']
      buffer << [severity, message].compact.join(': ')
    end
  end
  buffer.join("\n")
end