lib/danger/request_sources/github/github.rb in danger-4.2.1 vs lib/danger/request_sources/github/github.rb in danger-4.2.2

- old
+ new

@@ -1,11 +1,12 @@ # coding: utf-8 require "octokit" require "danger/helpers/comments_helper" require "danger/helpers/comment" require "danger/request_sources/github/github_review" -require "danger/request_sources/github/octokit_pr_review.rb" +require "danger/request_sources/github/github_review_unsupported" +require "danger/request_sources/github/octokit_pr_review" require "danger/request_sources/support/get_ignored_violation" module Danger module RequestSources class GitHub < RequestSource @@ -64,16 +65,21 @@ @pr_diff ||= client.pull_request(ci_source.repo_slug, ci_source.pull_request_id, accept: "application/vnd.github.v3.diff") end def review return @review unless @review.nil? - @review = client.pull_request_reviews(ci_source.repo_slug, ci_source.pull_request_id) - .map { |review_json| Danger::RequestSources::GitHubSource::Review.new(client, ci_source, review_json) } - .select(&:generated_by_danger?) - .last - @review ||= Danger::RequestSources::GitHubSource::Review.new(client, ci_source) - @review + begin + @review = client.pull_request_reviews(ci_source.repo_slug, ci_source.pull_request_id) + .map { |review_json| Danger::RequestSources::GitHubSource::Review.new(client, ci_source, review_json) } + .select(&:generated_by_danger?) + .last + @review ||= Danger::RequestSources::GitHubSource::Review.new(client, ci_source) + @review + rescue Octokit::NotFound + @review = Danger::RequestSources::GitHubSource::ReviewUnsupported.new + @review + end end def setup_danger_branches # we can use a github specific feature here: base_commit = self.pr_json["base"]["sha"] @@ -228,10 +234,10 @@ # Avoid doing any fetchs if there's no inline comments return if (warnings + errors + messages).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["body"].include?("generated_by_#{danger_id}") } + danger_comments = pr_comments.select { |comment| Comment.from_github(comment).generated_by_danger?(danger_id) } non_danger_comments = pr_comments - danger_comments submit_inline_comments_for_kind!("warning", warnings, diff_lines, danger_comments, previous_violations["warning"], danger_id: danger_id) submit_inline_comments_for_kind!("no_entry_sign", errors, diff_lines, danger_comments, previous_violations["error"], danger_id: danger_id) submit_inline_comments_for_kind!("book", messages, diff_lines, danger_comments, previous_violations["message"], danger_id: danger_id)