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.
-
#key ⇒ Object
Returns the value of attribute key.
-
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
-
#project ⇒ Object
Returns the value of attribute project.
-
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
- #credentials_given? ⇒ Boolean
- #delete_comment(id, version) ⇒ Object
- #fetch_last_comments ⇒ Object
- #fetch_pr_diff ⇒ 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
- #pull_request ⇒ Object
- #update_pr_build_status(status, changeset, build_job_link, description) ⇒ Object
Constructor Details
#initialize(project, slug, pull_request_id, environment) ⇒ BitbucketServerAPI
Returns a new instance of BitbucketServerAPI.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 12 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.verify_ssl = environment["DANGER_BITBUCKETSERVER_VERIFY_SSL"] != "false" if self.host && !(self.host.include? "http://") && !(self.host.include? "https://") self.host = "https://" + self.host end self.key = slug self.project = project self.pr_api_endpoint = "#{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.
10 11 12 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 10 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
10 11 12 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 10 def key @key end |
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
10 11 12 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 10 def pr_api_endpoint @pr_api_endpoint end |
#project ⇒ Object
Returns the value of attribute project.
10 11 12 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 10 def project @project end |
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
10 11 12 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 10 def verify_ssl @verify_ssl end |
Instance Method Details
#credentials_given? ⇒ Boolean
33 34 35 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 33 def credentials_given? @username && !@username.empty? && @password && !@password.empty? end |
#delete_comment(id, version) ⇒ Object
56 57 58 59 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 56 def delete_comment(id, version) uri = URI("#{pr_api_endpoint}/comments/#{id}?version=#{version}") delete(uri) end |
#fetch_last_comments ⇒ Object
51 52 53 54 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 51 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_diff ⇒ Object
46 47 48 49 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 46 def fetch_pr_diff uri = URI("#{pr_api_endpoint}/diff?withComments=false") fetch_json(uri) end |
#fetch_pr_json ⇒ Object
41 42 43 44 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 41 def fetch_pr_json uri = URI(pr_api_endpoint) fetch_json(uri) end |
#inspect ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 25 def inspect inspected = super inspected.gsub!(@password, "********") if @password inspected end |
#post_comment(text) ⇒ Object
61 62 63 64 65 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 61 def post_comment(text) uri = URI("#{pr_api_endpoint}/comments") body = { text: text }.to_json post(uri, body) end |
#pull_request ⇒ Object
37 38 39 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 37 def pull_request(*) fetch_pr_json end |
#update_pr_build_status(status, changeset, build_job_link, description) ⇒ Object
67 68 69 70 71 |
# File 'lib/danger/request_sources/bitbucket_server_api.rb', line 67 def update_pr_build_status(status, changeset, build_job_link, description) uri = URI("#{self.host}/rest/build-status/1.0/commits/#{changeset}") body = build_status_body(status, build_job_link, description) post(uri, body) end |