Skip to content

Commit 650c0a4

Browse files
committed
Merge pull request #66 from ispyropoulos/fix-repos-sources
Renamed Repos::Sources#get to #list as it returns a list of files
2 parents 77726c4 + 4fcdf46 commit 650c0a4

File tree

2 files changed

+98
-13
lines changed

2 files changed

+98
-13
lines changed

lib/bitbucket_rest_api/repos/sources.rb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@
33
module BitBucket
44
class Repos::Sources < API
55

6-
REQUIRED_COMMENT_PARAMS = %w[
7-
body
8-
changeset_id
9-
line
10-
path
11-
position
12-
].freeze
6+
# Gets a list of the src in a repository.
7+
#
8+
# = Examples
9+
# @bitbucket = BitBucket.new
10+
# @bitbucket.repos.sources.list 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6', 'app/contorllers/')
11+
#
12+
def list(user_name, repo_name, sha, path)
13+
_update_user_repo_params(user_name, repo_name)
14+
_validate_user_repo_params(user, repo) unless user? && repo?
15+
_validate_presence_of(sha, path)
16+
17+
get_request("/1.0/repositories/#{user}/#{repo.downcase}/src/#{sha}/#{path}")
18+
end
19+
alias :all :list
1320

14-
# Gets a source of repo
21+
# Gets information about an individual file. This method returns the file's
22+
# size and contents. If the file is encoded, this method returns the files
23+
# encoding; Currently, Bitbucket supports only base64 encoding.
1524
#
1625
# = Examples
1726
# @bitbucket = BitBucket.new
18-
# @bitbucket.repos.sources.get 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6', 'app/contorllers/')
27+
# @bitbucket.repos.sources.get 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6', 'app/assets/images/logo.jpg')
1928
#
20-
def get(user_name, repo_name, sha, path, params={})
29+
def get(user_name, repo_name, sha, path)
2130
_update_user_repo_params(user_name, repo_name)
2231
_validate_user_repo_params(user, repo) unless user? && repo?
23-
_validate_presence_of sha
24-
normalize! params
32+
_validate_presence_of(sha, path)
2533

26-
get_request("/1.0/repositories/#{user}/#{repo.downcase}/src/#{sha}/#{path}", params)
34+
get_request("/1.0/repositories/#{user}/#{repo.downcase}/raw/#{sha}/#{path}")
2735
end
2836
alias :find :get
2937

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
require 'spec_helper'
2+
3+
describe BitBucket::Repos::Sources do
4+
let(:subject) { BitBucket::Repos::Sources.new }
5+
6+
describe '#list' do
7+
context 'when some parameters are missing' do
8+
it 'raises an error' do
9+
expect do
10+
subject.list(
11+
'mock_username',
12+
'mock_repo'
13+
)
14+
end.to raise_error(ArgumentError)
15+
end
16+
end
17+
18+
context 'when path parameter is empty' do
19+
before do
20+
expect(subject).to receive(:request).with(
21+
:get,
22+
'/1.0/repositories/mock_username/mock_repo/src/moch_sha/',
23+
{},
24+
{}
25+
)
26+
end
27+
28+
it 'sends a GET request for a list of all source files' do
29+
subject.list('mock_username', 'mock_repo', 'moch_sha', '')
30+
end
31+
end
32+
33+
context 'when path parameter is defined' do
34+
before do
35+
expect(subject).to receive(:request).with(
36+
:get,
37+
'/1.0/repositories/mock_username/mock_repo/src/moch_sha/app/controller',
38+
{},
39+
{}
40+
)
41+
end
42+
43+
it 'send a GET request for a list of the source files under the specified path' do
44+
subject.list('mock_username', 'mock_repo', 'moch_sha', 'app/controller')
45+
end
46+
end
47+
end
48+
49+
describe '#get' do
50+
context 'when some parameters are missing' do
51+
it 'raises an error' do
52+
expect do
53+
subject.get(
54+
'mock_username',
55+
'mock_repo',
56+
'moch_sha'
57+
)
58+
end.to raise_error(ArgumentError)
59+
end
60+
end
61+
62+
context 'when path parameter is defined' do
63+
before do
64+
expect(subject).to receive(:request).with(
65+
:get,
66+
'/1.0/repositories/mock_username/mock_repo/raw/moch_sha/app/assets/images/logo.jpg',
67+
{},
68+
{}
69+
)
70+
end
71+
72+
it "send a GET request for a source file's size and contents" do
73+
subject.get('mock_username', 'mock_repo', 'moch_sha', 'app/assets/images/logo.jpg')
74+
end
75+
end
76+
end
77+
end

0 commit comments

Comments
 (0)