Class: Danger::RequestSources::BitbucketCloudAPI
- Inherits:
-
Object
- Object
- Danger::RequestSources::BitbucketCloudAPI
- Defined in:
- lib/danger/request_sources/bitbucket_cloud_api.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#host ⇒ Object
Returns the value of attribute host.
-
#my_uuid ⇒ Object
readonly
Returns the value of attribute my_uuid.
-
#project ⇒ Object
Returns the value of attribute project.
-
#pull_request_id ⇒ Object
Returns the value of attribute pull_request_id.
-
#slug ⇒ Object
Returns the value of attribute slug.
Instance Method Summary collapse
- #credentials_given? ⇒ Boolean
- #delete_comment(id) ⇒ Object
- #fetch_comments ⇒ Object
- #fetch_pr_json ⇒ Object
-
#initialize(repo_slug, pull_request_id, branch_name, environment) ⇒ BitbucketCloudAPI
constructor
A new instance of BitbucketCloudAPI.
- #initialize_my_uuid(uuid) ⇒ Object
- #inspect ⇒ Object
- #post_comment(text, file: nil, line: nil) ⇒ Object
- #pull_request ⇒ Object
Constructor Details
#initialize(repo_slug, pull_request_id, branch_name, environment) ⇒ BitbucketCloudAPI
Returns a new instance of BitbucketCloudAPI.
11 12 13 14 15 16 17 18 19 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 11 def initialize(repo_slug, pull_request_id, branch_name, environment) initialize_my_uuid(environment["DANGER_BITBUCKETCLOUD_UUID"]) @username = environment["DANGER_BITBUCKETCLOUD_USERNAME"] @password = environment["DANGER_BITBUCKETCLOUD_PASSWORD"] self.project, self.slug = repo_slug.split("/") self.access_token = fetch_access_token(environment) self.pull_request_id = pull_request_id || fetch_pr_from_branch(branch_name) self.host = "https://bitbucket.org/" end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 8 def access_token @access_token end |
#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 |
#my_uuid ⇒ Object (readonly)
Returns the value of attribute my_uuid.
9 10 11 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 9 def my_uuid @my_uuid end |
#project ⇒ Object
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_id ⇒ Object
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 |
#slug ⇒ Object
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
41 42 43 44 45 46 47 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 41 def credentials_given? return true if @access_token @my_uuid && !@my_uuid.empty? && @username && !@username.empty? && @password && !@password.empty? end |
#delete_comment(id) ⇒ Object
72 73 74 75 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 72 def delete_comment(id) uri = URI("#{pr_api_endpoint}/comments/#{id}") delete(uri) end |
#fetch_comments ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 58 def fetch_comments values = [] # TODO: use a url parts encoder to encode the query corrected_uuid = @my_uuid[1...-1] unless @my_uuid.nil? # Endpoint doesnt support curly brackets for this, so remove them for this uri = "#{pr_api_endpoint}/comments?pagelen=100&q=deleted+%7E+false+AND+user.uuid+%7E+%22#{corrected_uuid}%22" while uri json = fetch_json(URI(uri)) values += json[:values] uri = json[:next] end values end |
#fetch_pr_json ⇒ Object
53 54 55 56 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 53 def fetch_pr_json uri = URI(pr_api_endpoint) fetch_json(uri) end |
#initialize_my_uuid(uuid) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 21 def initialize_my_uuid(uuid) return if uuid.nil? return @my_uuid = uuid if uuid.empty? if uuid.start_with?("{") && uuid.end_with?("}") @my_uuid = uuid else @my_uuid = "{#{uuid}}" end end |
#inspect ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 32 def inspect inspected = super inspected.gsub!(@password, "********") if @password inspected.gsub!(@access_token, "********") if @access_token inspected end |
#post_comment(text, file: nil, line: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 77 def post_comment(text, file: nil, line: nil) uri = URI("#{pr_api_endpoint}/comments") body = { content: { raw: text } } body.merge!(inline: { path: file, to: line }) if file && line post(uri, body.to_json) end |
#pull_request ⇒ Object
49 50 51 |
# File 'lib/danger/request_sources/bitbucket_cloud_api.rb', line 49 def pull_request(*) fetch_pr_json end |