Skip to content

Commit

Permalink
Bitbucket deprecated its API v1.0: update all endpoints to API v2.0 (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathiou04 authored and doomspork committed Jun 17, 2019
1 parent 37e4485 commit 59dd7a9
Showing 1 changed file with 5 additions and 9 deletions.
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

0 comments on commit 59dd7a9

Please sign in to comment.