tinybucket 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -5
  3. data/README.md +100 -24
  4. data/lib/tinybucket.rb +1 -0
  5. data/lib/tinybucket/api.rb +1 -0
  6. data/lib/tinybucket/api/build_status_api.rb +55 -0
  7. data/lib/tinybucket/api/helper.rb +1 -0
  8. data/lib/tinybucket/api/helper/build_status_helper.rb +35 -0
  9. data/lib/tinybucket/client.rb +28 -45
  10. data/lib/tinybucket/enumerator.rb +4 -3
  11. data/lib/tinybucket/model.rb +2 -1
  12. data/lib/tinybucket/model/base.rb +1 -17
  13. data/lib/tinybucket/model/build_status.rb +55 -0
  14. data/lib/tinybucket/model/commit.rb +32 -15
  15. data/lib/tinybucket/model/concerns.rb +1 -0
  16. data/lib/tinybucket/model/concerns/api_callable.rb +19 -0
  17. data/lib/tinybucket/model/profile.rb +9 -26
  18. data/lib/tinybucket/model/pull_request.rb +18 -28
  19. data/lib/tinybucket/model/repository.rb +29 -76
  20. data/lib/tinybucket/model/team.rb +9 -34
  21. data/lib/tinybucket/parser.rb +1 -0
  22. data/lib/tinybucket/parser/build_status_parser.rb +9 -0
  23. data/lib/tinybucket/resource.rb +70 -0
  24. data/lib/tinybucket/resource/base.rb +29 -0
  25. data/lib/tinybucket/resource/branch_restrictions.rb +45 -0
  26. data/lib/tinybucket/resource/commit/base.rb +12 -0
  27. data/lib/tinybucket/resource/commit/build_statuses.rb +47 -0
  28. data/lib/tinybucket/resource/commit/comments.rb +32 -0
  29. data/lib/tinybucket/resource/commits.rb +33 -0
  30. data/lib/tinybucket/resource/forks.rb +22 -0
  31. data/lib/tinybucket/resource/pull_request/base.rb +18 -0
  32. data/lib/tinybucket/resource/pull_request/comments.rb +30 -0
  33. data/lib/tinybucket/resource/pull_request/commits.rb +17 -0
  34. data/lib/tinybucket/resource/pull_requests.rb +48 -0
  35. data/lib/tinybucket/resource/repos.rb +38 -0
  36. data/lib/tinybucket/resource/team/base.rb +22 -0
  37. data/lib/tinybucket/resource/team/followers.rb +13 -0
  38. data/lib/tinybucket/resource/team/following.rb +13 -0
  39. data/lib/tinybucket/resource/team/members.rb +13 -0
  40. data/lib/tinybucket/resource/team/repos.rb +13 -0
  41. data/lib/tinybucket/resource/user/base.rb +24 -0
  42. data/lib/tinybucket/resource/user/followers.rb +13 -0
  43. data/lib/tinybucket/resource/user/following.rb +13 -0
  44. data/lib/tinybucket/resource/user/repos.rb +13 -0
  45. data/lib/tinybucket/resource/watchers.rb +22 -0
  46. data/lib/tinybucket/version.rb +1 -1
  47. data/spec/fixtures/build_status.json +16 -0
  48. data/spec/fixtures/repositories/test_owner/get.json +1 -1
  49. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json +16 -0
  50. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json +16 -0
  51. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json +16 -0
  52. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +1 -1
  53. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +1 -1
  54. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +1 -1
  55. data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +1 -1
  56. data/spec/lib/tinybucket/api/build_status_api_spec.rb +65 -0
  57. data/spec/lib/tinybucket/client_spec.rb +8 -4
  58. data/spec/lib/tinybucket/model/build_status_spec.rb +66 -0
  59. data/spec/lib/tinybucket/model/commit_spec.rb +19 -1
  60. data/spec/lib/tinybucket/model/profile_spec.rb +3 -3
  61. data/spec/lib/tinybucket/model/pull_request_spec.rb +3 -15
  62. data/spec/lib/tinybucket/model/repository_spec.rb +14 -20
  63. data/spec/lib/tinybucket/model/team_spec.rb +16 -4
  64. data/spec/lib/tinybucket/resource/branch_restrictions_spec.rb +60 -0
  65. data/spec/lib/tinybucket/resource/commit/build_statuses_spec.rb +50 -0
  66. data/spec/lib/tinybucket/resource/commit/comments_spec.rb +49 -0
  67. data/spec/lib/tinybucket/resource/commits_spec.rb +43 -0
  68. data/spec/lib/tinybucket/resource/forks_spec.rb +36 -0
  69. data/spec/lib/tinybucket/resource/pull_request/comments_spec.rb +41 -0
  70. data/spec/lib/tinybucket/resource/pull_request/commits_spec.rb +41 -0
  71. data/spec/lib/tinybucket/resource/pull_requests_spec.rb +59 -0
  72. data/spec/lib/tinybucket/resource/repos_spec.rb +76 -0
  73. data/spec/lib/tinybucket/resource/team/followers_spec.rb +27 -0
  74. data/spec/lib/tinybucket/resource/team/following_spec.rb +27 -0
  75. data/spec/lib/tinybucket/resource/team/members_spec.rb +27 -0
  76. data/spec/lib/tinybucket/resource/team/repos_spec.rb +27 -0
  77. data/spec/lib/tinybucket/resource/user/followers_spec.rb +27 -0
  78. data/spec/lib/tinybucket/resource/user/following_spec.rb +27 -0
  79. data/spec/lib/tinybucket/resource/user/repos_spec.rb +27 -0
  80. data/spec/lib/tinybucket/resource/watchers_spec.rb +38 -0
  81. data/spec/support/api_response_macros.rb +45 -1
  82. metadata +77 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d596d1229598dd3fc84210c64d68b7e2f133986
