Skip to content

Commit d51cdd7

Browse files
committed
Merge branch 'master' into teams
2 parents 5c8dc34 + 77726c4 commit d51cdd7

30 files changed

+431
-158
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ TAGS
1515
.tags_sorted_by_file
1616
coverage
1717
tags
18+
/.idea
19+
.ruby-gemset

LICENSE.txt

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
1-
Copyright (c) 2013 James M Cochran
1+
The MIT License (MIT)
22

3-
Permission is hereby granted, free of charge, to any person obtaining
4-
a copy of this software and associated documentation files (the
5-
"Software"), to deal in the Software without restriction, including
6-
without limitation the rights to use, copy, modify, merge, publish,
7-
distribute, sublicense, and/or sell copies of the Software, and to
8-
permit persons to whom the Software is furnished to do so, subject to
9-
the following conditions:
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
104

11-
The above copyright notice and this permission notice shall be
12-
included in all copies or substantial portions of the Software.
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
136

14-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
22-
23-
Original github_api project:
24-
Copyright (c) 2011 Piotr Murach
25-
26-
Permission is hereby granted, free of charge, to any person obtaining
27-
a copy of this software and associated documentation files (the
28-
"Software"), to deal in the Software without restriction, including
29-
without limitation the rights to use, copy, modify, merge, publish,
30-
distribute, sublicense, and/or sell copies of the Software, and to
31-
permit persons to whom the Software is furnished to do so, subject to
32-
the following conditions:
33-
34-
The above copyright notice and this permission notice shall be
35-
included in all copies or substantial portions of the Software.
36-
37-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
42-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
43-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bitbucket_rest_api.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
2323
gem.add_dependency 'simple_oauth'
2424

2525
gem.add_development_dependency 'rspec', '>= 0'
26+
gem.add_development_dependency 'rack-test'
2627
gem.add_development_dependency 'webmock', '~> 1.8.0'
2728
gem.add_development_dependency 'vcr', '~> 2.2.0'
2829
gem.add_development_dependency 'simplecov', '~> 0.6.1'

lib/bitbucket_rest_api/api.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'bitbucket_rest_api/request'
77
require 'bitbucket_rest_api/core_ext/hash'
88
require 'bitbucket_rest_api/core_ext/array'
9-
require 'bitbucket_rest_api/compatibility'
109
require 'bitbucket_rest_api/api/actions'
1110
require 'bitbucket_rest_api/api_factory'
1211

@@ -80,6 +79,11 @@ def method_missing(method, *args, &block) # :nodoc:
8079
end
8180
end
8281

82+
def update_and_validate_user_repo_params(user_name, repo_name=nil)
83+
_update_user_repo_params(user_name, repo_name)
84+
_validate_user_repo_params(user, repo) unless user? && repo?
85+
end
86+
8387
def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
8488
self.user = user_name || self.user
8589
self.repo = repo_name || self.repo

lib/bitbucket_rest_api/api/actions.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,5 @@ def api_methods_in(klass)
3131
methods
3232
end
3333

34-
def append_arguments(method)
35-
_method = self.method(method)
36-
if _method.arity == 0
37-
args = "()"
38-
elsif _method.arity > 0
39-
args = "(few)"
40-
else
41-
args = "(else)"
42-
end
43-
args
44-
end
45-
4634
end # API
4735
end # BitBucket

lib/bitbucket_rest_api/client.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def issues(options = {})
1616

1717
# An API for users to manage their own tokens.
1818
def oauth(options = {})
19-
raise "Unimpletmented"
20-
#@oauth ||= ApiFactory.new 'Authorizations', options
19+
@oauth ||= ApiFactory.new 'Request::OAuth', options
2120
end
2221
alias :authorizations :oauth
2322

@@ -26,8 +25,7 @@ def teams(options = {})
2625
end
2726

2827
def pull_requests(options = {})
29-
raise "Unimplemented"
30-
#@pull_requests ||= ApiFactory.new 'PullRequests', options
28+
@pull_requests ||= ApiFactory.new 'Repos::PullRequest', options
3129
end
3230

3331
def repos(options = {})

lib/bitbucket_rest_api/compatibility.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/bitbucket_rest_api/repos.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Repos < API
1515
:Commits => 'commits',
1616
:Download => 'download',
1717
:Webhooks => 'webhooks',
18-
:PullRequest => 'pull_request'
18+
:PullRequest => 'pull_request',
19+
:DefaultReviewers => 'default_reviewers'
1920

