Skip to content

Commit

Permalink
Bitbucket deprecated its API v1.0: update all endpoints to API v2.0 (#…
Browse files Browse the repository at this point in the history
…354)

* Bitbucket deprecated its API v1.0: update all endpoints to API v2.0
(pull_requests wasn't updated)

* Fix issue of approve_pull_request and unapprove_pull_request method

* Use updated commit endpoint, instead of changeset

* Fix github create pullrequest comment issue

* Fix bitbucket create pullrequest comment issue

* Update bitbucket API v2 pullrequest format

* Update bitbucket API v2 pullrequest format

* Rollback bitbucket.rb and parse new bitbucket comment format

* Rename position to line_to

* Fix for parsing comments to get the path

* Support for comment paging in BitBucket API 2.0

* Print out response when request fails

At the moment it just gives an obtuse NoMethodError when the response does not contains a 'values' key

* fix (bitbucket): handle when a comment is made on a file

Currently if you create a top level 'file' comment on the PR, it breaks as the comment has no line property

* fix (bitbucket): remove extra end
  • Loading branch information
bradrees authored and doomspork committed Jan 2, 2020
1 parent c7dca8e commit d6d3f71
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions lib/pronto/clients/bitbucket_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,33 @@ def initialize(username, password)
end

def commit_comments(slug, sha)
response = get("/#{slug}/changesets/#{sha}/comments")
parse_comments(openstruct(response['values']))
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

def create_commit_comment(slug, sha, body, path, position)
post("/#{slug}/changesets/#{sha}/comments", body, path, position)
post("/#{slug}/commit/#{sha}/comments", body, path, position)
end

def pull_comments(slug, pull_id)
response = get("/#{slug}/pullrequests/#{pull_id}/comments")
parse_comments(openstruct(response['values']))
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

def pull_requests(slug)
response = get("/#{slug}/pullrequests?state=OPEN")
openstruct(response['values'])
openstruct(response)
end

def create_pull_comment(slug, pull_id, body, path, position)
Expand All @@ -40,14 +51,19 @@ def unapprove_pull_request(slug, pull_id)
private

def openstruct(response)
response.map { |r| OpenStruct.new(r) }
if response['values']
response['values'].map { |r| OpenStruct.new(r) }
else
p response
raise 'BitBucket response invalid'
end
end

def parse_comments(values)
values.each do |value|
value.content = value.content['raw']
value.line_to = value.inline['to']
value.filename = value.inline['path']
value.line_to = value.inline ? value.inline['to'] : 0
value.filename = value.inline ? value.inline['path'] : ''
end
values
end
Expand Down

0 comments on commit d6d3f71

Please sign in to comment.