Class: Danger::GitHub

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/request_sources/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ci_source) ⇒ GitHub

Returns a new instance of GitHub.



9
10
11
# File 'lib/danger/request_sources/github.rb', line 9

def initialize(ci_source)
  self.ci_source = ci_source
end

Instance Attribute Details

#ci_sourceObject

Returns the value of attribute ci_source.



7
8
9
# File 'lib/danger/request_sources/github.rb', line 7

def ci_source
  @ci_source
end

#pr_jsonObject

Returns the value of attribute pr_json.



7
8
9
# File 'lib/danger/request_sources/github.rb', line 7

def pr_json
  @pr_json
end

Instance Method Details

#api_urlObject



13
14
15
# File 'lib/danger/request_sources/github.rb', line 13

def api_url
  "https://api.github.com/repos/#{ci_source.repo_slug}/pulls/#{ci_source.pull_request_id}"
end

#get_detailsObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/danger/request_sources/github.rb', line 17

def get_details
  response = REST.get api_url
  if response.ok?
    self.pr_json = JSON.parse(response.body)
  else
    puts "Something went wrong getting GitHub details for #{api_url} - (#{response.status_code})"
    puts response.body
    raise "Could not get the pull request details from GitHub."
  end
end

#latest_pr_commit_refObject



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

def latest_pr_commit_ref
  self.pr_json['base']['sha']
end

#pr_bodyObject



36
37
38
# File 'lib/danger/request_sources/github.rb', line 36

def pr_body
  self.pr_json['body']
end

#pr_titleObject



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

def pr_title
  self.pr_json['title']
end