2021
DEFAULT_REPO_OPTIONS = {
2122
"website" => "",
@@ -69,20 +70,24 @@ def services
6970
@services ||= ApiFactory.new 'Repos::Services'
7071
end
7172
def forks
72-
@services ||= ApiFactory.new 'Repos::Forks'
73+
@forks ||= ApiFactory.new 'Repos::Forks'
7374
end
7475
def commits
75-
@services ||=ApiFactory.new 'Repos::Commits'
76+
@commits ||=ApiFactory.new 'Repos::Commits'
7677
end
7778
def download
78-
@services ||=ApiFactory.new "Repos::Download"
79+
@download ||=ApiFactory.new "Repos::Download"
7980
end
8081

8182
# Access to Repos::PullRequests API
8283
def pull_request
8384
@pull_request ||= ApiFactory.new 'Repos::PullRequest'
8485
end
8586

87+
def default_reviewers
88+
@default_reviewers ||= ApiFactory.new 'Repos::DefaultReviewers'
89+
end
90+
8691
# List branches
8792
#
8893
# = Examples

lib/bitbucket_rest_api/repos/commits.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,38 @@
33
module BitBucket
44
class Repos::Commits < API
55

6-
def get(user_name, repo_name)
6+
VALID_KEY_PARAM_NAMES = %w(include exclude).freeze
7+
8+
# Gets the commit information associated with a repository. By default, this
9+
# call returns all the commits across all branches, bookmarks, and tags. The
10+
# newest commit is first.
11+
#
12+
# = Parameters
13+
# *<tt>include</tt> - The SHA, branch, bookmark, or tag to include, for example, v10 or master. You can repeat the parameter multiple times.
14+
# *<tt>exclude</tt> - The SHA, branch, bookmark, or tag to exclude, for example, v10 or master . You can repeat the parameter multiple times.
15+
#
16+
# = Examples
17+
# bitbucket = BitBucket.new
18+
# bitbucket.repos.commits.list 'user-name', 'repo-name'
19+
# bitbucket.repos.commits.list 'user-name', 'repo-name', 'master'
20+
# bitbucket.repos.commits.list 'user-name', 'repo-name' { |key| ... }
21+
# bitbucket.repos.commits.list 'user-name', 'repo-name', nil,
22+
# "include" => "feature-branch",
23+
# "exclude" => "master"
24+
#
25+
def list(user_name, repo_name, branchortag=nil, params={})
726
_update_user_repo_params(user_name, repo_name)
827
_validate_user_repo_params(user, repo) unless user? && repo?
9-
get_request("/2.0/repositories/#{user}/#{repo.downcase}/commits")
10-
end
28+
normalize! params
29+
filter! VALID_KEY_PARAM_NAMES, params
1130

31+
path = "/2.0/repositories/#{user}/#{repo.downcase}/commits"
32+
path << "/#{branchortag}" if branchortag
33+
response = get_request(path, params)
34+
return response unless block_given?
35+
response.each { |el| yield el }
36+
end
37+
alias :all :list
1238

13-
end # Repos::Keys
39+
end # Repos::Commits
1440
end # BitBucket
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module BitBucket
2+
class Repos::DefaultReviewers < API
3+
4+
# List default reviewers
5+
#
6+
# = Examples
7+
# bitbucket = BitBucket.new
8+
# bitbucket.repos.default_reviewers.list 'user-name', 'repo-name'
9+
# bitbucket.repos.default_reviewers.list 'user-name', 'repo-name' { |reviewer| ... }
10+
#
11+
def list(user_name, repo_name, params={})
12+
update_and_validate_user_repo_params(user_name, repo_name)
13+
normalize! params
14+
15+
response = get_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers", params)
16+
return response unless block_given?
17+
response.each { |el| yield el }
18+
end
19+
alias :all :list
20+
21+
# Get a default reviewer's info
22+
#
23+
# = Examples
24+
# bitbucket = BitBucket.new
25+
# bitbucket.repos.default_reviewers.get 'user-name', 'repo-name', 'reviewer-username'
26+
#
27+
def get(user_name, repo_name, reviewer_username, params={})
28+
update_and_validate_user_repo_params(user_name, repo_name)
29+
normalize! params
30+
31+
get_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
32+
end
33+
34+
# Add a user to the default-reviewers list for the repo
35+
#
36+
# = Examples
37+
# bitbucket = BitBucket.new
38+
# bitbucket.repos.default_reviewers.add 'user-name', 'repo-name', 'reviewer-username'
39+
#
40+
def add(user_name, repo_name, reviewer_username, params={})
41+
update_and_validate_user_repo_params(user_name, repo_name)
42+
normalize! params
43+
44+
put_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
45+
end
46+
47+
# Remove a user from the default-reviewers list for the repo
48+
#
49+
# = Examples
50+
# bitbucket = BitBucket.new
51+
# bitbucket.repos.default_reviewers.remove 'user-name', 'repo-name', 'reviewer-username'
52+
#
53+
def remove(user_name, repo_name, reviewer_username, params={})
54+
update_and_validate_user_repo_params(user_name, repo_name)
55+
normalize! params
56+
delete_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)