4
- data.tar.gz: 1c9b5eeced1f04ec09f0be85ffa07306f6ee60ef
3
+ metadata.gz: 7c36e731063e026b4a9765820e9c2af76d614b37
4
+ data.tar.gz: 6c751c8bde9a75fd7bb43b82e25f9f291c711e5f
5
5
  SHA512:
6
- metadata.gz: 09ee886f336681f0b0b9e0b734899334b4589ce28cd8dc43989a726d0afca94bc9ede953e413c3887e450836d79169eefc4aab82df587210c749bf9cb1ec3fca
7
- data.tar.gz: 29a5525a8133c69414e3e7023d6c73213979bdad3544b4b0fc3b4a121a1f597a9f697ef001affbed0c668817c3804898e5ff5898a13357c6915e46a1e30975ff
6
+ metadata.gz: 932cbe0ffb529644bd277f0efe6d9e8fba47b37069aa3eb9ed8cf9c1b744717ebde8f6ed844e4c1ce55a5154829216365b137afffc52a30781ba02f9c3edb20c
7
+ data.tar.gz: 3145f50edc5ca01591945a5055ad14059afab8be2909f1d16213f23ea7dc35357d477d68b8c1fa7bb0e99ffff7f5ca26aa1a37e3be45a72b9c58a61723d78127
data/.gitignore CHANGED
@@ -22,11 +22,6 @@ features
22
22
  /pkg/
23
23
  /tmp/
24
24
 
25
- ## Specific to RubyMotion:
26
- .dat*
27
- .repl_history
28
- build/
29
-
30
25
  ## Documentation cache and generated files:
31
26
  /.yardoc/
32
27
  /_yardoc/
data/README.md CHANGED
@@ -134,6 +134,17 @@ repos = bucket.repos('someone')
134
134
 
135
135
  ##### repository Resource
136
136
 
137
+ ###### Collection Methods
138
+
139
+ ```ruby
140
+ repos = bucket.repos('myname')
141
+
142
+ # [ ] POST a new repository
143
+ repos.create(params)
144
+ ```
145
+
146
+ ###### Object Methods
147
+
137
148
  ```ruby
138
149
  # [x] GET a repository
139
150
  repo = bucket.repo('someone', 'great_repo')
@@ -142,11 +153,8 @@ repo = bucket.repo('someone', 'great_repo')
142
153
  # (Load the repository attributes from Bitbucket WebAPI)
143
154
  repo.load
144
155
 
145
- # [ ] POST a new repository
146
- repo.create(params)
147
-
148
156
  # [ ] DELETE a repository
149
- repo.destroy
157
+ repo.destroy
150
158
 
151
159
  # [x] GET a list of watchers
152
160
  watchers = repo.watchers
@@ -157,44 +165,52 @@ repos = repo.forks
157
165
 
158
166
  ##### pullrequests Resource
159
167
 
168
+ ###### Collection Methods
169
+
160
170
  ```ruby
161
171
  repo = bucket.repo('someone', 'great_repo')
162
172
 
163
- # [x] GET a list of open pull requests
173
+ # [x ] GET a list of pull requests
164
174
  pull_requests = repo.pull_requests(options)
165
175
 
166
- # [x] GET a specific pull request
167
- pull_request = repo.pull_request(pr_id)
168
-
169
176
  # [ ] POST (create) a new pull request
