github_api 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/README.md +11 -0
  2. data/lib/github_api/api.rb +20 -22
  3. data/lib/github_api/core_ext/hash.rb +17 -0
  4. data/lib/github_api/events.rb +3 -3
  5. data/lib/github_api/git_data/blobs.rb +2 -2
  6. data/lib/github_api/git_data/commits.rb +2 -2
  7. data/lib/github_api/git_data/references.rb +5 -5
  8. data/lib/github_api/git_data/tags.rb +2 -2
  9. data/lib/github_api/git_data/trees.rb +2 -2
  10. data/lib/github_api/issues.rb +4 -4
  11. data/lib/github_api/issues/comments.rb +6 -6
  12. data/lib/github_api/issues/events.rb +2 -2
  13. data/lib/github_api/issues/labels.rb +10 -10
  14. data/lib/github_api/issues/milestones.rb +5 -5
  15. data/lib/github_api/page_iterator.rb +4 -3
  16. data/lib/github_api/pull_requests.rb +8 -8
  17. data/lib/github_api/pull_requests/comments.rb +5 -5
  18. data/lib/github_api/repos.rb +15 -8
  19. data/lib/github_api/repos/collaborators.rb +4 -4
  20. data/lib/github_api/repos/comments.rb +121 -0
  21. data/lib/github_api/repos/commits.rb +56 -177
  22. data/lib/github_api/repos/contents.rb +3 -0
  23. data/lib/github_api/repos/downloads.rb +4 -4
  24. data/lib/github_api/repos/forks.rb +2 -2
  25. data/lib/github_api/repos/hooks.rb +6 -6
  26. data/lib/github_api/repos/keys.rb +5 -5
  27. data/lib/github_api/repos/merging.rb +1 -0
  28. data/lib/github_api/repos/starring.rb +3 -1
  29. data/lib/github_api/repos/statuses.rb +2 -2
  30. data/lib/github_api/repos/watching.rb +1 -1
  31. data/lib/github_api/version.rb +1 -1
  32. data/spec/github/api/set_spec.rb +19 -0
  33. data/spec/github/repos/comments/create_spec.rb +86 -0
  34. data/spec/github/repos/comments/delete_spec.rb +47 -0
  35. data/spec/github/repos/comments/get_spec.rb +54 -0
  36. data/spec/github/repos/comments/list_spec.rb +120 -0
  37. data/spec/github/repos/comments/update_spec.rb +54 -0
  38. data/spec/github/repos/commits/compare_spec.rb +37 -0
  39. data/spec/github/repos/commits/get_spec.rb +56 -0
  40. data/spec/github/repos/commits/list_spec.rb +63 -0
  41. data/spec/github/repos/downloads/create_spec.rb +66 -0
  42. data/spec/github/repos/downloads/delete_spec.rb +48 -0
  43. data/spec/github/repos/downloads/get_spec.rb +58 -0
  44. data/spec/github/repos/downloads/list_spec.rb +63 -0
  45. data/spec/github/repos/downloads/upload_spec.rb +32 -0
  46. data/spec/github/repos/downloads_spec.rb +1 -233
  47. data/spec/github/repos_spec.rb +2 -0
  48. data/spec/spec_helper.rb +1 -0
  49. metadata +48 -34
  50. data/spec/github/repos/commits_spec.rb +0 -471
