Class: Danger::RequestSources::BitbucketServerAPI
- Inherits:
-
Object
- Object
- Danger::RequestSources::BitbucketServerAPI
- Defined in:
- lib/danger/request_sources/bitbucket_server_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.
Instance Method Summary collapse
- #credentials_given? ⇒ Boolean
- #delete_comment(id, version) ⇒ Object
- #fetch_last_comments ⇒ Object
- #fetch_pr_json ⇒ Object
-
#initialize(project, slug, pull_request_id, environment) ⇒ BitbucketServerAPI
constructor
A new instance of BitbucketServerAPI.
- #inspect ⇒ Object
- #post_comment(text) ⇒ Object
Constructor Details
#initialize(project, slug, pull_request_id, environment) ⇒ BitbucketServerAPI
Returns a new instance of BitbucketServerAPI.
9 10 11 12 13 14 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 9 def initialize(project, slug, pull_request_id, environment) @username = environment["DANGER_BITBUCKETSERVER_USERNAME"] @password = environment["DANGER_BITBUCKETSERVER_PASSWORD"] self.host = environment["DANGER_BITBUCKETSERVER_HOST"] self.pr_api_endpoint = "https://#{host}/rest/api/1.0/projects/#{project}/repos/#{slug}/pull-requests/#{pull_request_id}" end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 7 def host @host end |
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
7 8 9 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 7 def pr_api_endpoint @pr_api_endpoint end |
Instance Method Details
#credentials_given? ⇒ Boolean
26 27 28 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 26 def credentials_given? @username && !@username.empty? && @password && !@password.empty? end |
#delete_comment(id, version) ⇒ Object
40 41 42 43 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 40 def delete_comment(id, version) uri = URI("#{pr_api_endpoint}/comments/#{id}?version=#{version}") delete(uri) end |
#fetch_last_comments ⇒ Object
35 36 37 38 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 35 def fetch_last_comments uri = URI("#{pr_api_endpoint}/activities?limit=1000") fetch_json(uri)[:values].select { |v| v[:action] == "COMMENTED" }.map { |v| v[:comment] } end |
#fetch_pr_json ⇒ Object
30 31 32 33 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 30 def fetch_pr_json uri = URI(pr_api_endpoint) fetch_json(uri) end |
#inspect ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 16 def inspect inspected = super if @password inspected = inspected.sub! @password, "********".freeze end inspected end |
#post_comment(text) ⇒ Object
45 46 47 48 49 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 45 def post_comment(text) uri = URI("#{pr_api_endpoint}/comments") body = { text: text }.to_json post(uri, body) end |