lib/danger/request_sources/github/github.rb in danger-9.4.2 vs lib/danger/request_sources/github/github.rb in danger-9.4.3
- old
+ new
@@ -250,25 +250,38 @@
client.delete_comment(ci_source.repo_slug, comment.id)
end
end
def submit_inline_comments!(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: [], danger_id: "danger")
- # Avoid doing any fetchs if there's no inline comments
- return {} if (warnings + errors + messages + markdowns).select(&:inline?).empty?
-
- diff_lines = self.pr_diff.lines
pr_comments = client.pull_request_comments(ci_source.repo_slug, ci_source.pull_request_id)
danger_comments = pr_comments.select { |comment| Comment.from_github(comment).generated_by_danger?(danger_id) }
non_danger_comments = pr_comments - danger_comments
+ if (warnings + errors + messages + markdowns).select(&:inline?).empty?
+ delete_old_inline_violations(danger_comments: danger_comments, non_danger_comments: non_danger_comments)
+ return {}
+ end
+
+ diff_lines = self.pr_diff.lines
warnings = submit_inline_comments_for_kind!(:warning, warnings, diff_lines, danger_comments, previous_violations["warning"], danger_id: danger_id)
errors = submit_inline_comments_for_kind!(:error, errors, diff_lines, danger_comments, previous_violations["error"], danger_id: danger_id)
messages = submit_inline_comments_for_kind!(:message, messages, diff_lines, danger_comments, previous_violations["message"], danger_id: danger_id)
markdowns = submit_inline_comments_for_kind!(:markdown, markdowns, diff_lines, danger_comments, [], danger_id: danger_id)
# submit removes from the array all comments that are still in force
# so we strike out all remaining ones
+ delete_old_inline_violations(danger_comments: danger_comments, non_danger_comments: non_danger_comments)
+
+ {
+ warnings: warnings,
+ errors: errors,
+ messages: messages,
+ markdowns: markdowns
+ }
+ end
+
+ def delete_old_inline_violations(danger_comments: [], non_danger_comments: [])
danger_comments.each do |comment|
violation = violations_from_table(comment["body"]).first
if !violation.nil? && violation.sticky
body = generate_inline_comment_body("white_check_mark", violation, danger_id: danger_id, resolved: true, template: "github")
client.update_pull_request_comment(ci_source.repo_slug, comment["id"], body)
@@ -283,17 +296,10 @@
end
client.delete_pull_request_comment(ci_source.repo_slug, comment["id"]) if replies.empty?
end
end
-
- {
- warnings: warnings,
- errors: errors,
- messages: messages,
- markdowns: markdowns
- }
end
def messages_are_equivalent(m1, m2)
blob_regexp = %r{blob/[0-9a-z]+/}
m1.file == m2.file && m1.line == m2.line &&
@@ -341,11 +347,13 @@
end
end
if matching_comments.empty?
begin
+ # Since Octokit v8, the signature of create_pull_request_comment has been changed.
+ # See https://github.com/danger/danger/issues/1475 for detailed information.
client.create_pull_request_comment(ci_source.repo_slug, ci_source.pull_request_id,
- body, head_ref, m.file, position)
+ body, head_ref, m.file, (Octokit::MAJOR >= 8 ? m.line : position))
rescue Octokit::UnprocessableEntity => e
# Show more detail for UnprocessableEntity error
message = [e, "body: #{body}", "head_ref: #{head_ref}", "filename: #{m.file}", "position: #{position}"].join("\n")
puts message