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

Use the 2.0 version of the Bitbucket API for repository lists #72

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions lib/bitbucket_rest_api/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def default_reviewers
@default_reviewers ||= ApiFactory.new 'Repos::DefaultReviewers'
end

def webhooks
@webhooks ||= ApiFactory.new 'Repos::Webhooks'
end

# List branches
#
# = Examples
Expand Down Expand Up @@ -219,20 +223,19 @@ def delete(user_name, repo_name)
#
# = Examples
# bitbucket = BitBucket.new
# bitbucket.repos.list :user => 'user-name'
# bitbucket.repos.list :user => 'user-name', :role => 'owner'
# bitbucket.repos.list :user => 'user-name', { |repo| ... }
def list(*args)
params = args.extract_options!
normalize! params
_merge_user_into_params!(params) unless params.has_key?('user')
filter! %w[ user type ], params

response = #if (user_name = params.delete("user"))
# get_request("/1.0/users/#{user_name}", params)
#else
# For authenticated user
get_request("/1.0/user/repositories", params)
#end
params.merge!('pagelen' => 100) unless params.has_key?('pagelen')

filter! %w[ user role pagelen ], params

response = get_request("/2.0/repositories", params)

response = response[:values]
return response unless block_given?
response.each { |el| yield el }
end
Expand Down
9 changes: 5 additions & 4 deletions lib/bitbucket_rest_api/repos/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def list(user_name, repo_name, params={})
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params)
response = get_request("/1.0/repositories/#{user}/#{repo}/deploy-keys/", params)
return response unless block_given?
response.each { |el| yield el }
end
Expand All @@ -42,7 +42,8 @@ def create(user_name, repo_name, params={})
filter! VALID_KEY_PARAM_NAMES, params
assert_required_keys(VALID_KEY_PARAM_NAMES, params)

post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params)
options = { headers: { "Content-Type" => "application/json" } }
post_request("/1.0/repositories/#{user}/#{repo}/deploy-keys/", params, options)
end

# Edit a key
Expand All @@ -65,7 +66,7 @@ def edit(user_name, repo_name, key_id, params={})
normalize! params
filter! VALID_KEY_PARAM_NAMES, params

put_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params)
put_request("/1.0/repositories/#{user}/#{repo}/deploy-keys/#{key_id}", params)
end

# Delete key
Expand All @@ -80,7 +81,7 @@ def delete(user_name, repo_name, key_id, params={})
_validate_presence_of key_id
normalize! params

delete_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params)
delete_request("/1.0/repositories/#{user}/#{repo}/deploy-keys/#{key_id}", params)
end

end # Repos::Keys
Expand Down
9 changes: 6 additions & 3 deletions lib/bitbucket_rest_api/repos/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def create(user_name, repo_name, params = {})
'events'
)

post_request("/2.0/repositories/#{user_name}/#{repo_name}/hooks", params)

options = { headers: { "Content-Type" => "application/json" } }
post_request("/2.0/repositories/#{user_name}/#{repo_name}/hooks", params, options)
end

def list(user_name, repo_name)
Expand Down Expand Up @@ -67,10 +69,11 @@ def edit(user_name, repo_name, hook_uuid, params = {})
'events'
)


options = { headers: { "Content-Type" => "application/json" } }
put_request(
"/2.0/repositories/#{user_name}/#{repo_name}/hooks/#{hook_uuid}",
params
)
params, options)
end

def delete(user_name, repo_name, hook_uuid)
Expand Down
2 changes: 1 addition & 1 deletion spec/bitbucket_rest_api/repos/keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:post,
'/1.0/repositories/mock_username/mock_repo/deploy-keys/',
{ 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
{}
{ headers: {"Content-Type"=>"application/json"} }
)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/bitbucket_rest_api/repos/webhooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
:post,
'/2.0/repositories/mock_username/mock_repo/hooks',
post_put_params,
{}
{ headers: { "Content-Type" => "application/json" } }
)

subject.create(
Expand Down Expand Up @@ -218,7 +218,7 @@
:put,
'/2.0/repositories/mock_username/mock_repo/hooks/mock_uuid',
post_put_params,
{}
{ headers: { "Content-Type" => "application/json" } }
)

subject.edit(
Expand Down
6 changes: 3 additions & 3 deletions spec/bitbucket_rest_api/repos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@
before do
expect(repo).to receive(:request).with(
:get,
'/1.0/user/repositories',
{},
'/2.0/repositories',
{"pagelen" => 100},
{}
).and_return(['repo1', 'repo2' ,'repo3'])
).and_return(values: ['repo1', 'repo2' ,'repo3'])
end

# FIXME: this method belongs in the User class!
Expand Down