tinybucket 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +35 -0
- data/.rspec +1 -0
- data/.rubocop.yml +44 -0
- data/.travis.yml +10 -0
- data/Gemfile +22 -0
- data/Guardfile +13 -0
- data/LICENSE +21 -0
- data/README.md +237 -0
- data/Rakefile +39 -0
- data/lib/faraday_middleware/follow_oauth_redirects.rb +67 -0
- data/lib/tinybucket.rb +61 -0
- data/lib/tinybucket/api.rb +20 -0
- data/lib/tinybucket/api/base_api.rb +31 -0
- data/lib/tinybucket/api/branch_restrictions_api.rb +26 -0
- data/lib/tinybucket/api/comments_api.rb +46 -0
- data/lib/tinybucket/api/commits_api.rb +26 -0
- data/lib/tinybucket/api/diff_api.rb +17 -0
- data/lib/tinybucket/api/helper.rb +22 -0
- data/lib/tinybucket/api/helper/api_helper.rb +48 -0
- data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +27 -0
- data/lib/tinybucket/api/helper/comments_helper.rb +49 -0
- data/lib/tinybucket/api/helper/commits_helper.rb +27 -0
- data/lib/tinybucket/api/helper/diff_helper.rb +29 -0
- data/lib/tinybucket/api/helper/pull_requests_helper.rb +44 -0
- data/lib/tinybucket/api/helper/repo_helper.rb +29 -0
- data/lib/tinybucket/api/helper/repos_helper.rb +21 -0
- data/lib/tinybucket/api/helper/team_helper.rb +35 -0
- data/lib/tinybucket/api/helper/user_helper.rb +31 -0
- data/lib/tinybucket/api/pull_requests_api.rb +49 -0
- data/lib/tinybucket/api/repo_api.rb +35 -0
- data/lib/tinybucket/api/repos_api.rb +19 -0
- data/lib/tinybucket/api/team_api.rb +51 -0
- data/lib/tinybucket/api/user_api.rb +44 -0
- data/lib/tinybucket/api_factory.rb +21 -0
- data/lib/tinybucket/client.rb +95 -0
- data/lib/tinybucket/connection.rb +62 -0
- data/lib/tinybucket/constants.rb +4 -0
- data/lib/tinybucket/error.rb +8 -0
- data/lib/tinybucket/error/base_error.rb +12 -0
- data/lib/tinybucket/error/service_error.rb +20 -0
- data/lib/tinybucket/model.rb +20 -0
- data/lib/tinybucket/model/base.rb +54 -0
- data/lib/tinybucket/model/branch_restriction.rb +17 -0
- data/lib/tinybucket/model/comment.rb +39 -0
- data/lib/tinybucket/model/commit.rb +39 -0
- data/lib/tinybucket/model/concerns.rb +14 -0
- data/lib/tinybucket/model/concerns/reloadable.rb +45 -0
- data/lib/tinybucket/model/concerns/repository_keys.rb +43 -0
- data/lib/tinybucket/model/error_response.rb +7 -0
- data/lib/tinybucket/model/page.rb +65 -0
- data/lib/tinybucket/model/profile.rb +37 -0
- data/lib/tinybucket/model/pull_request.rb +64 -0
- data/lib/tinybucket/model/repository.rb +96 -0
- data/lib/tinybucket/model/team.rb +39 -0
- data/lib/tinybucket/parser.rb +25 -0
- data/lib/tinybucket/parser/base_parser.rb +17 -0
- data/lib/tinybucket/parser/branch_restriction_parser.rb +9 -0
- data/lib/tinybucket/parser/branch_restrictions_parser.rb +10 -0
- data/lib/tinybucket/parser/comment_parser.rb +9 -0
- data/lib/tinybucket/parser/comments_parser.rb +10 -0
- data/lib/tinybucket/parser/commit_parser.rb +9 -0
- data/lib/tinybucket/parser/commits_parser.rb +9 -0
- data/lib/tinybucket/parser/profile_parser.rb +9 -0
- data/lib/tinybucket/parser/profiles_parser.rb +9 -0
- data/lib/tinybucket/parser/pull_request_parser.rb +9 -0
- data/lib/tinybucket/parser/pull_requests_parser.rb +10 -0
- data/lib/tinybucket/parser/repo_parser.rb +9 -0
- data/lib/tinybucket/parser/repos_parser.rb +10 -0
- data/lib/tinybucket/parser/team_parser.rb +9 -0
- data/lib/tinybucket/parser/teams_parser.rb +9 -0
- data/lib/tinybucket/request.rb +55 -0
- data/lib/tinybucket/response.rb +7 -0
- data/lib/tinybucket/response/error_handler.rb +14 -0
- data/lib/tinybucket/version.rb +3 -0
- data/spec/fixtures/commit.json +83 -0
- data/spec/fixtures/profile.json +29 -0
- data/spec/fixtures/pull_request.json +106 -0
- data/spec/fixtures/repositories/get.json +78 -0
- data/spec/fixtures/repositories/test_owner/get.json +78 -0
- data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/1/get.json +17 -0
- data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/get.json +101 -0
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json +38 -0
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json +40 -0
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json +83 -0
- data/spec/fixtures/repositories/test_owner/test_repo/commits/get.json +73 -0
- data/spec/fixtures/repositories/test_owner/test_repo/diff/1/get.json +21 -0
- data/spec/fixtures/repositories/test_owner/test_repo/forks/get.json +78 -0
- data/spec/fixtures/repositories/test_owner/test_repo/get.json +71 -0
- data/spec/fixtures/repositories/test_owner/test_repo/patch/1/get.json +29 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/delete.json +3 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/post.json +3 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/1/get.json +30 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +44 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +66 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/diff/get.txt +13 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/get.json +164 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +112 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_declined.json +112 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_merged.json +112 -0
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_open.json +112 -0
- data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +32 -0
- data/spec/fixtures/repository.json +71 -0
- data/spec/fixtures/teams/test_team/followers/get.json +36 -0
- data/spec/fixtures/teams/test_team/following/get.json +39 -0
- data/spec/fixtures/teams/test_team/get.json +32 -0
- data/spec/fixtures/teams/test_team/members/get.json +36 -0
- data/spec/fixtures/teams/test_team/repositories/get.json +125 -0
- data/spec/fixtures/users/test_owner/followers/get.json +65 -0
- data/spec/fixtures/users/test_owner/following/get.json +100 -0
- data/spec/fixtures/users/test_owner/get.json +29 -0
- data/spec/lib/tinybucket/api/branch_restrictions_api_spec.rb +78 -0
- data/spec/lib/tinybucket/api/comments_api_spec.rb +133 -0
- data/spec/lib/tinybucket/api/commits_api_spec.rb +63 -0
- data/spec/lib/tinybucket/api/diff_api_spec.rb +5 -0
- data/spec/lib/tinybucket/api/pull_requests_api_spec.rb +229 -0
- data/spec/lib/tinybucket/api/repo_api_spec.rb +100 -0
- data/spec/lib/tinybucket/api/repos_api_spec.rb +28 -0
- data/spec/lib/tinybucket/api/team_api_spec.rb +87 -0
- data/spec/lib/tinybucket/api/user_api_spec.rb +60 -0
- data/spec/lib/tinybucket/api_factory_spec.rb +23 -0
- data/spec/lib/tinybucket/client_spec.rb +102 -0
- data/spec/lib/tinybucket/connection_spec.rb +30 -0
- data/spec/lib/tinybucket/model/branch_restriction_spec.rb +29 -0
- data/spec/lib/tinybucket/model/comment_spec.rb +31 -0
- data/spec/lib/tinybucket/model/commit_spec.rb +62 -0
- data/spec/lib/tinybucket/model/page_spec.rb +58 -0
- data/spec/lib/tinybucket/model/profile_spec.rb +47 -0
- data/spec/lib/tinybucket/model/pull_request_spec.rb +122 -0
- data/spec/lib/tinybucket/model/repository_spec.rb +131 -0
- data/spec/lib/tinybucket/model/team_spec.rb +53 -0
- data/spec/lib/tinybucket_spec.rb +32 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/api_response_macros.rb +30 -0
- data/spec/support/model_macros.rb +61 -0
- data/tinybucket.gemspec +36 -0
- metadata +437 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
{
|
2
|
+
"pagelen": 10,
|
3
|
+
"values": [
|
4
|
+
{
|
5
|
+
"username": "jdoklovic",
|
6
|
+
"kind": "user",
|
7
|
+
"website": "http://www.sysbliss.com/",
|
8
|
+
"display_name": "Jonathan Doklovic",
|
9
|
+
"links": {
|
10
|
+
"self": {
|
11
|
+
"href": "https://api.bitbucket.org/2.0/users/jdoklovic"
|
12
|
+
},
|
13
|
+
"repositories": {
|
14
|
+
"href": "https://api.bitbucket.org/2.0/users/jdoklovic/repositories"
|
15
|
+
},
|
16
|
+
"html": {
|
17
|
+
"href": "https://api.bitbucket.org/jdoklovic"
|
18
|
+
},
|
19
|
+
"followers": {
|
20
|
+
"href": "https://api.bitbucket.org/2.0/users/jdoklovic/followers"
|
21
|
+
},
|
22
|
+
"avatar": {
|
23
|
+
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2010/Sep/30/jd_profile_avatar.jpg"
|
24
|
+
},
|
25
|
+
"following": {
|
26
|
+
"href": "https://api.bitbucket.org/2.0/users/jdoklovic/following"
|
27
|
+
}
|
28
|
+
},
|
29
|
+
"created_on": "2010-09-30T13:44:45.049874+00:00",
|
30
|
+
"location": "Minneapolis, MN",
|
31
|
+
"type":"user"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"username": "atlassian_tutorial",
|
35
|
+
"kind": "team",
|
36
|
+
"website": "",
|
37
|
+
"display_name": "Atlassian Tutorials",
|
38
|
+
"links": {
|
39
|
+
"self": {
|
40
|
+
"href": "https://api.bitbucket.org/2.0/teams/atlassian_tutorial"
|
41
|
+
},
|
42
|
+
"repositories": {
|
43
|
+
"href": "https://api.bitbucket.org/2.0/teams/atlassian_tutorial/repositories"
|
44
|
+
},
|
45
|
+
"html": {
|
46
|
+
"href": "https://api.bitbucket.org/atlassian_tutorial"
|
47
|
+
},
|
48
|
+
"followers": {
|
49
|
+
"href": "https://api.bitbucket.org/2.0/teams/atlassian_tutorial/followers"
|
50
|
+
},
|
51
|
+
"avatar": {
|
52
|
+
"href": "https://secure.gravatar.com/avatar/eb4e0ad6934518b3e335345a4ceeef21?d=https%3A%2F%2Fd3oaxc4q5k2d6q.cloudfront.net%2Fm%2Fbc85d1577e04%2Fimg%2Fdefault_team_avatar%2F32%2Fteam_blue.png&s=32"
|
53
|
+
},
|
54
|
+
"members": {
|
55
|
+
"href": "https://api.bitbucket.org/2.0/teams/atlassian_tutorial/members"
|
56
|
+
},
|
57
|
+
"following": {
|
58
|
+
"href": "https://api.bitbucket.org/2.0/teams/atlassian_tutorial/following"
|
59
|
+
}
|
60
|
+
},
|
61
|
+
"created_on": "2011-11-29T05:38:01.075233+00:00",
|
62
|
+
"location": "",
|
63
|
+
"type":"team"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"username": "cat_vasja",
|
67
|
+
"kind": "team",
|
68
|
+
"website": "",
|
69
|
+
"display_name": "cat_vasja",
|
70
|
+
"links": {
|
71
|
+
"self": {
|
72
|
+
"href": "https://api.bitbucket.org/2.0/teams/cat_vasja"
|
73
|
+
},
|
74
|
+
"repositories": {
|
75
|
+
"href": "https://api.bitbucket.org/2.0/teams/cat_vasja/repositories"
|
76
|
+
},
|
77
|
+
"html": {
|
78
|
+
"href": "https://api.bitbucket.org/cat_vasja"
|
79
|
+
},
|
80
|
+
"followers": {
|
81
|
+
"href": "https://api.bitbucket.org/2.0/teams/cat_vasja/followers"
|
82
|
+
},
|
83
|
+
"avatar": {
|
84
|
+
"href": "https://secure.gravatar.com/avatar/e16be80e861baccc5ed4691737faeb05?d=https%3A%2F%2Fd3oaxc4q5k2d6q.cloudfront.net%2Fm%2Fbc85d1577e04%2Fimg%2Fdefault_team_avatar%2F32%2Fteam_blue.png&s=32"
|
85
|
+
},
|
86
|
+
"members": {
|
87
|
+
"href": "https://api.bitbucket.org/2.0/teams/cat_vasja/members"
|
88
|
+
},
|
89
|
+
"following": {
|
90
|
+
"href": "https://api.bitbucket.org/2.0/teams/cat_vasja/following"
|
91
|
+
}
|
92
|
+
},
|
93
|
+
"created_on": "2012-10-09T19:45:37.292078+00:00",
|
94
|
+
"location": "Deutschland",
|
95
|
+
"type":"team"
|
96
|
+
}
|
97
|
+
],
|
98
|
+
"page": 1,
|
99
|
+
"size": 3
|
100
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"username": "tutorials",
|
3
|
+
"kind": "user",
|
4
|
+
"website": "https://tutorials.bitbucket.org/",
|
5
|
+
"display_name": "first name last",
|
6
|
+
"links": {
|
7
|
+
"self": {
|
8
|
+
"href": "https://api.bitbucket.org/2.0/users/tutorials"
|
9
|
+
},
|
10
|
+
"repositories": {
|
11
|
+
"href": "https://api.bitbucket.org/2.0/users/tutorials/repositories"
|
12
|
+
},
|
13
|
+
"html": {
|
14
|
+
"href": "https://api.bitbucket.org/tutorials"
|
15
|
+
},
|
16
|
+
"followers": {
|
17
|
+
"href": "https://api.bitbucket.org/2.0/users/tutorials/followers"
|
18
|
+
},
|
19
|
+
"avatar": {
|
20
|
+
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Jul/17/tutorials-avatar-1826704565-4_avatar.png"
|
21
|
+
},
|
22
|
+
"following": {
|
23
|
+
"href": "https://api.bitbucket.org/2.0/users/tutorials/following"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"created_on": "2011-12-20T16:34:07.132459+00:00",
|
27
|
+
"location": "San Francisco, CA",
|
28
|
+
"type": "user"
|
29
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Tinybucket::Api::BranchRestrictionsApi do
|
4
|
+
include ApiResponseMacros
|
5
|
+
|
6
|
+
let(:owner) { 'test_owner' }
|
7
|
+
let(:slug) { 'test_repo' }
|
8
|
+
let(:request_path) { nil }
|
9
|
+
|
10
|
+
let(:api_config) { {} }
|
11
|
+
let(:api) do
|
12
|
+
api = Tinybucket::Api::BranchRestrictionsApi.new(api_config)
|
13
|
+
api.repo_owner = owner
|
14
|
+
api.repo_slug = slug
|
15
|
+
api
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
|
19
|
+
|
20
|
+
before { stub_apiresponse(:get, request_path) if request_path }
|
21
|
+
|
22
|
+
describe '#list' do
|
23
|
+
subject { api.list }
|
24
|
+
|
25
|
+
context 'without repo_owner and repo_slug' do
|
26
|
+
let(:owner) { nil }
|
27
|
+
let(:slug) { nil }
|
28
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'without repo_owner' do
|
32
|
+
let(:owner) { nil }
|
33
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'without repo_slug' do
|
37
|
+
let(:slug) { nil }
|
38
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with repo_owner and repo_slug' do
|
42
|
+
let(:request_path) do
|
43
|
+
"/repositories/#{owner}/#{slug}/branch-restrictions"
|
44
|
+
end
|
45
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#find' do
|
50
|
+
let(:restriction_id) { '1' }
|
51
|
+
subject { api.find(restriction_id) }
|
52
|
+
|
53
|
+
context 'without repo_owner and repo_slug' do
|
54
|
+
let(:owner) { nil }
|
55
|
+
let(:slug) { nil }
|
56
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'without repo_owner' do
|
60
|
+
let(:owner) { nil }
|
61
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'without repo_slug' do
|
65
|
+
let(:slug) { nil }
|
66
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with repo_owner and repo_slug' do
|
70
|
+
let(:request_path) do
|
71
|
+
"/repositories/#{owner}/#{slug}/branch-restrictions/#{restriction_id}"
|
72
|
+
end
|
73
|
+
it 'return BranchRestriction Model' do
|
74
|
+
expect(subject).to be_an_instance_of(Tinybucket::Model::BranchRestriction)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Tinybucket::Api::CommentsApi do
|
4
|
+
include ApiResponseMacros
|
5
|
+
|
6
|
+
let(:request_path) { nil }
|
7
|
+
let(:owner) { 'test_owner' }
|
8
|
+
let(:slug) { 'test_repo' }
|
9
|
+
let(:options) { {} }
|
10
|
+
|
11
|
+
let(:commit_hash) { '1' }
|
12
|
+
let(:commit) do
|
13
|
+
m = Tinybucket::Model::Commit.new({})
|
14
|
+
m.repo_owner = owner
|
15
|
+
m.repo_slug = slug
|
16
|
+
m.hash = commit_hash
|
17
|
+
m
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:pullreq_id) { '1' }
|
21
|
+
let(:pullreq) do
|
22
|
+
m = Tinybucket::Model::PullRequest.new({})
|
23
|
+
m.repo_owner = owner
|
24
|
+
m.repo_slug = slug
|
25
|
+
m.id = pullreq_id
|
26
|
+
m
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:commented_to) { nil }
|
30
|
+
let(:api_config) { {} }
|
31
|
+
let(:api) do
|
32
|
+
api = Tinybucket::Api::CommentsApi.new(api_config)
|
33
|
+
api.repo_owner = owner
|
34
|
+
api.repo_slug = slug
|
35
|
+
api.commented_to = commented_to if commented_to.present?
|
36
|
+
api
|
37
|
+
end
|
38
|
+
|
39
|
+
it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
|
40
|
+
|
41
|
+
before { stub_apiresponse(:get, request_path) if request_path }
|
42
|
+
|
43
|
+
describe '#list' do
|
44
|
+
subject { api.list(options) }
|
45
|
+
let(:commented_to) { commit }
|
46
|
+
|
47
|
+
context 'when without owner' do
|
48
|
+
let(:owner) { nil }
|
49
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when without slug' do
|
53
|
+
let(:slug) { nil }
|
54
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when without commented_to' do
|
58
|
+
let(:commented_to) { nil }
|
59
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when with unknown commented_to' do
|
63
|
+
let(:commented_to) { {} }
|
64
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when commented_to is commit' do
|
68
|
+
let(:commented_to) { commit }
|
69
|
+
let(:request_path) do
|
70
|
+
"/repositories/#{owner}/#{slug}/commit/#{commit_hash}/comments"
|
71
|
+
end
|
72
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when commented_to is pullreq' do
|
76
|
+
let(:commented_to) { pullreq }
|
77
|
+
let(:request_path) do
|
78
|
+
"/repositories/#{owner}/#{slug}/pullrequests/#{pullreq_id}/comments"
|
79
|
+
end
|
80
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#find' do
|
85
|
+
subject { api.find(comment_id, options) }
|
86
|
+
let(:commented_to) { commit }
|
87
|
+
let(:comment_id) { '1' }
|
88
|
+
|
89
|
+
context 'when without owner' do
|
90
|
+
let(:owner) { nil }
|
91
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when without slug' do
|
95
|
+
let(:slug) { nil }
|
96
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when without commented_to' do
|
100
|
+
let(:commented_to) { nil }
|
101
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when with unknown commented_to' do
|
105
|
+
let(:commented_to) { {} }
|
106
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when commented_to is commit' do
|
110
|
+
let(:commented_to) { commit }
|
111
|
+
let(:request_path) do
|
112
|
+
"/repositories/#{owner}/#{slug}/commit/#{commit_hash}" \
|
113
|
+
"/comments/#{comment_id}"
|
114
|
+
end
|
115
|
+
it 'return Comment model' do
|
116
|
+
expect(subject).to be_an_instance_of(Tinybucket::Model::Comment)
|
117
|
+
expect(subject.commented_to).to eq(commit)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when commented_to is pull_request' do
|
122
|
+
let(:commented_to) { pullreq }
|
123
|
+
let(:request_path) do
|
124
|
+
"/repositories/#{owner}/#{slug}/pullrequests/#{pullreq_id}" \
|
125
|
+
"/comments/#{comment_id}"
|
126
|
+
end
|
127
|
+
it 'return Comment model' do
|
128
|
+
expect(subject).to be_an_instance_of(Tinybucket::Model::Comment)
|
129
|
+
expect(subject.commented_to).to eq(pullreq)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Tinybucket::Api::CommitsApi do
|
4
|
+
include ApiResponseMacros
|
5
|
+
|
6
|
+
let(:request_path) { nil }
|
7
|
+
let(:owner) { 'test_owner' }
|
8
|
+
let(:slug) { 'test_repo' }
|
9
|
+
let(:options) { {} }
|
10
|
+
|
11
|
+
let(:api_config) { {} }
|
12
|
+
let(:api) do
|
13
|
+
api = Tinybucket::Api::CommitsApi.new(api_config)
|
14
|
+
api.repo_owner = owner
|
15
|
+
api.repo_slug = slug
|
16
|
+
api
|
17
|
+
end
|
18
|
+
|
19
|
+
it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
|
20
|
+
|
21
|
+
before { stub_apiresponse(:get, request_path) if request_path }
|
22
|
+
|
23
|
+
describe 'list' do
|
24
|
+
subject { api.list(options) }
|
25
|
+
|
26
|
+
context 'without owner' do
|
27
|
+
let(:owner) { nil }
|
28
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'without slug' do
|
32
|
+
let(:slug) { nil }
|
33
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with owner and slug' do
|
37
|
+
let(:request_path) { "/repositories/#{owner}/#{slug}/commits" }
|
38
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'find' do
|
43
|
+
let(:revision) { '1' }
|
44
|
+
subject { api.find(revision, options) }
|
45
|
+
|
46
|
+
context 'without owner' do
|
47
|
+
let(:owner) { nil }
|
48
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'without slug' do
|
52
|
+
let(:slug) { nil }
|
53
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with owner and slug' do
|
57
|
+
let(:request_path) do
|
58
|
+
"/repositories/#{owner}/#{slug}/commit/#{revision}"
|
59
|
+
end
|
60
|
+
it { expect(subject).to be_instance_of(Tinybucket::Model::Commit) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Tinybucket::Api::PullRequestsApi do
|
4
|
+
include ApiResponseMacros
|
5
|
+
|
6
|
+
let(:api_config) { {} }
|
7
|
+
let(:api) do
|
8
|
+
api = Tinybucket::Api::PullRequestsApi.new(api_config)
|
9
|
+
api.repo_owner = owner
|
10
|
+
api.repo_slug = slug
|
11
|
+
api
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:owner) { 'test_owner' }
|
15
|
+
let(:slug) { 'test_repo' }
|
16
|
+
let(:request_path) { nil }
|
17
|
+
let(:request_method) { :get }
|
18
|
+
let(:stub_options) { nil }
|
19
|
+
|
20
|
+
it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
|
21
|
+
|
22
|
+
before do
|
23
|
+
if request_path
|
24
|
+
opts = stub_options.present? ? stub_options : {}
|
25
|
+
stub_apiresponse(request_method, request_path, opts)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'list' do
|
30
|
+
let(:options) { {} }
|
31
|
+
|
32
|
+
subject { api.list(options) }
|
33
|
+
|
34
|
+
context 'without repo_owner and repo_slug' do
|
35
|
+
let(:owner) { nil }
|
36
|
+
let(:slug) { nil }
|
37
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'without repo_owner' do
|
41
|
+
let(:owner) { nil }
|
42
|
+
let(:slug) { 'test_repo' }
|
43
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'without repo_slug' do
|
47
|
+
let(:owner) { 'test_owner' }
|
48
|
+
let(:slug) { nil }
|
49
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with repo_owner and repo_slug' do
|
53
|
+
let(:request_path) { "/repositories/#{owner}/#{slug}/pullrequests" }
|
54
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when request with state' do
|
58
|
+
let(:options) { { state: state } }
|
59
|
+
let(:request_path) do
|
60
|
+
"/repositories/#{owner}/#{slug}/pullrequests?state=#{state}"
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when state is OPEN' do
|
64
|
+
let(:state) { 'open' }
|
65
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when state is DECLINED' do
|
69
|
+
let(:state) { 'declined' }
|
70
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when state is MERGED' do
|
74
|
+
let(:state) { 'merged' }
|
75
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'find' do
|
81
|
+
let(:pr_id) { 1 }
|
82
|
+
subject { api.find(pr_id) }
|
83
|
+
|
84
|
+
context 'when without repo_owner and repo_slug' do
|
85
|
+
let(:owner) { nil }
|
86
|
+
let(:slug) { nil }
|
87
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when without repo_owner' do
|
91
|
+
let(:owner) { nil }
|
92
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when without repo_slug' do
|
96
|
+
let(:slug) { nil }
|
97
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when with repo_owner and repo_slug' do
|
101
|
+
let(:request_path) do
|
102
|
+
"/repositories/#{owner}/#{slug}/pullrequests/#{pr_id}"
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'return pull request model' do
|
106
|
+
expect(subject).to be_an_instance_of(Tinybucket::Model::PullRequest)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'commits' do
|
112
|
+
let(:pr_id) { 1 }
|
113
|
+
subject { api.commits(pr_id) }
|
114
|
+
|
115
|
+
context 'when without repo_owner and repo_slug' do
|
116
|
+
let(:owner) { nil }
|
117
|
+
let(:slug) { nil }
|
118
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when without repo_owner' do
|
122
|
+
let(:owner) { nil }
|
123
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'when without repo_slug' do
|
127
|
+
let(:slug) { nil }
|
128
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when with repo_owner and repo_slug' do
|
132
|
+
let(:request_path) do
|
133
|
+
"/repositories/#{owner}/#{slug}/pullrequests/1/commits"
|
134
|
+
end
|
135
|
+
it 'return page model which contains commit models' do
|
136
|
+
expect(subject).to be_an_instance_of(Tinybucket::Model::Page)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'approve' do
|
142
|
+
let(:pr_id) { 1 }
|
143
|
+
let(:request_method) { :post }
|
144
|
+
subject { api.approve(pr_id) }
|
145
|
+
|
146
|
+
context 'when without repo_owner and repo_slug' do
|
147
|
+
let(:owner) { nil }
|
148
|
+
let(:slug) { nil }
|
149
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when without repo_owner' do
|
153
|
+
let(:owner) { nil }
|
154
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when without repo_slug' do
|
158
|
+
let(:slug) { nil }
|
159
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when with repo_owner and repo_slug' do
|
163
|
+
let(:request_path) do
|
164
|
+
"/repositories/#{owner}/#{slug}/pullrequests/1/approve"
|
165
|
+
end
|
166
|
+
it { expect(subject).to be_truthy }
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'unapprove' do
|
171
|
+
let(:pr_id) { 1 }
|
172
|
+
let(:request_method) { :delete }
|
173
|
+
subject { api.unapprove(pr_id) }
|
174
|
+
|
175
|
+
context 'when without repo_owner and repo_slug' do
|
176
|
+
let(:owner) { nil }
|
177
|
+
let(:slug) { nil }
|
178
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'when without repo_owner' do
|
182
|
+
let(:owner) { nil }
|
183
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'when without repo_slug' do
|
187
|
+
let(:slug) { nil }
|
188
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when with repo_owner and repo_slug' do
|
192
|
+
let(:request_path) do
|
193
|
+
"/repositories/#{owner}/#{slug}/pullrequests/1/approve"
|
194
|
+
end
|
195
|
+
it { expect(subject).to be_truthy }
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe 'diff' do
|
200
|
+
let(:pr_id) { 1 }
|
201
|
+
subject { api.diff(pr_id) }
|
202
|
+
|
203
|
+
context 'when without repo_owner and repo_slug' do
|
204
|
+
let(:owner) { nil }
|
205
|
+
let(:slug) { nil }
|
206
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'when without repo_owner' do
|
210
|
+
let(:owner) { nil }
|
211
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'when without repo_slug' do
|
215
|
+
let(:slug) { nil }
|
216
|
+
it { expect { subject }.to raise_error(ArgumentError) }
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'when with repo_owner and repo_slug' do
|
220
|
+
let(:stub_options) do
|
221
|
+
{ content_type: 'plain/text' }
|
222
|
+
end
|
223
|
+
let(:request_path) do
|
224
|
+
"/repositories/#{owner}/#{slug}/pullrequests/1/diff"
|
225
|
+
end
|
226
|
+
it { expect(subject).to be_instance_of(String) }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|