From 0532074c9c83a596b2a0b1304165fd4b8188619e Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Sat, 24 Jun 2017 14:28:43 +0800 Subject: [PATCH 1/3] get privileges granted on a repo --- lib/bitbucket_rest_api.rb | 3 ++- lib/bitbucket_rest_api/privileges.rb | 18 ++++++++++++++++++ spec/bitbucket_rest_api/privileges_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lib/bitbucket_rest_api/privileges.rb create mode 100644 spec/bitbucket_rest_api/privileges_spec.rb diff --git a/lib/bitbucket_rest_api.rb b/lib/bitbucket_rest_api.rb index de13095..0b59d5e 100644 --- a/lib/bitbucket_rest_api.rb +++ b/lib/bitbucket_rest_api.rb @@ -77,7 +77,8 @@ def lookup_constant(const_name) :User => 'user', :Users => 'users', :Invitations => 'invitations', - :Teams => 'teams' + :Teams => 'teams', + :Privileges => 'privileges' #:Teams => 'teams', #:PullRequests => 'pull_requests', diff --git a/lib/bitbucket_rest_api/privileges.rb b/lib/bitbucket_rest_api/privileges.rb new file mode 100644 index 0000000..1733ad6 --- /dev/null +++ b/lib/bitbucket_rest_api/privileges.rb @@ -0,0 +1,18 @@ +# encoding: utf-8 + +module BitBucket + class Privileges < API + extend AutoloadHelper + + def initialize(options = { }) + super(options) + end + + def repo_list(user_name, repo_name) + _update_user_repo_params(user_name, repo_name) + _validate_user_repo_params(user, repo) unless user? && repo? + + get_request("/1.0/privileges/#{user_name}/#{repo_name}") + end + end +end diff --git a/spec/bitbucket_rest_api/privileges_spec.rb b/spec/bitbucket_rest_api/privileges_spec.rb new file mode 100644 index 0000000..04bb534 --- /dev/null +++ b/spec/bitbucket_rest_api/privileges_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe BitBucket::Privileges do + let(:repo) { BitBucket::Privileges.new } + + describe '.repo_list' do + before do + expect(repo).to receive(:request).with( + :get, + '/1.0/privileges/mock_username/mock_repo', + {}, + {} + ) + end + + it 'should send a GET request for the given repo' do + repo.repo_list('mock_username', 'mock_repo') + end + end +end From 871e0b125aaec057256a054923234bd4705828d2 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Sat, 24 Jun 2017 14:35:48 +0800 Subject: [PATCH 2/3] add privileges to client --- lib/bitbucket_rest_api/client.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bitbucket_rest_api/client.rb b/lib/bitbucket_rest_api/client.rb index bd594e0..d61357c 100644 --- a/lib/bitbucket_rest_api/client.rb +++ b/lib/bitbucket_rest_api/client.rb @@ -51,5 +51,9 @@ def user_api(options = {}) def invitations(options = {}) @invitations ||= ApiFactory.new "Invitations", options end + + def privileges(options = {}) + @privileges ||= ApiFactory.new 'Privileges', options + end end # Client end # BitBucket From 0e3b5f5de104c4e6e0c2ce07a979beabcfaf94f3 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Mon, 25 Sep 2017 19:57:42 +0800 Subject: [PATCH 3/3] privilege request with privilege_account_name --- lib/bitbucket_rest_api/privileges.rb | 8 +++-- spec/bitbucket_rest_api/privileges_spec.rb | 35 ++++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/bitbucket_rest_api/privileges.rb b/lib/bitbucket_rest_api/privileges.rb index 1733ad6..a8c5864 100644 --- a/lib/bitbucket_rest_api/privileges.rb +++ b/lib/bitbucket_rest_api/privileges.rb @@ -8,11 +8,15 @@ def initialize(options = { }) super(options) end - def repo_list(user_name, repo_name) + def repo_list(user_name, repo_name, privilege_account = nil) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? - get_request("/1.0/privileges/#{user_name}/#{repo_name}") + if privilege_account + get_request("/1.0/privileges/#{user_name}/#{repo_name}/#{privilege_account}") + else + get_request("/1.0/privileges/#{user_name}/#{repo_name}") + end end end end diff --git a/spec/bitbucket_rest_api/privileges_spec.rb b/spec/bitbucket_rest_api/privileges_spec.rb index 04bb534..0426927 100644 --- a/spec/bitbucket_rest_api/privileges_spec.rb +++ b/spec/bitbucket_rest_api/privileges_spec.rb @@ -4,17 +4,34 @@ let(:repo) { BitBucket::Privileges.new } describe '.repo_list' do - before do - expect(repo).to receive(:request).with( - :get, - '/1.0/privileges/mock_username/mock_repo', - {}, - {} - ) + context 'without privilege_account' do + before do + expect(repo).to receive(:request).with( + :get, + '/1.0/privileges/mock_username/mock_repo', + {}, + {} + ) + end + + it 'should send a GET request for the given repo' do + repo.repo_list('mock_username', 'mock_repo') + end end - it 'should send a GET request for the given repo' do - repo.repo_list('mock_username', 'mock_repo') + context 'with privilege_account' do + before do + expect(repo).to receive(:request).with( + :get, + '/1.0/privileges/mock_username/mock_repo/mock_privilege_account', + {}, + {} + ) + end + + it 'should send a GET request for the given repo' do + repo.repo_list('mock_username', 'mock_repo', 'mock_privilege_account') + end end end end