From 9d2ab8b4cb74b0865893b8b975e1833ddf966fa4 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Wed, 12 Jun 2019 11:39:46 +0200 Subject: [PATCH] Bitbucket deprecated its API v1.0: update all endpoints to API v2.0 --- lib/pronto/clients/bitbucket_client.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/pronto/clients/bitbucket_client.rb b/lib/pronto/clients/bitbucket_client.rb index 4f73ee4f..5efd1e45 100644 --- a/lib/pronto/clients/bitbucket_client.rb +++ b/lib/pronto/clients/bitbucket_client.rb @@ -1,6 +1,6 @@ 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) @@ -8,7 +8,7 @@ def initialize(username, password) 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) @@ -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) @@ -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