170
- repo.pull_request.create(params)
177
+ pull_requests.create(params)
178
+
179
+ # [ ] GET the log of all of a repository's pull request activity
180
+ activities = pull_requests.activities(options)
181
+ ```
182
+
183
+ ###### Object Methods
184
+
185
+ ```ruby
186
+ repo = bucket.repo('someone', 'great_repo')
187
+
188
+ # [x] GET a specific pull request
189
+ pull_request = repo.pull_request(pr_id)
171
190
 
172
191
  # [ ] PUT a pull request update
173
- repo.pull_request(pr_id).update(params)
192
+ pull_request.update(params)
174
193
 
175
194
  # [x] GET the commits for a pull request
176
195
  commits = pull_request.commits
177
196
 
178
197
  # [x] POST a pull request approval
179
- pull_request.approve
198
+ pull_request.approve
180
199
 
181
200
  # [x] DELETE a pull request approval
182
- pull_request.unapprove
201
+ pull_request.unapprove
183
202
 
184
203
  # [x] GET the diff for a pull request
185
204
  diff = pull_request.diff
186
205
 
187
- # [ ] GET the log of all of a repository's pull request activity
188
- activities = repo.pull_requests_activities(options) # TODO: fix method name.
189
-
190
206
  # [ ] GET the activity for a pull request
191
207
  activities = pull_request.activities(options)
192
208
 
193
209
  # [x] Accept and merge a pull request
194
- pull_request.merge(options)
210
+ pull_request.merge(options)
195
211
 
196
212
  # [x] Decline or reject a pull request
197
- pull_request.decline(options)
213
+ pull_request.decline(options)
198
214
 
199
215
  # [x] GET a list of pull request comments
200
216
  comments = pull_request.comments
@@ -205,12 +221,20 @@ comment = pull_request.comment(comment_id)
205
221
 
206
222
  ##### commits or commit Resource
207
223
 
224
+ ###### Collection Methods
225
+
208
226
  ```ruby
209
227
  repo = bucket.repo('someone', 'great_repo')
210
228
 
211
229
  # [x] GET a commits list for a repository or compare commits across branches
212
230
  # branchortag, include, exclude options
213
231
  commits = repo.commits(options)
232
+ ```
233
+
234
+ ###### Object Methods
235
+
236
+ ```ruby
237
+ repo = bucket.repo('someone', 'great_repo')
214
238
 
215
239
  # [x] GET an individual commit
216
240
  commit = repo.commit('revision')
@@ -222,37 +246,45 @@ comments = commit.comments
222
246
  comment = commit.comment(comment_id)
223
247
 
224
248
  # [x] POST a commit approval
225
- commit.approve
249
+ commit.approve
226
250
 
227
251
  # [x] DELETE a commit approval
228
- commit.unapprove
252
+ commit.unapprove
229
253
  ```
230
254
 
231
255
  ##### branch-restrictions Resource
232
256
 
257
+ ###### Collection Methods
258
+
233
259
  ```ruby
234
- repo = bucket.repo('someone', 'great_repo').find
260
+ repo = bucket.repo('someone', 'great_repo')
235
261
 
236
262
  # [x] GET the branch-restrictions
237
263
  restrictions = repo.branch_restrictions
238
264
 
239
265
  # [ ] POST the branch-restrictions
240
- repo.create_branch_restrictions(restrictions)
266
+ new_restriction = restrictions.create(params)
267
+ ```
268
+
269
+ ###### Object Methods
270
+
271
+ ```ruby
272
+ repo = bucket.repo('someone', 'great_repo').find
241
273
 
242
274
  # [x] GET a specific restriction
243
275
  restriction = repo.branch_restriction(restriction_id)
244
276
 
245
277
  # [ ] PUT a branch restriction update
246
- restriction.update(params)
278
+ restriction.update(params)
247
279
 
248
280
  # [ ] DELETE the branch restriction
249
- restriction.destroy
281
+ restriction.destroy
250
282
  ```
251
283
 
252
284
  ##### diff Resource
253
285
 
254
286
  ```ruby
255
- repo = bucket.repo('someone', 'great_repo').find
287
+ repo = bucket.repo('someone', 'great_repo')
256
288
  COMMIT_ID = '7e968c5'
257
289
 
258
290
  # [x] GET a diff
@@ -262,6 +294,50 @@ diff = repo.diff(COMMIT_ID)
262
294
  patch = repo.patch(COMMIT_ID)
263
295
  ```
264
296
 
