Class: Danger::RequestSources::GitHubSource::Review

Inherits:
Object
  • Object
show all
Includes:
Helpers::CommentsHelper
Defined in:
lib/danger/request_sources/github/github_review.rb

Constant Summary collapse

EVENT_APPROVE =
"APPROVE".freeze
EVENT_REQUEST_CHANGES =
"REQUEST_CHANGES".freeze
EVENT_COMMENT =
"COMMENT".freeze
STATUS_APPROVED =

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

"APPROVED".freeze
STATUS_REQUESTED_CHANGES =
"CHANGES_REQUESTED".freeze
STATUS_COMMENTED =
"COMMENTED".freeze
STATUS_PENDING =
"PENDING".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CommentsHelper

#apply_template, #generate_comment, #generate_description, #generate_inline_comment_body, #generate_inline_markdown_body, #markdown_link_to_message, #markdown_parser, #messages_are_equivalent, #process_markdown, #random_compliment, #table

Methods included from Helpers::CommentsParsingHelper

#parse_comment, #parse_message_from_row, #parse_tables_from_comment, #table_kind_from_title, #violations_from_table

Constructor Details

#initialize(client, ci_source, review_json = nil) ⇒ Review

Returns a new instance of Review.



30
31
32
33
34
# File 'lib/danger/request_sources/github/github_review.rb', line 30

def initialize(client, ci_source, review_json = nil)
  @ci_source = ci_source
  @client = client
  @review_json = review_json
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



28
29
30
# File 'lib/danger/request_sources/github/github_review.rb', line 28

def body
  @body
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/danger/request_sources/github/github_review.rb', line 28

def id
  @id
end

#review_jsonObject (readonly)

Returns the value of attribute review_json.



28
29
30
# File 'lib/danger/request_sources/github/github_review.rb', line 28

def review_json
  @review_json
end

#statusObject (readonly)

Returns the value of attribute status.



28
29
30
# File 'lib/danger/request_sources/github/github_review.rb', line 28

def status
  @status
end

Instance Method Details

#fail(message, sticky = true, file = nil, line = nil) ⇒ Object



82
83
84
# File 'lib/danger/request_sources/github/github_review.rb', line 82

def fail(message, sticky = true, file = nil, line = nil)
  @errors << Violation.new(message, sticky, file, line)
end

#generated_by_danger?(danger_id = "danger") ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/danger/request_sources/github/github_review.rb', line 70

def generated_by_danger?(danger_id = "danger")
  self.review_json["body"].include?("generated_by_#{danger_id}")
end

#markdown(message, file = nil, line = nil) ⇒ Object



86
87
88
# File 'lib/danger/request_sources/github/github_review.rb', line 86

def markdown(message, file = nil, line = nil)
  @markdowns << Markdown.new(message, file, line)
end

#message(message, sticky = true, file = nil, line = nil) ⇒ Object



74
75
76
# File 'lib/danger/request_sources/github/github_review.rb', line 74

def message(message, sticky = true, file = nil, line = nil)
  @messages << Violation.new(message, sticky, file, line)
end

#startObject

Starts the new review process



52
53
54
55
56
57
# File 'lib/danger/request_sources/github/github_review.rb', line 52

def start
  @warnings = []
  @errors = []
  @messages = []
  @markdowns = []
end

#submitObject

Submits the prepared review



60
61
62
63
64
65
66
67
68
# File 'lib/danger/request_sources/github/github_review.rb', line 60

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) ⇒ Object



78
79
80
# File 'lib/danger/request_sources/github/github_review.rb', line 78

def warn(message, sticky = true, file = nil, line = nil)
  @warnings << Violation.new(message, sticky, file, line)
end