File tree Expand file tree Collapse file tree 3 files changed +83
-0
lines changed
spec/bitbucket_rest_api/repos Expand file tree Collapse file tree 3 files changed +83
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ class Repos < API
1717 :Webhooks => 'webhooks' ,
1818 :PullRequest => 'pull_request' ,
1919 :DefaultReviewers => 'default_reviewers'
20+ :Components => 'components'
2021
2122 DEFAULT_REPO_OPTIONS = {
2223 "website" => "" ,
@@ -88,6 +89,10 @@ def default_reviewers
8889 @default_reviewers ||= ApiFactory . new 'Repos::DefaultReviewers'
8990 end
9091
92+ def components
93+ @components ||= ApiFactory . new 'Repos::Components'
94+ end
95+
9196 # List branches
9297 #
9398 # = Examples
Original file line number Diff line number Diff line change 1+ # encoding: utf-8
2+
3+ module BitBucket
4+ class Repos ::Components < API
5+
6+ # List components
7+ #
8+ # = Examples
9+ # bitbucket = BitBucket.new
10+ # bitbucket.repos.components.list 'user-name', 'repo-name'
11+ # bitbucket.repos.components.list 'user-name', 'repo-name' { |component| ... }
12+ #
13+ def list ( user_name , repo_name , params = { } )
14+ update_and_validate_user_repo_params ( user_name , repo_name )
15+ normalize! params
16+
17+ response = get_request ( "/2.0/repositories/#{ user } /#{ repo . downcase } /components" , params )
18+ return response [ 'values' ] unless block_given?
19+ response [ 'values' ] . each { |el | yield el }
20+ end
21+ alias :all :list
22+
23+ # Get a component by it's ID
24+ #
25+ # = Examples
26+ # bitbucket = BitBucket.new
27+ # bitbucket.repos.components.get 'user-name', 'repo-name', 1
28+ #
29+ def get ( user_name , repo_name , component_id , params = { } )
30+ update_and_validate_user_repo_params ( user_name , repo_name )
31+ normalize! params
32+
33+ get_request ( "/2.0/repositories/#{ user } /#{ repo . downcase } /components/#{ component_id } " , params )
34+ end
35+ end
36+ end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ describe BitBucket ::Repos ::Components do
4+ subject { described_class . new }
5+ describe '#list' do
6+ before do
7+ expect ( subject ) . to receive ( :request ) . with (
8+ :get ,
9+ '/2.0/repositories/mock_user/mock_repo/components' ,
10+ { } ,
11+ { }
12+ ) . and_return ( { 'values' => [ 'component1' , 'component2' , 'component3' ] } )
13+ end
14+
15+ context 'without a block' do
16+ it 'makes a GET request for all components defined in the issue tracker' do
17+ subject . list ( 'mock_user' , 'mock_repo' )
18+ end
19+ end
20+
21+ context 'with a block' do
22+ it 'makes a GET request for all components defined in the issue tracker' do
23+ subject . list ( 'mock_user' , 'mock_repo' ) { |component | component }
24+ end
25+ end
26+ end
27+
28+ describe '#get' do
29+ before do
30+ expect ( subject ) . to receive ( :request ) . with (
31+ :get ,
32+ '/2.0/repositories/mock_user/mock_repo/components/1' ,
33+ { } ,
34+ { }
35+ )
36+ end
37+
38+ it 'makes a GET request for all components defined in the issue tracker' do
39+ subject . get ( 'mock_user' , 'mock_repo' , 1 )
40+ end
41+ end
42+ end
You can’t perform that action at this time.
0 commit comments