297
+ ##### statuses/build Resource
298
+
299
+ ###### Collection Methods
300
+
301
+ ```ruby
302
+ repo = bucket.repo('someone', 'great_repo')
303
+
304
+ COMMIT_ID = '7e968c5'
305
+ commit = repo.commit(COMMIT_ID)
306
+
307
+ BUILD_STATUS_KEY = 'tinybucket'
308
+
309
+ # [x] POST a build status for a commit
310
+ commit.build_statuses.create(
311
+ key: BUILD_STATUS_KEY,
312
+ state: 'INPROGRESS',
313
+ name: 'Name of build',
314
+ url: 'link to the build result',
315
+ description: 'about build'
316
+ )
317
+ ```
318
+
319
+ ###### Object Methods
320
+
321
+ ```
322
+ repo = bucket.repo('someone', 'great_repo')
323
+
324
+ COMMIT_ID = '7e968c5'
325
+ commit = repo.commit(COMMIT_ID)
326
+
327
+ BUILD_STATUS_KEY = 'tinybucket'
328
+
329
+ # [x] GET the build status for a commit
330
+ status = commit.build_status(BUILD_STATUS_KEY)
331
+
332
+ # [x] PUT a build status for a commit
333
+ status.update(
334
+ state: 'SUCCESSFUL',
335
+ name: 'Name of build',
336
+ url: 'link to the build result',
337
+ description: 'about build'
338
+ )
339
+ ```
340
+
265
341
  ## Contribution
266
342
 
