Class: Danger::RequestSources::BitbucketCloudAPI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_slug, pull_request_id, branch_name, environment) ⇒ BitbucketCloudAPI

Returns a new instance of BitbucketCloudAPI.



10
11
12
13
14
15
16
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 10

def initialize(repo_slug, pull_request_id, branch_name, environment)
  @username = environment["DANGER_BITBUCKETCLOUD_USERNAME"]
  @password = environment["DANGER_BITBUCKETCLOUD_PASSWORD"]
  self.project, self.slug = repo_slug.split("/")
  self.pull_request_id = pull_request_id || fetch_pr_from_branch(branch_name)
  self.host = "https://bitbucket.org/"
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8

def host
  @host
end

#projectObject

Returns the value of attribute project.



8
9
10
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8

def project
  @project
end

#pull_request_idObject

Returns the value of attribute pull_request_id.



8
9
10
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8

def pull_request_id
  @pull_request_id
end

#slugObject

Returns the value of attribute slug.



8
9
10
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8

def slug
  @slug
end

Instance Method Details

#credentials_given?Boolean

Returns:

  • (Boolean)


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

def credentials_given?
  @username && !@username.empty? && @password && !@password.empty?
end

#delete_comment(id) ⇒ Object



46
47
48
49
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 46

def delete_comment(id)
  uri = URI("#{pr_api_endpoint_v1}/comments/#{id}")
  delete(uri)
end

#fetch_last_commentsObject



41
42
43
44
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 41

def fetch_last_comments
  uri = URI("#{pr_api_endpoint}/activity?limit=1000")
  fetch_json(uri)[:values].select { |v| v[:comment] }.map { |v| v[:comment] }
end

#fetch_pr_jsonObject



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

def fetch_pr_json
  uri = URI(pr_api_endpoint)
  fetch_json(uri)
end

#inspectObject



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

def inspect
  inspected = super

  if @password
    inspected = inspected.sub! @password, "********".freeze
  end

  inspected
end

#post_comment(text) ⇒ Object



51
52
53
54
55
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 51

def post_comment(text)
  uri = URI("#{pr_api_endpoint_v1}/comments")
  body = { content: text }.to_json
  post(uri, body)
end

#pull_requestObject



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

def pull_request(*)
  fetch_pr_json
end