Skip to content

Commit 7028a6d

Browse files
twoism-devibrahima
authored andcommitted
Use the 2.0 version of the Bitbucket API for repository lists - this gives us the extra
parameter of role, allowing us to filter the repository list by whether a user is an owner, contributor etc
1 parent e03b693 commit 7028a6d

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

lib/bitbucket_rest_api/repos.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,19 @@ def delete(user_name, repo_name)
228228
#
229229
# = Examples
230230
# bitbucket = BitBucket.new
231-
# bitbucket.repos.list :user => 'user-name'
231+
# bitbucket.repos.list :user => 'user-name', :role => 'owner'
232232
# bitbucket.repos.list :user => 'user-name', { |repo| ... }
233233
def list(*args)
234234
params = args.extract_options!
235235
normalize! params
236236
_merge_user_into_params!(params) unless params.has_key?('user')
237-
filter! %w[ user type ], params
238-
239-
response = #if (user_name = params.delete("user"))
240-
# get_request("/1.0/users/#{user_name}", params)
241-
#else
242-
# For authenticated user
243-
get_request("/1.0/user/repositories", params)
244-
#end
237+
params.merge!('pagelen' => 100) unless params.has_key?('pagelen')
238+
239+
filter! %w[ user role pagelen ], params
240+
241+
response = get_request("/2.0/repositories", params)
242+
243+
response = response[:values]
245244
return response unless block_given?
246245
response.each { |el| yield el }
247246
end

spec/bitbucket_rest_api/repos_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@
100100
before do
101101
expect(repo).to receive(:request).with(
102102
:get,
103-
'/1.0/user/repositories',
104-
{},
103+
'/2.0/repositories',
104+
{"pagelen" => 100},
105105
{}
106-
).and_return(['repo1', 'repo2' ,'repo3'])
106+
).and_return(values: ['repo1', 'repo2' ,'repo3'])
107107
end
108108

109109
# FIXME: this method belongs in the User class!

0 commit comments

Comments
 (0)