bitbucket_rest_api2 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +7 -0
  3. data/README.md +169 -0
  4. data/lib/bitbucket_rest_api.rb +90 -0
  5. data/lib/bitbucket_rest_api/api.rb +106 -0
  6. data/lib/bitbucket_rest_api/api/actions.rb +35 -0
  7. data/lib/bitbucket_rest_api/api_factory.rb +30 -0
  8. data/lib/bitbucket_rest_api/authorization.rb +34 -0
  9. data/lib/bitbucket_rest_api/client.rb +56 -0
  10. data/lib/bitbucket_rest_api/configuration.rb +106 -0
  11. data/lib/bitbucket_rest_api/connection.rb +98 -0
  12. data/lib/bitbucket_rest_api/constants.rb +58 -0
  13. data/lib/bitbucket_rest_api/core_ext/array.rb +7 -0
  14. data/lib/bitbucket_rest_api/core_ext/hash.rb +46 -0
  15. data/lib/bitbucket_rest_api/deprecation.rb +39 -0
  16. data/lib/bitbucket_rest_api/error.rb +38 -0
  17. data/lib/bitbucket_rest_api/error/bad_events.rb +9 -0
  18. data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
  19. data/lib/bitbucket_rest_api/error/blank_value.rb +9 -0
  20. data/lib/bitbucket_rest_api/error/client_error.rb +20 -0
  21. data/lib/bitbucket_rest_api/error/forbidden.rb +12 -0
  22. data/lib/bitbucket_rest_api/error/internal_server_error.rb +12 -0
  23. data/lib/bitbucket_rest_api/error/invalid_options.rb +18 -0
  24. data/lib/bitbucket_rest_api/error/no_events.rb +9 -0
  25. data/lib/bitbucket_rest_api/error/not_found.rb +12 -0
  26. data/lib/bitbucket_rest_api/error/required_params.rb +18 -0
  27. data/lib/bitbucket_rest_api/error/service_error.rb +19 -0
  28. data/lib/bitbucket_rest_api/error/service_unavailable.rb +12 -0
  29. data/lib/bitbucket_rest_api/error/unauthorized.rb +12 -0
  30. data/lib/bitbucket_rest_api/error/unknown_value.rb +18 -0
  31. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +12 -0
  32. data/lib/bitbucket_rest_api/error/validations.rb +18 -0
  33. data/lib/bitbucket_rest_api/invitations.rb +15 -0
  34. data/lib/bitbucket_rest_api/issues.rb +230 -0
  35. data/lib/bitbucket_rest_api/issues/comments.rb +118 -0
  36. data/lib/bitbucket_rest_api/issues/components.rb +106 -0
  37. data/lib/bitbucket_rest_api/issues/milestones.rb +107 -0
  38. data/lib/bitbucket_rest_api/normalizer.rb +27 -0
  39. data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
  40. data/lib/bitbucket_rest_api/repos.rb +264 -0
  41. data/lib/bitbucket_rest_api/repos/changesets.rb +54 -0
  42. data/lib/bitbucket_rest_api/repos/commits.rb +40 -0
  43. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +59 -0
  44. data/lib/bitbucket_rest_api/repos/download.rb +21 -0
  45. data/lib/bitbucket_rest_api/repos/following.rb +39 -0
  46. data/lib/bitbucket_rest_api/repos/forks.rb +69 -0
  47. data/lib/bitbucket_rest_api/repos/keys.rb +87 -0
  48. data/lib/bitbucket_rest_api/repos/pull_request.rb +160 -0
  49. data/lib/bitbucket_rest_api/repos/services.rb +103 -0
  50. data/lib/bitbucket_rest_api/repos/sources.rb +39 -0
  51. data/lib/bitbucket_rest_api/repos/webhooks.rb +96 -0
  52. data/lib/bitbucket_rest_api/request.rb +76 -0
  53. data/lib/bitbucket_rest_api/request/basic_auth.rb +31 -0
  54. data/lib/bitbucket_rest_api/request/jsonize.rb +46 -0
  55. data/lib/bitbucket_rest_api/request/oauth.rb +53 -0
  56. data/lib/bitbucket_rest_api/response.rb +28 -0
  57. data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
  58. data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
  59. data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
  60. data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
  61. data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
  62. data/lib/bitbucket_rest_api/result.rb +140 -0
  63. data/lib/bitbucket_rest_api/user.rb +101 -0
  64. data/lib/bitbucket_rest_api/users.rb +24 -0
  65. data/lib/bitbucket_rest_api/users/account.rb +53 -0
  66. data/lib/bitbucket_rest_api/utils/url.rb +56 -0
  67. data/lib/bitbucket_rest_api/validations.rb +25 -0
  68. data/lib/bitbucket_rest_api/validations/format.rb +24 -0
  69. data/lib/bitbucket_rest_api/validations/presence.rb +25 -0
  70. data/lib/bitbucket_rest_api/validations/required.rb +44 -0
  71. data/lib/bitbucket_rest_api/validations/token.rb +43 -0
  72. data/lib/bitbucket_rest_api/version.rb +11 -0
  73. data/spec/bitbucket_rest_api/api/actions_spec.rb +17 -0
  74. data/spec/bitbucket_rest_api/api_factory_spec.rb +30 -0
  75. data/spec/bitbucket_rest_api/api_spec.rb +86 -0
  76. data/spec/bitbucket_rest_api/authorization_spec.rb +72 -0
  77. data/spec/bitbucket_rest_api/client_spec.rb +15 -0
  78. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +12 -0
  79. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +49 -0
  80. data/spec/bitbucket_rest_api/deprecation_spec.rb +30 -0
  81. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +10 -0
  82. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +13 -0
  83. data/spec/bitbucket_rest_api/error/no_events_spec.rb +10 -0
  84. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  85. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  86. data/spec/bitbucket_rest_api/issues/components_spec.rb +88 -0
  87. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +88 -0
  88. data/spec/bitbucket_rest_api/issues_spec.rb +90 -0
  89. data/spec/bitbucket_rest_api/normalizer_spec.rb +30 -0
  90. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +41 -0
  91. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +43 -0
  92. data/spec/bitbucket_rest_api/repos/commits_spec.rb +20 -0
  93. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +64 -0
  94. data/spec/bitbucket_rest_api/repos/download_spec.rb +9 -0
  95. data/spec/bitbucket_rest_api/repos/following_spec.rb +52 -0
  96. data/spec/bitbucket_rest_api/repos/forks_spec.rb +45 -0
  97. data/spec/bitbucket_rest_api/repos/keys_spec.rb +72 -0
  98. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +288 -0
  99. data/spec/bitbucket_rest_api/repos/sources_spec.rb +77 -0
  100. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  101. data/spec/bitbucket_rest_api/repos_spec.rb +157 -0
  102. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +18 -0
  103. data/spec/bitbucket_rest_api/request/oauth_spec.rb +27 -0
  104. data/spec/bitbucket_rest_api/request_spec.rb +81 -0
  105. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +12 -0
  106. data/spec/bitbucket_rest_api/response/mashify_spec.rb +32 -0
  107. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +41 -0
  108. data/spec/bitbucket_rest_api/user_spec.rb +77 -0
  109. data/spec/bitbucket_rest_api/utils/url_spec.rb +33 -0
  110. data/spec/bitbucket_rest_api/validations/format_spec.rb +29 -0
  111. data/spec/bitbucket_rest_api/validations/presence_spec.rb +12 -0
  112. data/spec/bitbucket_rest_api/validations/required_spec.rb +43 -0
  113. data/spec/bitbucket_rest_api/validations/token_spec.rb +16 -0
  114. data/spec/bitbucket_rest_api_spec.rb +17 -0
  115. data/spec/spec_helper.rb +24 -0
  116. metadata +373 -0
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'bitbucket_rest_api/core_ext/hash'
5
+
6
+ describe BitBucket::Normalizer, '#normalize!' do
7
+ let(:hash) { { 'a' => { :b => { 'c' => 1 }, 'd' => ['a', { :e => 2 }] } } }
8
+
9
+ let(:klass) do
10
+ Class.new do
11
+ include BitBucket::Normalizer
12
+ end
13
+ end
14
+
15
+ subject(:instance) { klass.new }
16
+
17
+ context '#normalize!' do
18
+ it 'converts hash keys to string' do
19
+ ['a', 'b', 'c'].each do |key|
20
+ expect(subject.normalize!(hash).has_deep_key?(key)).to eq(true)
21
+ end
22
+ end
23
+
24
+ it 'should stringify all the keys inside nested hash' do
25
+ actual = subject.normalize! hash
26
+ expected = { 'a' => { 'b'=> { 'c' => 1 }, 'd' => ['a', { 'e'=> 2 }] } }
27
+ expect(actual).to eq expected
28
+ end
29
+ end
30
+ end # BitBucket::Normalizer
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'bitbucket_rest_api/core_ext/hash'
3
+
4
+ describe BitBucket::ParameterFilter, '#filter!' do
5
+ let(:hash) { { :a => { :b => { :c => 1 } } } }
6
+ let(:array) { [{ :a => { :b => { :c => 1 } } }, {d: {e: 2}}] }
7
+
8
+ let(:klass) {
9
+ Class.new do
10
+ include BitBucket::ParameterFilter
11
+ end
12
+ }
13
+
14
+ subject(:instance) { klass.new }
15
+
16
+ it 'removes unwanted keys from hash' do
17
+ instance.filter!([:a], hash)
18
+ expect(hash.has_deep_key?(:a)).to eq(true)
19
+ expect(hash.has_deep_key?(:b)).to eq(false)
20
+ expect(hash.has_deep_key?(:c)).to eq(false)
21
+ end
22
+
23
+ it 'removes unwanted keys from array of hashes' do
24
+ instance.filter!([:a, :d], array)
25
+ expect(array[0].has_deep_key?(:a)).to eq(true)
26
+ expect(array[0].has_deep_key?(:b)).to eq(false)
27
+ expect(array[0].has_deep_key?(:c)).to eq(false)
28
+ expect(array[1].has_deep_key?(:d)).to eq(true)
29
+ expect(array[1].has_deep_key?(:e)).to eq(false)
30
+ end
31
+
32
+ it 'recursively filters inputs tree' do
33
+ instance.filter!([:a, :b], hash)
34
+ expect(hash.has_deep_key?(:c)).to eq(false)
35
+ end
36
+
37
+ it 'filters inputs tree only on top level' do
38
+ instance.filter!([:a, :b], hash, :recursive => false)
39
+ expect(hash.has_deep_key?(:c)).to eq(true)
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Changesets do
4
+ let(:changesets) { BitBucket::Repos::Changesets.new }
5
+
6
+ describe '.list' do
7
+ before do
8
+ expect(changesets).to receive(:request).with(
9
+ :get,
10
+ '/2.0/repositories/mock_username/mock_repo/changesets',
11
+ {},
12
+ {}
13
+ ).and_return(['changset1', 'changeset2', 'changeset3'])
14
+ end
15
+
16
+ context 'without a block' do
17
+ it 'should send a GET request for the changesets belonging to the given repo' do
18
+ changesets.list('mock_username', 'mock_repo')
19
+ end
20
+ end
21
+
22
+ context 'with a block' do
23
+ it 'should send a GET request for the changesets belonging to the given repo' do
24
+ changesets.list('mock_username', 'mock_repo') { |changeset| changeset }
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '.get' do
30
+ before do
31
+ expect(changesets).to receive(:request).with(
32
+ :get,
33
+ '/2.0/repositories/mock_username/mock_repo/changesets/test_sha',
34
+ {},
35
+ {}
36
+ )
37
+ end
38
+
39
+ it 'should send a GET request for a particular changeset belonging to the given repo' do
40
+ changesets.get('mock_username', 'mock_repo', 'test_sha')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Commits do
4
+ let(:commits) { BitBucket::Repos::Commits.new }
5
+
6
+ describe '.list' do
7
+ before do
8
+ expect(commits).to receive(:request).with(
9
+ :get,
10
+ '/2.0/repositories/mock_username/mock_repo/commits',
11
+ {},
12
+ {}
13
+ )
14
+ end
15
+
16
+ it 'should send a GET request for the commits belonging to the given repo' do
17
+ commits.list('mock_username', 'mock_repo')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::DefaultReviewers 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/default-reviewers',
10
+ {},
11
+ {}
12
+ )
13
+ end
14
+
15
+ it 'makes a GET request for all default reviewers belonging to the repo' do
16
+ subject.list('mock_user', 'mock_repo')
17
+ end
18
+ end
19
+
20
+ describe '#get' do
21
+ before do
22
+ expect(subject).to receive(:request).with(
23
+ :get,
24
+ '/2.0/repositories/mock_user/mock_repo/default-reviewers/mock_reviewer',
25
+ {},
26
+ {}
27
+ )
28
+ end
29
+
30
+ it 'makes a GET request for a default reviewer by username' do
31
+ subject.get('mock_user', 'mock_repo', 'mock_reviewer')
32
+ end
33
+ end
34
+
35
+ describe '#add' do
36
+ before do
37
+ expect(subject).to receive(:request).with(
38
+ :put,
39
+ '/2.0/repositories/mock_user/mock_repo/default-reviewers/mock_reviewer',
40
+ {},
41
+ {}
42
+ )
43
+ end
44
+
45
+ it 'makes a PUT request to add the new reviewer to the default reviewers list' do
46
+ subject.add('mock_user', 'mock_repo', 'mock_reviewer')
47
+ end
48
+ end
49
+
50
+ describe '#remove' do
51
+ before do
52
+ expect(subject).to receive(:request).with(
53
+ :delete,
54
+ '/2.0/repositories/mock_user/mock_repo/default-reviewers/mock_reviewer',
55
+ {},
56
+ {}
57
+ )
58
+ end
59
+
60
+ it 'makes a DELETE request to remove a reviewer from the list' do
61
+ subject.remove('mock_user', 'mock_repo', 'mock_reviewer')
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Download do
4
+ describe '.get' do
5
+ it 'should send a GET request for the download link for the given repo' do
6
+ skip 'this is a regression test and the method is not finished being written'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Following do
4
+ let(:following) { BitBucket::Repos::Following.new }
5
+
6
+ describe '.followers' do
7
+ before do
8
+ expect(following).to receive(:request).with(
9
+ :get,
10
+ '/2.0/repositories/mock_username/mock_repo/followers/',
11
+ {},
12
+ {}
13
+ ).and_return(['follower1', 'follower2', 'follower3'])
14
+ end
15
+
16
+ context 'without a block' do
17
+ it 'should send a GET request for the followers belonging to the given repo' do
18
+ following.followers('mock_username', 'mock_repo')
19
+ end
20
+ end
21
+
22
+ context 'with a block' do
23
+ it 'should send a GET request for the followers belonging to the given repo' do
24
+ following.followers('mock_username', 'mock_repo') { |follower| follower }
25
+ end
26
+ end
27
+ end
28
+
29
+ # TODO: implement this method in the User class where it belongs
30
+ describe '.followed' do
31
+ before do
32
+ expect(following).to receive(:request).with(
33
+ :get,
34
+ '/2.0/user/follows',
35
+ {},
36
+ {}
37
+ ).and_return(['followed1', 'followed2', 'followed3'])
38
+ end
39
+
40
+ context 'without a block' do
41
+ it 'should send a GET request for the followers belonging to a particular user' do
42
+ following.followed
43
+ end
44
+ end
45
+
46
+ context 'with a block' do
47
+ it 'should send a GET request for the followers belonging to a particular user' do
48
+ following.followed { |followed| followed }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Forks do
4
+ let(:forks) { BitBucket::Repos::Forks.new }
5
+
6
+ describe '.list' do
7
+ before do
8
+ expect(forks).to receive(:request).with(
9
+ :get,
10
+ '/2.0/repositories/mock_username/mock_repo/forks/',
11
+ {},
12
+ {}
13
+ ).and_return(['fork1', 'fork2', 'fork3'])
14
+ end
15
+
16
+ context 'without a block' do
17
+ it 'sends a GET request for the forks of the given repo' do
18
+ forks.list('mock_username', 'mock_repo')
19
+ end
20
+ end
21
+
22
+ context 'with a block' do
23
+ it 'sends a GET request for the forks of the given repo' do
24
+ forks.list('mock_username', 'mock_repo') { |fork| fork }
25
+ end
26
+ end
27
+ end
28
+
29
+ # TODO: make sure this is documented in the README since it is not so
30
+ # in the official API docs
31
+ describe '.create' do
32
+ before do
33
+ expect(forks).to receive(:request).with(
34
+ :post,
35
+ '/2.0/repositories/mock_username/mock_repo/fork',
36
+ { 'name' => 'mock_fork_name'},
37
+ {}
38
+ )
39
+ end
40
+
41
+ it 'should send a POST request to create a fork of the given repo' do
42
+ forks.create('mock_username', 'mock_repo', { 'name' => 'mock_fork_name' })
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Keys do
4
+ let(:deploy_keys) { described_class.new }
5
+ describe '.list' do
6
+ before do
7
+ expect(deploy_keys).to receive(:request).with(
8
+ :get,
9
+ '/2.0/repositories/mock_username/mock_repo/deploy-keys/',
10
+ {},
11
+ {}
12
+ ).and_return(['key1', 'key2', 'key3'])
13
+ end
14
+
15
+ context 'without a block' do
16
+ it 'should make a GET request for the deploy keys belonging to the given repo' do
17
+ deploy_keys.list('mock_username', 'mock_repo')
18
+ end
19
+ end
20
+
21
+ context 'with a block' do
22
+ it 'should make a GET request for the deploy keys belonging to the given repo' do
23
+ deploy_keys.list('mock_username', 'mock_repo') { |key| key }
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '.create' do
29
+ before do
30
+ expect(deploy_keys).to receive(:request).with(
31
+ :post,
32
+ '/2.0/repositories/mock_username/mock_repo/deploy-keys/',
33
+ { 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
34
+ {}
35
+ )
36
+ end
37
+
38
+ it 'should make a POST request for the deploy keys belonging to the given repo' do
39
+ deploy_keys.create('mock_username', 'mock_repo', { key: 'mock_ssh_key', label: 'mock_label' })
40
+ end
41
+ end
42
+
43
+ describe '.edit' do
44
+ before do
45
+ expect(deploy_keys).to receive(:request).with(
46
+ :put,
47
+ '/2.0/repositories/mock_username/mock_repo/deploy-keys/1',
48
+ { 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
49
+ {}
50
+ )
51
+ end
52
+
53
+ it 'should make a PUT request for the deploy keys belonging to the given repo' do
54
+ deploy_keys.edit('mock_username', 'mock_repo', 1, { key: 'mock_ssh_key', label: 'mock_label' })
55
+ end
56
+ end
57
+
58
+ describe '.delete' do
59
+ before do
60
+ expect(deploy_keys).to receive(:request).with(
61
+ :delete,
62
+ '/2.0/repositories/mock_username/mock_repo/deploy-keys/mock_id',
63
+ { 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
64
+ {}
65
+ )
66
+ end
67
+
68
+ it 'should make a DELETE request for the deploy keys belonging to the given repo' do
69
+ deploy_keys.delete('mock_username', 'mock_repo', 'mock_id', { key: 'mock_ssh_key', label: 'mock_label' })
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,288 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::PullRequest 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/pullrequests',
10
+ {},
11
+ {}
12
+ ).and_return(['pr1', 'pr2', 'pr3'])
13
+ end
14
+
15
+ context 'without a block' do
16
+ it 'makes a GET request for all pull requests belonging to the repo' 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 pull requests belonging to the repo' do
23
+ subject.list('mock_user', 'mock_repo') { |pr| pr }
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#participants' do
29
+ before do
30
+ expect(subject).to receive(:request).with(
31
+ :get,
32
+ "/2.0/repositories/mock_user/mock_repo/pullrequests/mock_pull_request_id/participants",
33
+ {},
34
+ {}
35
+ ).and_return(['participant1', 'participant2', 'participant3'])
36
+ end
37
+
38
+ context 'without a block' do
39
+ it 'makes a GET request for all participants belonging to the repo' do
40
+ subject.participants('mock_user', 'mock_repo', 'mock_pull_request_id')
41
+ end
42
+ end
43
+
44
+ context 'with a block' do
45
+ it 'makes a GET request for all participants belonging to the repo' do
46
+ subject.participants('mock_user', 'mock_repo', 'mock_pull_request_id') { |p| p }
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#get' do
52
+ before do
53
+ expect(subject).to receive(:request).with(
54
+ :get,
55
+ "/2.0/repositories/mock_user/mock_repo/pullrequests/mock_pull_request_id",
56
+ {}
57
+ )
58
+ end
59
+
60
+ it 'makes a GET request for the pull request belonging to the repo' do
61
+ subject.get('mock_user', 'mock_repo', 'mock_pull_request_id')
62
+ end
63
+ end
64
+
65
+ describe '#create' do
66
+ before do
67
+ @params = {
68
+ title: "mock_pr_title",
69
+ description: "mock_pull_request_description",
70
+ source: {
71
+ branch: {
72
+ name: "mock_source_branch_name"
73
+ },
74
+ repository: {
75
+ full_name: "mock_owner/mock_repo"
76
+ }
77
+ },
78
+ destination: {
79
+ branch: {
80
+ name: "mock_destination_branch_name"
81
+ },
82
+ commit: {
83
+ hash: "mock_uuid"
84
+ }
85
+ },
86
+ close_source_branch: true
87
+ }
88
+ end
89
+
90
+ it 'makes a POST request to create a new pull request' do
91
+ expect(subject).to receive(:request).with(
92
+ :post,
93
+ '/2.0/repositories/mock_user/mock_repo/pullrequests',
94
+ @params
95
+ )
96
+
97
+ subject.create('mock_user', 'mock_repo', @params)
98
+ end
99
+
100
+ it 'validates presence of required params' do
101
+ expect do
102
+ subject.create(
103
+ 'mock_user',
104
+ 'mock_repo',
105
+ {
106
+ title: "",
107
+ description: "mock_pull_request_description",
108
+ source: {
109
+ branch: {
110
+ name: "mock_source_branch_name"
111
+ },
112
+ repository: {
113
+ full_name: "mock_owner/mock_repo"
114
+ }
115
+ },
116
+ destination: {
117
+ branch: {
118
+ name: "mock_destination_branch_name"
119
+ },
120
+ commit: {
121
+ hash: "mock_uuid"
122
+ }
123
+ },
124
+ close_source_branch: true
125
+ }
126
+ )
127
+ end.to raise_error
128
+ end
129
+ end
130
+
131
+ describe '.put' do
132
+ before do
133
+ expect(subject).to receive(:request).with(
134
+ :put,
135
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id',
136
+ {}
137
+ )
138
+ end
139
+
140
+ it 'makes a PUT request for the given pull request' do
141
+ subject.update('mock_user', 'mock_repo', 'mock_id')
142
+ end
143
+ end
144
+
145
+ describe '.commits' do
146
+ before do
147
+ expect(subject).to receive(:request).with(
148
+ :get,
149
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/commits',
150
+ {}
151
+ )
152
+ end
153
+
154
+ it 'makes a GET request for the commits' do
155
+ subject.commits('mock_user', 'mock_repo', 'mock_id')
156
+ end
157
+ end
158
+
159
+ describe '.commits' do
160
+ before do
161
+ expect(subject).to receive(:request).with(
162
+ :post,
163
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/approve',
164
+ {}
165
+ )
166
+ end
167
+
168
+ it 'makes a POST request' do
169
+ subject.approve('mock_user', 'mock_repo', 'mock_id')
170
+ end
171
+ end
172
+
173
+ describe '.delete_approval' do
174
+ before do
175
+ expect(subject).to receive(:request).with(
176
+ :delete,
177
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/approve',
178
+ {}
179
+ )
180
+ end
181
+
182
+ it 'makes a DELTE request' do
183
+ subject.delete_approval('mock_user', 'mock_repo', 'mock_id')
184
+ end
185
+ end
186
+
187
+
188
+ describe '.diff' do
189
+ before do
190
+ expect(subject).to receive(:request).with(
191
+ :get,
192
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/diff',
193
+ {}
194
+ )
195
+ end
196
+
197
+ it 'makes a GET request for the diff of the pull request' do
198
+ subject.diff('mock_user', 'mock_repo', 'mock_id')
199
+ end
200
+ end
201
+
202
+ describe '.all_activity' do
203
+ before do
204
+ expect(subject).to receive(:request).with(
205
+ :get,
206
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/activity',
207
+ {}
208
+ )
209
+ end
210
+
211
+ it 'makes a GET request' do
212
+ subject.all_activity('mock_user', 'mock_repo')
213
+ end
214
+ end
215
+
216
+
217
+ describe '.activity' do
218
+ before do
219
+ expect(subject).to receive(:request).with(
220
+ :get,
221
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/activity',
222
+ {}
223
+ )
224
+ end
225
+
226
+ it 'makes a GET request' do
227
+ subject.activity('mock_user', 'mock_repo', 'mock_id')
228
+ end
229
+ end
230
+
231
+
232
+ describe '.accept_and_merge' do
233
+ before do
234
+ expect(subject).to receive(:request).with(
235
+ :post,
236
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/merge',
237
+ {}
238
+ )
239
+ end
240
+
241
+ it 'makes a POST request' do
242
+ subject.merge('mock_user', 'mock_repo', 'mock_id')
243
+ end
244
+ end
245
+
246
+ describe '.decline' do
247
+ before do
248
+ expect(subject).to receive(:request).with(
249
+ :post,
250
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/decline',
251
+ {}
252
+ )
253
+ end
254
+
255
+ it 'makes a POST request' do
256
+ subject.decline('mock_user', 'mock_repo', 'mock_id')
257
+ end
258
+ end
259
+
260
+
261
+ describe '.comments' do
262
+ before do
263
+ expect(subject).to receive(:request).with(
264
+ :get,
265
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/comments',
266
+ {}
267
+ )
268
+ end
269
+
270
+ it 'makes a GET request' do
271
+ subject.comments('mock_user', 'mock_repo', 'mock_id')
272
+ end
273
+ end
274
+
275
+ describe '.comment' do
276
+ before do
277
+ expect(subject).to receive(:request).with(
278
+ :get,
279
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/comments/comment_id',
280
+ {}
281
+ )
282
+ end
283
+
284
+ it 'makes a GET request' do
285
+ subject.comment('mock_user', 'mock_repo', 'mock_id', 'comment_id')
286
+ end
287
+ end
288
+ end