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 #354

Merged
merged 19 commits into from
Jan 2, 2020
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
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