Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket deprecated its API v1.0: update all endpoints to API v2.0 #347

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/pronto/clients/bitbucket_client.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class BitbucketClient
include HTTParty
base_uri 'https://api.bitbucket.org/1.0/repositories'
base_uri 'https://api.bitbucket.org/2.0/repositories'

def initialize(username, password)
self.class.basic_auth(username, password)
end

def commit_comments(slug, sha)
response = get("/#{slug}/changesets/#{sha}/comments")
openstruct(response)
openstruct(response['values'])
end

def create_commit_comment(slug, sha, body, path, position)
Expand All @@ -17,7 +17,7 @@ def create_commit_comment(slug, sha, body, path, position)

def pull_comments(slug, pull_id)
response = get("/#{slug}/pullrequests/#{pull_id}/comments")
openstruct(response)
openstruct(response['values'])
end

def pull_requests(slug)
Expand All @@ -30,19 +30,15 @@ def create_pull_comment(slug, pull_id, body, path, position)
end

def approve_pull_request(slug, pull_id)
self.class.post("#{pull_request_api(slug)}/pullrequests/#{pull_id}/approve")
self.class.post("#{slug}/pullrequests/#{pull_id}/approve")
end

def unapprove_pull_request(slug, pull_id)
self.class.delete("#{pull_request_api(slug)}/pullrequests/#{pull_id}/approve")
self.class.delete("#{slug}/pullrequests/#{pull_id}/approve")
end

private

def pull_request_api(slug)
"https://api.bitbucket.org/2.0/repositories/#{slug}"
end

def openstruct(response)
response.map { |r| OpenStruct.new(r) }
end
Expand Down