diff --git a/lib/bitbucket_rest_api/repos.rb b/lib/bitbucket_rest_api/repos.rb index b4d83fb..558ae05 100644 --- a/lib/bitbucket_rest_api/repos.rb +++ b/lib/bitbucket_rest_api/repos.rb @@ -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 @@ -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 diff --git a/lib/bitbucket_rest_api/repos/keys.rb b/lib/bitbucket_rest_api/repos/keys.rb index 4d94b2a..91ef747 100644 --- a/lib/bitbucket_rest_api/repos/keys.rb +++ b/lib/bitbucket_rest_api/repos/keys.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/bitbucket_rest_api/repos/webhooks.rb b/lib/bitbucket_rest_api/repos/webhooks.rb index 6c71ec9..e8c7b2f 100644 --- a/lib/bitbucket_rest_api/repos/webhooks.rb +++ b/lib/bitbucket_rest_api/repos/webhooks.rb @@ -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) @@ -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) diff --git a/spec/bitbucket_rest_api/repos/keys_spec.rb b/spec/bitbucket_rest_api/repos/keys_spec.rb index cc555f4..c2043b1 100644 --- a/spec/bitbucket_rest_api/repos/keys_spec.rb +++ b/spec/bitbucket_rest_api/repos/keys_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/repos/webhooks_spec.rb b/spec/bitbucket_rest_api/repos/webhooks_spec.rb index 6ff995a..2eaac5a 100644 --- a/spec/bitbucket_rest_api/repos/webhooks_spec.rb +++ b/spec/bitbucket_rest_api/repos/webhooks_spec.rb @@ -112,7 +112,7 @@ :post, '/2.0/repositories/mock_username/mock_repo/hooks', post_put_params, - {} + { headers: { "Content-Type" => "application/json" } } ) subject.create( @@ -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( diff --git a/spec/bitbucket_rest_api/repos_spec.rb b/spec/bitbucket_rest_api/repos_spec.rb index 822e02d..e48b66a 100644 --- a/spec/bitbucket_rest_api/repos_spec.rb +++ b/spec/bitbucket_rest_api/repos_spec.rb @@ -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!