class BitbucketClient
Public Class Methods
new(username, password)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 5 def initialize(username, password) self.class.basic_auth(username, password) end
Public Instance Methods
approve_pull_request(slug, pull_id)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 43 def approve_pull_request(slug, pull_id) self.class.post("/#{slug}/pullrequests/#{pull_id}/approve") end
commit_comments(slug, sha)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 9 def commit_comments(slug, sha) response = get("/#{slug}/commit/#{sha}/comments?pagelen=100") result = parse_comments(openstruct(response)) while (response['next']) response = get response['next'] result.concat(parse_comments(openstruct(response))) end result end
create_commit_comment(slug, sha, body, path, position)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 19 def create_commit_comment(slug, sha, body, path, position) post("/#{slug}/commit/#{sha}/comments", body, path, position) end
create_pull_comment(slug, pull_id, body, path, position)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 39 def create_pull_comment(slug, pull_id, body, path, position) post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position) end
pull_comments(slug, pull_id)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 23 def pull_comments(slug, pull_id) response = get("/#{slug}/pullrequests/#{pull_id}/comments?pagelen=100") parse_comments(openstruct(response)) result = parse_comments(openstruct(response)) while (response['next']) response = get response['next'] result.concat(parse_comments(openstruct(response))) end result end
pull_requests(slug)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 34 def pull_requests(slug) response = get("/#{slug}/pullrequests?state=OPEN") openstruct(response) end
unapprove_pull_request(slug, pull_id)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 47 def unapprove_pull_request(slug, pull_id) self.class.delete("/#{slug}/pullrequests/#{pull_id}/approve") end
Private Instance Methods
get(url)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 89 def get(url) self.class.get(url).parsed_response end
openstruct(response)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 53 def openstruct(response) if response['values'] response['values'].map { |r| OpenStruct.new(r) } else p response raise 'BitBucket response invalid' end end
parse_comments(values)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 62 def parse_comments(values) values.each do |value| value.content = value.content['raw'] value.line_to = value.inline ? value.inline['to'] : 0 value.filename = value.inline ? value.inline['path'] : '' end values end
post(url, body, path, position)
click to toggle source
# File lib/pronto/clients/bitbucket_client.rb, line 71 def post(url, body, path, position) options = { body: { content: { raw: body }, inline: { to: position, path: path } }.to_json, headers: { 'Content-Type': 'application/json' } } self.class.post(url, options) end