@@ -1,471 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::Repos::Commits do
4
- let(:github) { Github.new }
5
- let(:user) { 'peter-murach' }
6
- let(:repo) { 'github' }
7
-
8
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
9
-
10
- describe "#compare" do
11
- let(:base) { 'master' }
12
- let(:head) { 'topic' }
13
-
14
- context 'resource found' do
15
- before do
16
- stub_get("/repos/#{user}/#{repo}/compare/#{base}...#{head}").
17
- to_return(:body => fixture('repos/commit_comparison.json'),
18
- :status => 200,
19
- :headers => {:content_type => "application/json; charset=utf-8"})
20
- end
21
-
22
- it "should fail to get resource without base" do
23
- expect {
24
- github.repos.commits.compare user, repo, nil, head
25
- }.to raise_error(ArgumentError)
26
- end
27
-
28
- it "should compare successfully" do
29
- github.repos.commits.compare user, repo, base, head
30
- a_get("/repos/#{user}/#{repo}/compare/#{base}...#{head}").should have_been_made
31
- end
32
-
33
- it "should get comparison information" do
34
- commit = github.repos.commits.compare user, repo, base, head
35
- commit.base_commit.commit.author.name.should == 'Monalisa Octocat'
36
- end
37
- end
38
- end # compare
39
-
40
- describe "#list" do
41
- it { github.repos.commits.should respond_to :all }
42
-
43
- context "resource found" do
44
- before do
45
- stub_get("/repos/#{user}/#{repo}/commits").
46
- to_return(:body => fixture('repos/commits.json'),
47
- :status => 200,
48
- :headers => {:content_type => "application/json; charset=utf-8"})
49
- end
50
-
51
- it "should fail to get resource without username" do
52
- expect { github.repos.commits.list }.to raise_error(ArgumentError)
53
- end
54
-
55
- it "should get the resources" do
56
- github.repos.commits.list user, repo
57
- a_get("/repos/#{user}/#{repo}/commits").should have_been_made
58
- end
59
-
60
- it "should return array of resources" do
61
- commits = github.repos.commits.list user, repo
62
- commits.should be_an Array
63
- commits.should have(1).items
64
- end
65
-
66
- it "should be a mash type" do
67
- commits = github.repos.commits.list user, repo
68
- commits.first.should be_a Hashie::Mash
69
- end
70
-
71
- it "should get commit information" do
72
- commits = github.repos.commits.list user, repo
73
- commits.first.author.name.should == 'Scott Chacon'
74
- end
75
-
76
- it "should yield to a block" do
77
- github.repos.commits.should_receive(:list).
78
- with(user, repo).and_yield('web')
79
- github.repos.commits.list(user, repo) { |param| 'web' }
80
- end
81
- end
82
-
83
- context "resource not found" do
84
- before do
85
- stub_get("/repos/#{user}/#{repo}/commits").
86
- to_return(:body => "", :status => [404, "Not Found"])
87
- end
88
-
89
- it "should return 404 with a message 'Not Found'" do
90
- expect {
91
- github.repos.commits.list user, repo
92
- }.to raise_error(Github::Error::NotFound)
93
- end
94
- end
95
- end # list
96
-
97
- describe "#get" do
98
- let(:sha) { '23432dfosfsufd' }
99
-
100
- it { github.repos.commits.should respond_to :find }
101
-
102
- context "resource found" do
103
- before do
104
- stub_get("/repos/#{user}/#{repo}/commits/#{sha}").
105
- to_return(:body => fixture('repos/commit.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
106
- end
107
-
108
- it "should fail to get resource without sha key" do
109
- expect {
110
- github.repos.commits.get user, repo, nil
111
- }.to raise_error(ArgumentError)
112
- end
113
-
114
- it "should get the resource" do
115
- github.repos.commits.get user, repo, sha
116
- a_get("/repos/#{user}/#{repo}/commits/#{sha}").should have_been_made
117
- end
118
-
119
- it "should get commit information" do
120
- commit = github.repos.commits.get user, repo, sha
121
- commit.commit.author.name.should == 'Monalisa Octocat'
122
- end
123
-
124
- it "should return mash" do
125
- commit = github.repos.commits.get user, repo, sha
126
- commit.should be_a Hashie::Mash
127
- end
128
- end
129
-
130
- context "resource not found" do
131
- before do
132
- stub_get("/repos/#{user}/#{repo}/commits/#{sha}").
133
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
134
- end
135
-
136
- it "should fail to retrive resource" do
137
- expect {
138
- github.repos.commits.get user, repo, sha
139
- }.to raise_error(Github::Error::NotFound)
140
- end
141
- end
142
- end # get
143
-
144
- describe "commit comments" do
145
- context "resource found" do
146
- before do
147
- stub_get("/repos/#{user}/#{repo}/comments").
148
- to_return(:body => fixture('repos/repo_comments.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
149
- end
150
-
151
- it "should fail to get resource without username" do
152
- expect {
153
- github.repos.commits.repo_comments
154
- }.to raise_error(ArgumentError)
155
- end
156
-
157
- it "should get the resources" do
158
- github.repos.commits.repo_comments user, repo
159
- a_get("/repos/#{user}/#{repo}/comments").should have_been_made
160
- end
161
-
162
- it "should return array of resources" do
163
- repo_comments = github.repos.commits.repo_comments user, repo
164
- repo_comments.should be_an Array
165
- repo_comments.should have(1).items
166
- end
167
-
168
- it "should be a mash type" do
169
- repo_comments = github.repos.commits.repo_comments user, repo
170
- repo_comments.first.should be_a Hashie::Mash
171
- end
172
-
173
- it "should get commit comment information" do
174
- repo_comments = github.repos.commits.repo_comments user, repo
175
- repo_comments.first.user.login.should == 'octocat'
176
- end
177
-
178
- it "should yield to a block" do
179
- github.repos.commits.should_receive(:repo_comments).
180
- with(user, repo).and_yield('web')
181
- github.repos.commits.repo_comments(user, repo) { |param| 'web' }
182
- end
183
- end
184
-
185
- context "resource not found" do
186
- before do
187
- stub_get("/repos/#{user}/#{repo}/comments").
188
- to_return(:body => "", :status => [404, "Not Found"])
189
- end
190
-
191
- it "should return 404 with a message 'Not Found'" do
192
- expect {
193
- github.repos.commits.repo_comments user, repo
194
- }.to raise_error(Github::Error::NotFound)
195
- end
196
- end
197
- end # repo_comments
198
-
199
- describe "commit_comments" do
200
- let(:sha) { '23432dfosfsufd' }
201
-
202
- context "resource found" do
203
- before do
204
- stub_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
205
- to_return(:body => fixture('repos/commit_comments.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
206
- end
207
-
208
- it "should fail to get resource without sha key" do
209
- expect {
210
- github.repos.commits.commit_comments user, repo, nil
211
- }.to raise_error(ArgumentError)
212
- end
213
-
214
- it "should get the resource" do
215
- github.repos.commits.commit_comments user, repo, sha
216
- a_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
217
- should have_been_made
218
- end
219
-
220
- it "should return array of resources" do
221
- commit_comments = github.repos.commits.commit_comments user, repo, sha
222
- commit_comments.should be_an Array
223
- commit_comments.should have(1).items
224
- end
225
-
226
- it "should be a mash type" do
227
- commit_comments = github.repos.commits.commit_comments user, repo, sha
228
- commit_comments.first.should be_a Hashie::Mash
229
- end
230
-
231
- it "should get commit comment information" do
232
- commit_comments = github.repos.commits.commit_comments user, repo, sha
233
- commit_comments.first.user.login.should == 'octocat'
234
- end
235
-
236
- it "should yield to a block" do
237
- github.repos.commits.should_receive(:commit_comments).
238
- with(user, repo, sha).and_yield('web')
239
- github.repos.commits.commit_comments(user, repo, sha) { |param| 'web' }
240
- end
241
- end
242
-
243
- context "resource not found" do
244
- before do
245
- stub_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
246
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
247
- end
248
-
249
- it "should fail to retrive resource" do
250
- expect {
251
- github.repos.commits.commit_comments user, repo, sha
252
- }.to raise_error(Github::Error::NotFound)
253
- end
254
- end
255
- end # commit_comments
256
-
257
- describe "#commit_comment" do
258
- let(:comment_id) { 1 }
259
-
260
- context "resource found" do
261
- before do
262
- stub_get("/repos/#{user}/#{repo}/comments/#{comment_id}").
263
- to_return(:body => fixture('repos/commit_comment.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
264
- end
265
-
266
- it "should fail to get resource without comment id" do
267
- expect {
268
- github.repos.commits.commit_comment user, repo, nil
269
- }.to raise_error(ArgumentError)
270
- end
271
-
272
- it "should get the resource" do
273
- github.repos.commits.commit_comment user, repo, comment_id
274
- a_get("/repos/#{user}/#{repo}/comments/#{comment_id}").should have_been_made
275
- end
276
-
277
- it "should get commit comment information" do
278
- commit_comment = github.repos.commits.commit_comment user, repo, comment_id
279
- commit_comment.user.login.should == 'octocat'
280
- end
281
-
282
- it "should return mash" do
283
- commit_comment = github.repos.commits.commit_comment user, repo, comment_id
284
- commit_comment.should be_a Hashie::Mash
285
- end
286
- end
287
-
288
- context "resource not found" do
289
- before do
290
- stub_get("/repos/#{user}/#{repo}/comments/#{comment_id}").
291
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
292
- end
293
-
294
- it "should fail to retrive resource" do
295
- expect {
296
- github.repos.commits.commit_comment user, repo, comment_id
297
- }.to raise_error(Github::Error::NotFound)
298
- end
299
- end
300
- end # commit_comment
301
-
302
- describe "create_comment" do
303
- let(:sha) { '23432dfosfsufd' }
304
- let(:inputs) do
305
- { 'body' => 'web',
306
- :commit_id => 1,
307
- :line => 1,
308
- :path => 'file1.txt',
309
- :position => 4 }
310
- end
311
-
312
- context "resouce created" do
313
- before do
314
- stub_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).
315
- to_return(:body => fixture('repos/commit_comment.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
316
- end
317
-
318
- it "should fail to create resource if 'body' input is missing" do
319
- expect {
320
- github.repos.commits.create_comment user, repo, sha, inputs.except('body')
321
- }.to raise_error(Github::Error::RequiredParams)
322
- end
323
-
324
- it "should fail to create resource if 'commit_id' input is missing" do
325
- expect {
326
- github.repos.commits.create_comment user, repo, sha, inputs.except(:commit_id)
327
- }.to raise_error(Github::Error::RequiredParams)
328
- end
329
-
330
- it "should fail to create resource if 'line' input is missing" do
331
- expect {
332
- github.repos.commits.create_comment user, repo, sha, inputs.except(:line)
333
- }.to raise_error(Github::Error::RequiredParams)
334
- end
335
-
336
- it "should fail to create resource if 'path' input is missing" do
337
- expect {
338
- github.repos.commits.create_comment user, repo, sha, inputs.except(:path)
339
- }.to raise_error(Github::Error::RequiredParams)
340
- end
341
-
342
- it "should fail to create resource if 'position' input is missing" do
343
- expect {
344
- github.repos.commits.create_comment user, repo, sha, inputs.except(:position)
345
- }.to raise_error(Github::Error::RequiredParams)
346
- end
347
-
348
- it "should create resource successfully" do
349
- github.repos.commits.create_comment user, repo, sha, inputs
350
- a_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).should have_been_made
351
- end
352
-
353
- it "should return the resource" do
354
- comment = github.repos.commits.create_comment user, repo, sha, inputs
355
- comment.should be_a Hashie::Mash
356
- end
357
-
358
- it "should get the commit comment information" do
359
- comment = github.repos.commits.create_comment user, repo, sha, inputs
360
- comment.user.login.should == 'octocat'
361
- end
362
- end
363
-
364
- context "failed to create resource" do
365
- before do
366
- stub_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).
367
- to_return(:body => fixture('repos/commit_comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
368
-
369
- end
370
-
371
- it "should fail to retrieve resource" do
372
- expect {
373
- github.repos.commits.create_comment user, repo, sha, inputs
374
- }.to raise_error(Github::Error::NotFound)
375
- end
376
- end
377
- end # create_comment
378
-
379
- describe "delete_comment" do
380
- let(:comment_id) { 1 }
381
-
382
- context "resource deleted successfully" do
383
- before do
384
- stub_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").
385
- to_return(:body => '', :status => 204,
386
- :headers => { :content_type => "application/json; charset=utf-8"})
387
- end
388
-
389
- it "should fail to delete without 'user/repo' parameters" do
390
- expect {
391
- github.repos.commits.delete_comment
392
- }.to raise_error(ArgumentError)
393
- end
394
-
395
- it "should fail to delete resource without 'comment_id'" do
396
- expect {
397
- github.repos.commits.delete_comment user, repo, nil
398
- }.to raise_error(ArgumentError)
399
- end
400
-
401
- it "should delete the resource" do
402
- github.repos.commits.delete_comment user, repo, comment_id
403
- a_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").should have_been_made
404
- end
405
- end
406
-
407
- context "failed to delete resource" do
408
- before do
409
- stub_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").
410
- to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
411
-
412
- end
413
-
414
- it "should fail to find resource" do
415
- expect {
416
- github.repos.commits.delete_comment user, repo, comment_id
417
- }.to raise_error(Github::Error::NotFound)
418
- end
419
- end
420
- end # delete_comment
421
-
422
- describe "#update_comment" do
423
- let(:comment_id) { 1 }
424
- let(:inputs) { {'body'=> 'web'} }
425
-
426
- context "resouce created" do
427
- before do
428
- stub_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).
429
- to_return(:body => fixture('repos/commit_comment.json'),
430
- :status => 200,
431
- :headers => {:content_type => "application/json; charset=utf-8"})
432
- end
433
-
434
- it "should fail to create resource if 'body' input is missing" do
435
- expect {
436
- github.repos.commits.update_comment user, repo, comment_id, inputs.except('body')
437
- }.to raise_error(Github::Error::RequiredParams)
438
- end
439
-
440
- it "should create resource successfully" do
441
- github.repos.commits.update_comment user, repo, comment_id, inputs
442
- a_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).should have_been_made
443
- end
444
-
445
- it "should return the resource" do
446
- comment = github.repos.commits.update_comment user, repo, comment_id, inputs
447
- comment.should be_a Hashie::Mash
448
- end
449
-
450
- it "should get the commit comment information" do
451
- comment = github.repos.commits.update_comment user, repo, comment_id, inputs
452
- comment.user.login.should == 'octocat'
453
- end
454
- end
455
-
456
- context "failed to update resource" do
457
- before do
458
- stub_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).
459
- to_return(:body => fixture('repos/commit_comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
460
-
461
- end
462
-
463
- it "should fail to retrieve resource" do
464
- expect {
465
- github.repos.commits.update_comment user, repo, comment_id, inputs
466
- }.to raise_error(Github::Error::NotFound)
467
- end
468
- end
469
- end # update_comment
470
-
471
- end # Github::Repos::Commits