Class: Danger::RequestSources::BitbucketCloudAPI
- Inherits:
-
Object
- Object
- Danger::RequestSources::BitbucketCloudAPI
- Defined in:
- lib/danger/request_sources/bitbucket_cloud_api.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
-
#pr_api_endpoint_v1 ⇒ Object
Returns the value of attribute pr_api_endpoint_v1.
Instance Method Summary collapse
- #credentials_given? ⇒ Boolean
- #delete_comment(id) ⇒ Object
- #fetch_last_comments ⇒ Object
- #fetch_pr_json ⇒ Object
-
#initialize(project, slug, pull_request_id, environment) ⇒ BitbucketCloudAPI
constructor
A new instance of BitbucketCloudAPI.
- #inspect ⇒ Object
- #post_comment(text) ⇒ Object
Constructor Details
#initialize(project, slug, pull_request_id, environment) ⇒ BitbucketCloudAPI
Returns a new instance of BitbucketCloudAPI.
10 11 12 13 14 15 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 10 def initialize(project, slug, pull_request_id, environment) @username = environment["DANGER_BITBUCKETCLOUD_USERNAME"] @password = environment["DANGER_BITBUCKETCLOUD_PASSWORD"] self.pr_api_endpoint = "https://api.bitbucket.org/2.0/repositories/#{project}/#{slug}/pullrequests/#{pull_request_id}" self.pr_api_endpoint_v1 = "https://api.bitbucket.org/1.0/repositories/#{project}/#{slug}/pullrequests/#{pull_request_id}" end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8 def host @host end |
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
8 9 10 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8 def pr_api_endpoint @pr_api_endpoint end |
#pr_api_endpoint_v1 ⇒ Object
Returns the value of attribute pr_api_endpoint_v1.
8 9 10 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8 def pr_api_endpoint_v1 @pr_api_endpoint_v1 end |
Instance Method Details
#credentials_given? ⇒ Boolean
27 28 29 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 27 def credentials_given? @username && !@username.empty? && @password && !@password.empty? end |
#delete_comment(id) ⇒ Object
41 42 43 44 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 41 def delete_comment(id) uri = URI("#{pr_api_endpoint_v1}/comments/#{id}") delete(uri) end |
#fetch_last_comments ⇒ Object
36 37 38 39 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 36 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_json ⇒ Object
31 32 33 34 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 31 def fetch_pr_json uri = URI(pr_api_endpoint) fetch_json(uri) end |
#inspect ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 17 def inspect inspected = super if @password inspected = inspected.sub! @password, "********".freeze end inspected end |
#post_comment(text) ⇒ Object
46 47 48 49 50 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 46 def post_comment(text) uri = URI("#{pr_api_endpoint_v1}/comments") body = { content: text }.to_json post(uri, body) end |