267
343
  1. Fork it ( https://github.com/[my-github-username]/bitbucket/fork )
data/lib/tinybucket.rb CHANGED
@@ -31,6 +31,7 @@ require 'tinybucket/model/concerns'
31
31
  require 'tinybucket/model'
32
32
  require 'tinybucket/parser'
33
33
  require 'tinybucket/request'
34
+ require 'tinybucket/resource'
34
35
  require 'tinybucket/response'
35
36
 
36
37
  require 'tinybucket/client'
@@ -5,6 +5,7 @@ module Tinybucket
5
5
  [
6
6
  :BaseApi,
7
7
  :BranchRestrictionsApi,
8
+ :BuildStatusApi,
8
9
  :CommitsApi,
9
10
  :CommentsApi,
10
11
  :DiffApi,
@@ -0,0 +1,55 @@
1
+ module Tinybucket
2
+ module Api
3
+ # BuildStatus Api client
4
+ #
5
+ # @see https://confluence.atlassian.com/bitbucket/statuses-build-resource-779295267.html
6
+ # statuses/build Resource - Bitbucket Cloud REST API
7
+ class BuildStatusApi < BaseApi
8
+ include Tinybucket::Api::Helper::BuildStatusHelper
9
+
10
+ attr_accessor :repo_owner, :repo_slug
11
+
12
+ # Send 'GET the build status for a commit' request
13
+ #
14
+ # @param revision [String]
15
+ # @param key [String]
16
+ # @param options [Hash]
17
+ # @return [Tinybucket::Model::BuildStatus]
18
+ def find(revision, key, options = {})
19
+ get_path(
20
+ path_to_find(revision, key),
21
+ options,
22
+ Tinybucket::Parser::BuildStatusParser
23
+ )
24
+ end
25
+
26
+ # Send 'POST a build status for a commit' request
27
+ #
28
+ # @param revision [String]
29
+ # @param key [String]
30
+ # @param options [Hash]
31
+ # @return [Tinybucket::Model::BuildStatus]
32
+ def post(revision, key, options)
33
+ post_path(
34
+ path_to_post(revision),
35
+ options.merge(key: key),
36
+ Tinybucket::Parser::BuildStatusParser
37
+ )
38
+ end
39
+
40
+ # Send 'PUT a build status for a commit' request
41
+ #
42
+ # @param revision [String]
43
+ # @param key [String]
44
+ # @param options [Hash]
45
+ # @return [Tinybucket::Model::BuildStatus]
46
+ def put(revision, key, options)
47
+ put_path(
48
+ path_to_put(revision, key),
49
+ options,
50
+ Tinybucket::Parser::BuildStatusParser
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
@@ -6,6 +6,7 @@ module Tinybucket
6
6
  [
7
7
  :ApiHelper,
8
8
  :BranchRestrictionsHelper,
9
+ :BuildStatusHelper,
9
10
  :CommitsHelper,
10
11
  :CommentsHelper,
11
12
  :DiffHelper,
@@ -0,0 +1,35 @@
1
+ module Tinybucket
2
+ module Api
3
+ module Helper
4
+ module BuildStatusHelper
5
+ include ::Tinybucket::Api::Helper::ApiHelper
6
+
7
+ private
8
+
9
+ def path_to_find(revision, key)
10
+ build_path(base_path(revision),
11
+ [key, 'key'])
12
+ end
13
+
14
+ def path_to_post(revision)
15
+ base_path(revision)
16
+ end
17
+
18
+ def path_to_put(revision, key)
19
+ build_path(base_path(revision),
20
+ [key, 'key'])
21
+ end
22
+
23
+ def base_path(revision)
24
+ build_path('/repositories',
25
+ [repo_owner, 'repo_owner'],
26
+ [repo_slug, 'repo_slug'],
27
+ 'commit',
28
+ [revision, 'revision'],
29
+ 'statuses',
30
+ 'build')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -17,23 +17,22 @@ module Tinybucket
17
17
  # @overload repos(options)
18
18
  # get public repositories.
19
19
  # @option options [Hash] a hash with options
20
- # @return [Tinybucket::Enumerator] enumerator to enumerate repositories
21
- # as [Tinybucket::Model::Repository]
20
+ # @return [Tinybucket::Resource::Repos] repository resource
22
21
  def repos(*args)
23
22
  case args.size
24
23
  when 0
25
- public_repos(*args)
24
+ public_repos
26
25
  when 1
27
26
  case args.first
28
27
  when Hash
29
- public_repos(*args)
28
+ public_repos(args.first)
30
29
  when String, Symbol
31
- owners_repos(*args)
30
+ owners_repos(args.first)
32
31
  else
33
32
  raise ArgumentError
34
33
  end
35
34
  when 2
36
- owners_repos(*args)
35
+ owners_repos(args[0], args[1])
37
36
  else
38
37
  raise ArgumentError
39
38
  end
@@ -46,10 +45,10 @@ module Tinybucket
46
45
  # repo_slug})
47
46
  # @return [Tinybucket::Model::Repository]
48
47
  def repo(owner, repo_slug)
49
- m = Tinybucket::Model::Repository.new({})
50
- m.repo_owner = owner
51
- m.repo_slug = repo_slug
52
- m
48
+ Tinybucket::Model::Repository.new({}).tap do |m|
49
+ m.repo_owner = owner
50
+ m.repo_slug = repo_slug
51
+ end
53
52
  end
54
53
 
55
54
  # Get the team
@@ -57,9 +56,9 @@ module Tinybucket
57
56
  # @param teamname [String] the team name.
58
57
  # @return [Tinybucket::Model::Team]
59
58
  def team(teamname)
60
- m = Tinybucket::Model::Team.new({})
61
- m.username = teamname
62
- m
59
+ Tinybucket::Model::Team.new({}).tap do |m|
60
+ m.username = teamname
61
+ end
63
62
  end
64
63
 
65
64
  # Get the user profile
@@ -67,48 +66,32 @@ module Tinybucket
67
66
  # @param username [String] the user name.
68
67
  # @return [Tinybucket::Model::Profile]
69
68
  def user(username)
70
- m = Tinybucket::Model::Profile.new({})
71
- m.username = username
72
- m
69
+ Tinybucket::Model::Profile.new({}).tap do |m|
70
+ m.username = username
71
+ end
73
72
  end
74
73
 
75
74
  private
76
75
 
77
- def public_repos(*args)
78
- options = args.empty? ? {} : args.first
76
+ # Get public repositories
77
+ #
78
+ # @param options [Hash]
79
+ # @return [Tinybucket::Resource::Repos]
80
+ def public_repos(options = {})
79
81
  raise ArgumentError unless options.is_a?(Hash)
80
82
 
81
- enumerator(
82
- repos_api,
83
- :list,
84
- options
85
- )
83
+ Tinybucket::Resource::Repos.new(nil, options)
86
84
  end
87
85
 
88
- def owners_repos(*args)
89
- owner = args.first
90
- options = (args.size == 2) ? args[1] : {}
86
+ # Get Owner's repositories
87
+ #
88
+ # @param owner [String]
89
+ # @param options [Hash]
90
+ # @return [Tinybucket::Resource::Repos]
91
+ def owners_repos(owner, options = {})
91
92
  raise ArgumentError unless options.is_a?(Hash)
92
93
 
93
- enumerator(
94
- user_api(owner),
95
- :repos,
96
- options
97
- )
98
- end
99
-
100
- def repos_api
101
- create_instance('Repos')
102
- end
103
-
104
- def user_api(owner)
105
- api = create_instance('User')
106
- api.username = owner
107
- api
108
- end
109
-
110
- def create_instance(name)
111
- ApiFactory.create_instance(name)
94
+ Tinybucket::Resource::Repos.new(owner, options)
112
95
  end
113
96
  end
114
97
  end