Skip to content

Commit 977192f

Browse files
committed
Renamed Repos:Commits#get to #list for consistency and added alias
- Added support for the `branchortag` optional parameter - Added support for additional optional parameters according to official API documention - Replaced `pry-debugger` with `pry-byebug` gem https://confluence.atlassian.com/display/bitbucket/commits+or+commit+resource
1 parent 13901a5 commit 977192f

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
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

bitbucket_rest_api.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Gem::Specification.new do |gem|
2727
gem.add_development_dependency 'simplecov', '~> 0.6.1'
2828
gem.add_development_dependency 'rake'
2929
gem.add_development_dependency 'bundler'
30-
gem.add_development_dependency 'pry-debugger'
30+
gem.add_development_dependency 'pry-byebug'
3131
gem.add_development_dependency 'mocha'
3232
end

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

spec/bitbucket_rest_api/repos/commits_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe BitBucket::Repos::Commits do
44
let(:commits) { BitBucket::Repos::Commits.new }
55

6-
describe '.get' do
6+
describe '.list' do
77
before do
88
expect(commits).to receive(:request).with(
99
:get,
@@ -14,7 +14,7 @@
1414
end
1515

1616
it 'should send a GET request for the commits belonging to the given repo' do
17-
commits.get('mock_username', 'mock_repo')
17+
commits.list('mock_username', 'mock_repo')
1818
end
1919
end
2020
end

0 commit comments

Comments
 (0)