zz_bitbucket_rest_api 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) 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 +91 -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 +55 -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 +272 -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/components.rb +36 -0
  44. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +59 -0
  45. data/lib/bitbucket_rest_api/repos/download.rb +21 -0
  46. data/lib/bitbucket_rest_api/repos/following.rb +39 -0
  47. data/lib/bitbucket_rest_api/repos/forks.rb +69 -0
  48. data/lib/bitbucket_rest_api/repos/keys.rb +88 -0
  49. data/lib/bitbucket_rest_api/repos/pull_request.rb +160 -0
  50. data/lib/bitbucket_rest_api/repos/services.rb +103 -0
  51. data/lib/bitbucket_rest_api/repos/sources.rb +39 -0
  52. data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
  53. data/lib/bitbucket_rest_api/request.rb +76 -0
  54. data/lib/bitbucket_rest_api/request/basic_auth.rb +31 -0
  55. data/lib/bitbucket_rest_api/request/jsonize.rb +46 -0
  56. data/lib/bitbucket_rest_api/request/oauth.rb +53 -0
  57. data/lib/bitbucket_rest_api/response.rb +28 -0
  58. data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
  59. data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
  60. data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
  61. data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
  62. data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
  63. data/lib/bitbucket_rest_api/result.rb +140 -0
  64. data/lib/bitbucket_rest_api/teams.rb +88 -0
  65. data/lib/bitbucket_rest_api/user.rb +101 -0
  66. data/lib/bitbucket_rest_api/users.rb +24 -0
  67. data/lib/bitbucket_rest_api/users/account.rb +53 -0
  68. data/lib/bitbucket_rest_api/utils/url.rb +56 -0
  69. data/lib/bitbucket_rest_api/validations.rb +25 -0
  70. data/lib/bitbucket_rest_api/validations/format.rb +24 -0
  71. data/lib/bitbucket_rest_api/validations/presence.rb +25 -0
  72. data/lib/bitbucket_rest_api/validations/required.rb +44 -0
  73. data/lib/bitbucket_rest_api/validations/token.rb +43 -0
  74. data/lib/bitbucket_rest_api/version.rb +11 -0
  75. data/spec/bitbucket_rest_api/api/actions_spec.rb +17 -0
  76. data/spec/bitbucket_rest_api/api_factory_spec.rb +30 -0
  77. data/spec/bitbucket_rest_api/api_spec.rb +86 -0
  78. data/spec/bitbucket_rest_api/authorization_spec.rb +72 -0
  79. data/spec/bitbucket_rest_api/client_spec.rb +16 -0
  80. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +12 -0
  81. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +49 -0
  82. data/spec/bitbucket_rest_api/deprecation_spec.rb +30 -0
  83. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +10 -0
  84. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +13 -0
  85. data/spec/bitbucket_rest_api/error/no_events_spec.rb +10 -0
  86. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  87. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  88. data/spec/bitbucket_rest_api/issues/components_spec.rb +88 -0
  89. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +88 -0
  90. data/spec/bitbucket_rest_api/issues_spec.rb +90 -0
  91. data/spec/bitbucket_rest_api/normalizer_spec.rb +30 -0
  92. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +41 -0
  93. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +43 -0
  94. data/spec/bitbucket_rest_api/repos/commits_spec.rb +20 -0
  95. data/spec/bitbucket_rest_api/repos/components_spec.rb +42 -0
  96. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +64 -0
  97. data/spec/bitbucket_rest_api/repos/download_spec.rb +9 -0
  98. data/spec/bitbucket_rest_api/repos/following_spec.rb +52 -0
  99. data/spec/bitbucket_rest_api/repos/forks_spec.rb +45 -0
  100. data/spec/bitbucket_rest_api/repos/keys_spec.rb +72 -0
  101. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +288 -0
  102. data/spec/bitbucket_rest_api/repos/sources_spec.rb +77 -0
  103. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  104. data/spec/bitbucket_rest_api/repos_spec.rb +157 -0
  105. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +18 -0
  106. data/spec/bitbucket_rest_api/request/oauth_spec.rb +27 -0
  107. data/spec/bitbucket_rest_api/request_spec.rb +81 -0
  108. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +12 -0
  109. data/spec/bitbucket_rest_api/response/mashify_spec.rb +32 -0
  110. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +41 -0
  111. data/spec/bitbucket_rest_api/teams_spec.rb +135 -0
  112. data/spec/bitbucket_rest_api/user_spec.rb +77 -0
  113. data/spec/bitbucket_rest_api/utils/url_spec.rb +33 -0
  114. data/spec/bitbucket_rest_api/validations/format_spec.rb +29 -0
  115. data/spec/bitbucket_rest_api/validations/presence_spec.rb +12 -0
  116. data/spec/bitbucket_rest_api/validations/required_spec.rb +43 -0
  117. data/spec/bitbucket_rest_api/validations/token_spec.rb +16 -0
  118. data/spec/bitbucket_rest_api_spec.rb +17 -0
  119. data/spec/spec_helper.rb +24 -0
  120. metadata +378 -0
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe BitBucket::Issues do
5
+ let(:issue) { BitBucket::Issues.new }
6
+
7
+ describe '.create' do
8
+ before do
9
+ expect(issue).to receive(:request).with(
10
+ :post,
11
+ '/1.0/repositories/mock_username/mock_repo/issues/',
12
+ { 'title' => 'mock_issue' },
13
+ {}
14
+ )
15
+ end
16
+
17
+ it 'should send a POST request to create the issue' do
18
+ issue.create('mock_username', 'mock_repo', { 'title' => 'mock_issue' })
19
+ end
20
+ end
21
+
22
+ describe '.edit' do
23
+ before do
24
+ expect(issue).to receive(:request).with(
25
+ :put,
26
+ '/1.0/repositories/mock_username/mock_repo/issues/1/',
27
+ { 'title' => 'new_title' },
28
+ {}
29
+ )
30
+ end
31
+
32
+ it 'should send a PUT request for the given issue' do
33
+ issue.edit('mock_username', 'mock_repo', 1, { 'title' => 'new_title' })
34
+ end
35
+ end
36
+
37
+ describe '.get' do
38
+ before do
39
+ expect(issue).to receive(:request).with(
40
+ :get,
41
+ '/1.0/repositories/mock_username/mock_repo/issues/1',
42
+ {},
43
+ {}
44
+ )
45
+ end
46
+
47
+ it 'should send a GET request for the given issue' do
48
+ issue.get('mock_username', 'mock_repo', 1, {})
49
+ end
50
+ end
51
+
52
+ describe '.delete' do
53
+ before do
54
+ expect(issue).to receive(:request).with(
55
+ :delete,
56
+ '/1.0/repositories/mock_username/mock_repo/issues/1',
57
+ {},
58
+ {}
59
+ )
60
+ end
61
+
62
+ it 'should send a DELETE request for the given issue' do
63
+ issue.delete('mock_username', 'mock_repo', 1)
64
+ end
65
+ end
66
+
67
+ describe '.list_repo' do
68
+ before do
69
+ expect(issue).to receive(:request).with(
70
+ :get,
71
+ '/1.0/repositories/mock_username/mock_repo/issues',
72
+ {},
73
+ {}
74
+ ).and_return(OpenStruct.new(:issues => [])).twice
75
+ end
76
+
77
+ it 'should send a GET request for the issues for that repo' do
78
+ issue.list_repo('mock_username', 'mock_repo')
79
+ issue.list_repo('mock_username', 'mock_repo') { |issue| issue }
80
+ end
81
+ end
82
+
83
+ describe "getter methods" do
84
+ it "returns an object of the correct class" do
85
+ expect(issue.comments).to be_a BitBucket::Issues::Comments
86
+ expect(issue.components).to be_a BitBucket::Issues::Components
87
+ expect(issue.milestones).to be_a BitBucket::Issues::Milestones
88
+ end
89
+ end
90
+ end
@@ -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
+ '/1.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
+ '/1.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,42 @@
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
@@ -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
+ '/1.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
+ '/1.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
+ '/1.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