class Danger::RequestSources::GitHubSource::Review

Constants

EVENT_APPROVE

@see developer.github.com/v3/pulls/reviews/ for all possible events

EVENT_COMMENT
EVENT_REQUEST_CHANGES
STATUS_APPROVED

Current review status, if the review has not been submitted yet -> STATUS_PENDING

STATUS_COMMENTED
STATUS_PENDING
STATUS_REQUESTED_CHANGES

Attributes

body[R]
id[R]
review_json[R]
status[R]

Public Class Methods

new(client, ci_source, review_json = nil) click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 28
def initialize(client, ci_source, review_json = nil)
  @ci_source = ci_source
  @client = client
  @review_json = review_json
end

Public Instance Methods

fail(message, sticky = true, file = nil, line = nil) click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 83
def fail(message, sticky = true, file = nil, line = nil)
  @errors << Violation.new(message, sticky, file, line)
end
generated_by_danger?(danger_id = "danger") click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 71
def generated_by_danger?(danger_id = "danger")
  self.review_json["body"].include?("generated_by_#{danger_id}")
end
markdown(message, file = nil, line = nil) click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 87
def markdown(message, file = nil, line = nil)
  @markdowns << Markdown.new(message, file, line)
end
message(message, sticky = true, file = nil, line = nil) click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 75
def message(message, sticky = true, file = nil, line = nil)
  @messages << Violation.new(message, sticky, file, line)
end
start() click to toggle source

Starts the new review process

# File lib/danger/request_sources/github/github_review.rb, line 53
def start
  @warnings = []
  @errors = []
  @messages = []
  @markdowns = []
end
submit() click to toggle source

Submits the prepared review

# File lib/danger/request_sources/github/github_review.rb, line 61
def submit
  general_violations = generate_general_violations
  submission_body = generate_body

  # If the review resolver says that there is nothing to submit we skip submission
  return unless ReviewResolver.should_submit?(self, submission_body)

  @review_json = @client.create_pull_request_review(@ci_source.repo_slug, @ci_source.pull_request_id, event: generate_event(general_violations), body: submission_body)
end
warn(message, sticky = true, file = nil, line = nil) click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 79
def warn(message, sticky = true, file = nil, line = nil)
  @warnings << Violation.new(message, sticky, file, line)
end

Private Instance Methods

generate_body(danger_id: "danger") click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 99
def generate_body(danger_id: "danger")
  previous_violations = parse_comment(body)
  general_violations = generate_general_violations
  new_body = generate_comment(warnings: general_violations[:warnings],
                              errors: general_violations[:errors],
                              messages: general_violations[:messages],
                              markdowns: general_violations[:markdowns],
                              previous_violations: previous_violations,
                              danger_id: danger_id,
                              template: "github")
  return new_body
end
generate_event(violations) click to toggle source

The only reason to request changes for the PR is to have errors from Danger otherwise let’s just notify user and we’re done

# File lib/danger/request_sources/github/github_review.rb, line 95
def generate_event(violations)
  violations[:errors].empty? ? EVENT_APPROVE : EVENT_REQUEST_CHANGES
end
generate_general_violations() click to toggle source
# File lib/danger/request_sources/github/github_review.rb, line 112
def generate_general_violations
  general_warnings = @warnings.reject(&:inline?)
  general_errors = @errors.reject(&:inline?)
  general_messages = @messages.reject(&:inline?)
  general_markdowns = @markdowns.reject(&:inline?)
  {
    warnings: general_warnings,
    markdowns: general_markdowns,
    errors: general_errors,
    messages: general_messages
  }
end