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



28
29
30
31
32
# 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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



26
27
28
# File 'lib/danger/request_sources/github/github_review.rb', line 26

def body
  @body
end

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'lib/danger/request_sources/github/github_review.rb', line 26

def id
  @id
end

#review_jsonObject (readonly)

Returns the value of attribute review_json.



26
27
28
# File 'lib/danger/request_sources/github/github_review.rb', line 26

def review_json
  @review_json
end

#statusObject (readonly)

Returns the value of attribute status.



26
27
28
# File 'lib/danger/request_sources/github/github_review.rb', line 26

def status
  @status
end

Instance Method Details

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



83
84
85
# 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") ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# 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) ⇒ Object



87
88
89
# 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) ⇒ Object



75
76
77
# 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

#startObject

Starts the new review process



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

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

#submitObject

Submits the prepared review



61
62
63
64
65
66
67
68
69
# 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) ⇒ Object



79
80
81
# 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