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"
EVENT_REQUEST_CHANGES =
"REQUEST_CHANGES"
EVENT_COMMENT =
"COMMENT"
STATUS_APPROVED =

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

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

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, #generate_message_group_comment, #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



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

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)


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

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

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



89
90
91
# File 'lib/danger/request_sources/github/github_review.rb', line 89

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

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



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

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

#startObject

Starts the new review process



55
56
57
58
59
60
# File 'lib/danger/request_sources/github/github_review.rb', line 55

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

#submitObject

Submits the prepared review



63
64
65
66
67
68
69
70
71
# File 'lib/danger/request_sources/github/github_review.rb', line 63

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



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

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