octokit 0.5.0 → 0.5.1

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 (41) hide show
  1. data/.gemtest +0 -0
  2. data/Rakefile +1 -0
  3. data/lib/octokit/configuration.rb +23 -9
  4. data/lib/octokit/version.rb +1 -1
  5. data/octokit.gemspec +2 -2
  6. metadata +7 -131
  7. data/test/fixtures/blob.json +0 -10
  8. data/test/fixtures/branch_commits.json +0 -48
  9. data/test/fixtures/branches.json +0 -6
  10. data/test/fixtures/close_issue.json +0 -1
  11. data/test/fixtures/collaborators.json +0 -1
  12. data/test/fixtures/comment.json +0 -1
  13. data/test/fixtures/commits.json +0 -824
  14. data/test/fixtures/contributors.json +0 -6
  15. data/test/fixtures/emails.json +0 -1
  16. data/test/fixtures/followers.json +0 -3
  17. data/test/fixtures/full_user.json +0 -27
  18. data/test/fixtures/issue.json +0 -14
  19. data/test/fixtures/issues.json +0 -50
  20. data/test/fixtures/keys.json +0 -1
  21. data/test/fixtures/labels.json +0 -1
  22. data/test/fixtures/languages.json +0 -1
  23. data/test/fixtures/network.json +0 -26
  24. data/test/fixtures/network_data.json +0 -1
  25. data/test/fixtures/network_meta.json +0 -109
  26. data/test/fixtures/open_issue.json +0 -1
  27. data/test/fixtures/raw_git_data.yaml +0 -7
  28. data/test/fixtures/reopen_issue.json +0 -1
  29. data/test/fixtures/repo.json +0 -14
  30. data/test/fixtures/repo_search.json +0 -452
  31. data/test/fixtures/repos.json +0 -830
  32. data/test/fixtures/search-email.json +0 -19
  33. data/test/fixtures/search-username.json +0 -44
  34. data/test/fixtures/show_commit.json +0 -37
  35. data/test/fixtures/tags.json +0 -8
  36. data/test/fixtures/timeline.json +0 -1018
  37. data/test/fixtures/trees.json +0 -140
  38. data/test/fixtures/user.json +0 -16
  39. data/test/helper.rb +0 -59
  40. data/test/octokit_test.rb +0 -789
  41. data/test/repository_test.rb +0 -45
@@ -1,140 +0,0 @@
1
- {
2
- "tree": [{
3
- "name": ".gitignore",
4
- "sha": "e43b0f988953ae3a84b00331d0ccf5f7d51cb3cf",
5
- "mode": "100644",
6
- "type": "blob"
7
- },
8
- {
9
- "name": "README.txt",
10
- "sha": "d4fc2d5e810d9b4bc1ce67702603080e3086a4ed",
11
- "mode": "100644",
12
- "type": "blob"
13
- },
14
- {
15
- "name": "b.png",
16
- "sha": "f184e6269b343014f58694093b55558dd5dde193",
17
- "mode": "100644",
18
- "type": "blob"
19
- },
20
- {
21
- "name": "bl.png",
22
- "sha": "f6271859d51654b6fb2719df5fe192c8398ecefc",
23
- "mode": "100644",
24
- "type": "blob"
25
- },
26
- {
27
- "name": "br.png",
28
- "sha": "31f204fc451cd9dd5cfdadfad2d86ed0e1104882",
29
- "mode": "100644",
30
- "type": "blob"
31
- },
32
- {
33
- "name": "build_tar.sh",
34
- "sha": "08f6f1fce2f6a02dcb15b6c66244470794587bb0",
35
- "mode": "100755",
36
- "type": "blob"
37
- },
38
- {
39
- "name": "closelabel.gif",
40
- "sha": "87b4f8bd699386e3a6fcc2e50d7c61bfc4aabb8d",
41
- "mode": "100755",
42
- "type": "blob"
43
- },
44
- {
45
- "name": "facebox.css",
46
- "sha": "08e190d5f81959d73d2bdd3e4f752271800886bf",
47
- "mode": "100644",
48
- "type": "blob"
49
- },
50
- {
51
- "name": "facebox.js",
52
- "sha": "43245f3b1b50a0568ece00b44d2dc67be413f2a4",
53
- "mode": "100644",
54
- "type": "blob"
55
- },
56
- {
57
- "name": "faceplant.css",
58
- "sha": "dc61a86c3f342b930f0a0447cae33fee812e27d3",
59
- "mode": "100644",
60
- "type": "blob"
61
- },
62
- {
63
- "name": "index.html",
64
- "sha": "a9d1c235d08ae383e4d9dedf5e2cc0236defdaa6",
65
- "mode": "100644",
66
- "type": "blob"
67
- },
68
- {
69
- "name": "jquery.js",
70
- "sha": "ebe02bdd357c337e0e817fcbce2a034a54a13287",
71
- "mode": "100644",
72
- "type": "blob"
73
- },
74
- {
75
- "name": "loading.gif",
76
- "sha": "f864d5fd38b7466c76b5a36dc0e3e9455c0126e2",
77
- "mode": "100755",
78
- "type": "blob"
79
- },
80
- {
81
- "name": "logo.png",
82
- "sha": "e41cfe5c654e8e05ad46f15af1c462a1360e9764",
83
- "mode": "100644",
84
- "type": "blob"
85
- },
86
- {
87
- "name": "releases",
88
- "sha": "82e3a754b6a0fcb238b03c0e47d05219fbf9cf89",
89
- "mode": "040000",
90
- "type": "tree"
91
- },
92
- {
93
- "name": "remote.html",
94
- "sha": "98d3e92373d1bc541e7f516e5e73b645a991ddc2",
95
- "mode": "100644",
96
- "type": "blob"
97
- },
98
- {
99
- "name": "screenshots",
100
- "sha": "bbf747873075ac28667d246491ffdefbd314fe4f",
101
- "mode": "040000",
102
- "type": "tree"
103
- },
104
- {
105
- "name": "shadow.gif",
106
- "sha": "e58b35b362ce5347bb5064e91a3bf8e4fed4f6ef",
107
- "mode": "100644",
108
- "type": "blob"
109
- },
110
- {
111
- "name": "stairs.jpg",
112
- "sha": "63459bb418f5f6d896a8eb925c01f45024933ed6",
113
- "mode": "100644",
114
- "type": "blob"
115
- },
116
- {
117
- "name": "test.html",
118
- "sha": "0a279c66167d358e40682186864935d0f856c4c4",
119
- "mode": "100644",
120
- "type": "blob"
121
- },
122
- {
123
- "name": "test_programmatic.html",
124
- "sha": "0249382efbdc7412a67976d19154ef07ac51437f",
125
- "mode": "100644",
126
- "type": "blob"
127
- },
128
- {
129
- "name": "tl.png",
130
- "sha": "d99c8f6c6eaa12d7b49a20f41f08a5006f3ea8b7",
131
- "mode": "100644",
132
- "type": "blob"
133
- },
134
- {
135
- "name": "tr.png",
136
- "sha": "e99b6ec8310e859fd27519694f04e1babf2ab2c4",
137
- "mode": "100644",
138
- "type": "blob"
139
- }]
140
- }
@@ -1,16 +0,0 @@
1
- {
2
- "user": {
3
- "name": "Wynn Netherland",
4
- "company": "Orrka",
5
- "location": "Dallas, TX",
6
- "created_at": "2008/02/25 10:24:19 -0800",
7
- "public_gist_count": 3,
8
- "public_repo_count": 15,
9
- "blog": "http://wynnnetherland.com",
10
- "following_count": 55,
11
- "id": 865,
12
- "followers_count": 21,
13
- "login": "pengwynn",
14
- "email": "wynn.netherland@gmail.com"
15
- }
16
- }
@@ -1,59 +0,0 @@
1
- require 'test/unit'
2
- require 'pathname'
3
-
4
- require 'shoulda'
5
- require 'matchy'
6
- require 'mocha'
7
- require 'fakeweb'
8
-
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
- $LOAD_PATH.unshift(File.dirname(__FILE__))
11
- require 'octokit'
12
-
13
- FakeWeb.allow_net_connect = false
14
-
15
- class Test::Unit::TestCase
16
- end
17
-
18
- def fixture_file(filename)
19
- return '' if filename == ''
20
- file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
21
- File.read(file_path)
22
- end
23
-
24
- def github_url(url)
25
- if url =~ /^http/
26
- url
27
- elsif @client && @client.authenticated?
28
- "https://pengwynn%2Ftoken:OU812@github.com/api/v#{Octokit.version}/#{Octokit.format}/#{url}"
29
- elsif @client && @client.oauthed?
30
- "https://github.com/api/v#{Octokit.version}/#{Octokit.format}/#{url}?access_token=#{@client.oauth_token}"
31
- else
32
- "https://github.com/api/v#{Octokit.version}/#{Octokit.format}/#{url}"
33
- end
34
- end
35
-
36
- def stub_request(method, url, filename, status=nil)
37
- options = {:body => ""}
38
- options.merge!({:body => fixture_file(filename)}) if filename
39
- options.merge!({:body => status.last}) if status
40
- options.merge!({:status => status}) if status
41
-
42
- FakeWeb.register_uri(method, github_url(url), options)
43
- end
44
-
45
- def stub_delete(*args)
46
- stub_request(:delete, *args)
47
- end
48
-
49
- def stub_get(*args)
50
- stub_request(:get, *args)
51
- end
52
-
53
- def stub_post(*args)
54
- stub_request(:post, *args)
55
- end
56
-
57
- def stub_put(*args)
58
- stub_request(:put, *args)
59
- end
@@ -1,789 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
-
3
- class OctokitTest < Test::Unit::TestCase
4
-
5
- context "when oauthed" do
6
- setup do
7
- @client = Octokit::Client.new(:login => 'pengwynn', :oauth_token => 'OU812')
8
- end
9
- should "return full user info for the authenticated user" do
10
- stub_get("user/show", "full_user.json")
11
- user = @client.user
12
- user.plan.name.should == 'free'
13
- user.plan.space.should == 307200
14
- end
15
- end
16
-
17
- context "when authenticated" do
18
- setup do
19
- @client = Octokit::Client.new(:login => 'pengwynn', :token => 'OU812')
20
- end
21
-
22
- should "should search users by username" do
23
- stub_get("user/search/wynn", "search-username.json")
24
- users = @client.search_users("wynn")
25
- users.first.username.should == 'pengwynn'
26
- end
27
-
28
- should "should search users by email" do
29
- stub_get("user/email/wynn.netherland@gmail.com", "search-email.json")
30
- users = @client.search_users("wynn.netherland@gmail.com")
31
- users.login.should == 'pengwynn'
32
- end
33
-
34
- should "return full user info for the authenticated user" do
35
- stub_get("user/show", "full_user.json")
36
- user = @client.user
37
- user.plan.name.should == 'free'
38
- user.plan.space.should == 307200
39
- end
40
-
41
- should "return followers for a user" do
42
- stub_get("user/show/pengwynn/followers", "followers.json")
43
- followers = @client.followers("pengwynn")
44
- followers.size.should == 21
45
- assert followers.include?("adamstac")
46
- end
47
-
48
- should "return followers for the authenticated user" do
49
- stub_get("user/show/pengwynn/followers", "followers.json")
50
- followers = @client.followers
51
- followers.size.should == 21
52
- assert followers.include?("adamstac")
53
- end
54
-
55
- should "return users a user follows" do
56
- stub_get("user/show/pengwynn/following", "followers.json")
57
- followers = @client.following("pengwynn")
58
- followers.size.should == 21
59
- assert followers.include?("adamstac")
60
- end
61
-
62
- should "return the users the authenticated user follows" do
63
- stub_get("user/show/pengwynn/following", "followers.json")
64
- followers = @client.following
65
- followers.size.should == 21
66
- assert followers.include?("adamstac")
67
- end
68
-
69
- should "indicate if one user follows another" do
70
- stub_get("user/show/pengwynn/following", "followers.json")
71
- @client.follows?('adamstac')
72
- end
73
-
74
- should "return the repos a user watches" do
75
- stub_get("repos/watched/pengwynn", "repos.json")
76
- repos = @client.watched
77
- repos.first.owner.should == 'jnunemaker'
78
- repos.first.forks.should == 120
79
- end
80
-
81
- should "return the repos the authenticated user watched" do
82
- stub_get("repos/watched/pengwynn", "repos.json")
83
- repos = @client.watched('pengwynn')
84
- repos.first.owner.should == 'jnunemaker'
85
- repos.first.forks.should == 120
86
- end
87
-
88
- should "update user info" do
89
- stub_post("user/show/pengwynn", "user.json")
90
- user = @client.update_user(:location => "Dallas, TX")
91
- user.location.should == 'Dallas, TX'
92
- end
93
-
94
- should "return emails for the authenticated user" do
95
- stub_get("user/emails", "emails.json")
96
- emails = @client.emails
97
- emails.size.should == 3
98
- assert emails.include? "wynn@orrka.com"
99
- end
100
-
101
- should "add an email for the authenticated user" do
102
- stub_post("user/email/add", "emails.json")
103
- emails = @client.add_email('wynn@orrka.com')
104
- emails.size.should == 3
105
- assert emails.include? "wynn@orrka.com"
106
- end
107
-
108
- should "remove an email for the authenticated user" do
109
- stub_post("user/email/remove", "emails.json")
110
- emails = @client.remove_email('wynn@squeejee.com')
111
- emails.size.should == 3
112
- end
113
-
114
- should "return keys for the authenticated user" do
115
- stub_get("user/keys", "keys.json")
116
- keys = @client.keys
117
- keys.size.should == 6
118
- keys.last.title.should == 'wynn@pengwynn.local'
119
- end
120
-
121
- should "add an key for the authenticated user" do
122
- stub_post("user/key/add", "keys.json")
123
- keys = @client.add_key('pengwynn', 'ssh-rsa 009aasd0kalsdfa-sd9a-sdf')
124
- keys.size.should == 6
125
- keys.last.title.should == 'wynn@pengwynn.local'
126
- end
127
-
128
- should "remove an key for the authenticated user" do
129
- stub_post("user/key/remove", "keys.json")
130
- keys = @client.remove_key(1234)
131
- keys.size.should == 6
132
- end
133
-
134
- should "open an issue" do
135
- stub_post("issues/open/pengwynn/linkedin", "open_issue.json")
136
- issue = @client.open_issue({:username => "pengwynn", :repo => "linkedin"}, "testing", "Testing api")
137
- issue.title.should == "testing"
138
- issue.number.should == 2
139
- end
140
-
141
- should "close an issue" do
142
- stub_post("issues/close/pengwynn/linkedin/2", "close_issue.json")
143
- issue = @client.close_issue({:username => "pengwynn", :repo => "linkedin"}, 2)
144
- issue.title.should == "testing"
145
- issue.number.should == 2
146
- end
147
-
148
- should "reopen an issue" do
149
- stub_post("issues/reopen/pengwynn/linkedin/2", "reopen_issue.json")
150
- issue = @client.close_issue({:username => "pengwynn", :repo => "linkedin"}, 2)
151
- issue.title.should == "testing"
152
- issue.number.should == 2
153
- end
154
-
155
- should "edit an issue" do
156
- stub_post("issues/edit/pengwynn/linkedin/2", "open_issue.json")
157
- issue = @client.update_issue("pengwynn/linkedin", 2, "testing", "Testing api")
158
- issue.title.should == "testing"
159
- issue.number.should == 2
160
- end
161
-
162
- should "list issue labels for a repo" do
163
- stub_get("issues/labels/pengwynn/linkedin", "labels.json")
164
- labels = @client.labels("pengwynn/linkedin")
165
- labels.first.should == 'oauth'
166
- end
167
-
168
- should "add a label to an issue" do
169
- stub_post("issues/label/add/pengwynn/linkedin/oauth/2", "labels.json")
170
- labels = @client.add_label('pengwynn/linkedin', 2, 'oauth')
171
- assert labels.include?("oauth")
172
- end
173
-
174
- should "remove a label from an issue" do
175
- stub_post("issues/label/remove/pengwynn/linkedin/oauth/2", "labels.json")
176
- labels = @client.remove_label('pengwynn/linkedin', 2, 'oauth')
177
- assert labels.is_a?(Array)
178
- end
179
-
180
- should "add a comment to an issue" do
181
- stub_post("issues/comment/pengwynn/linkedin/2", "comment.json")
182
- comment = @client.add_comment('pengwynn/linkedin', 2, 'Nice catch!')
183
- comment.comment.should == 'Nice catch!'
184
- end
185
-
186
- should "watch a repository" do
187
- stub_post("repos/watch/pengwynn/linkedin", "repo.json")
188
- repo = @client.watch('pengwynn/linkedin')
189
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
190
- end
191
-
192
- should "unwatch a repository" do
193
- stub_post("repos/unwatch/pengwynn/linkedin", "repo.json")
194
- repo = @client.unwatch('pengwynn/linkedin')
195
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
196
- end
197
-
198
- should "fork a repository" do
199
- stub_post("repos/fork/pengwynn/linkedin", "repo.json")
200
- repo = @client.fork('pengwynn/linkedin')
201
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
202
- end
203
-
204
- should "create a repository" do
205
- stub_post("repos/create", "repo.json")
206
- repo = @client.create(:name => 'linkedin', :description => 'Ruby wrapper for the LinkedIn API', :homepage => 'http://bit.ly/ruby-linkedin', :public => 1)
207
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
208
- end
209
-
210
- # should "return a delete_token when calling delete without supplying a delete_token" do
211
- #
212
- # end
213
-
214
- should "set a repo's visibility to private" do
215
- stub_post("repos/set/private/linkedin", "repo.json")
216
- repo = @client.set_private('linkedin')
217
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
218
- end
219
-
220
- should "set a repo's visibility to public" do
221
- stub_post("repos/set/public/linkedin", "repo.json")
222
- repo = @client.set_public('linkedin')
223
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
224
- end
225
-
226
- should "return deploy keys for a repo" do
227
- stub_get("repos/keys/linkedin", "keys.json")
228
- keys = @client.deploy_keys('linkedin')
229
- keys.size.should == 6
230
- keys.last.title.should == 'wynn@pengwynn.local'
231
- end
232
-
233
- should "add a deploy key for a repo" do
234
- stub_post("repos/key/pengwynn/linkedin/add", "keys.json")
235
- keys = @client.add_deploy_key('pengwynn/linkedin', 'ssh-rsa 009aasd0kalsdfa-sd9a-sdf')
236
- keys.size.should == 6
237
- keys.last.title.should == 'wynn@pengwynn.local'
238
- end
239
-
240
- should "remove a deploy key for a repo" do
241
- stub_post("repos/key/pengwynn/linkedin/remove", "keys.json")
242
- keys = @client.remove_deploy_key('pengwynn/linkedin', 1234)
243
- keys.size.should == 6
244
- end
245
-
246
- should "add a collaborator to a repo" do
247
- stub_post("repos/collaborators/linkedin/add/adamstac", "collaborators.json")
248
- collaborators = @client.add_collaborator("linkedin", "adamstac")
249
- collaborators.first.should == 'pengwynn'
250
- end
251
-
252
- should "remove a collaborator from a repo" do
253
- stub_post("repos/collaborators/linkedin/remove/adamstac", "collaborators.json")
254
- collaborators = @client.remove_collaborator("linkedin", "adamstac")
255
- collaborators.last.should == 'adamstac'
256
- end
257
-
258
- should "fetch a user's public timeline" do
259
- stub_get("https://pengwynn%2Ftoken:OU812@github.com/pengwynn.json", "timeline.json")
260
- events = @client.public_timeline('pengwynn')
261
- events.first['type'].should == 'FollowEvent'
262
- events[1].repository.name.should == 'octokit'
263
- end
264
-
265
- should "fetch a user's private timeline" do
266
- stub_get("https://pengwynn%2Ftoken:OU812@github.com/pengwynn.private.json", "timeline.json")
267
- events = @client.timeline
268
- events.first['type'].should == 'FollowEvent'
269
- events[1].repository.name.should == 'octokit'
270
- end
271
- end
272
-
273
-
274
- context "when unauthenticated" do
275
-
276
- should "search users" do
277
- stub_get("user/search/wynn", "search-username.json")
278
- users = Octokit.search_users("wynn")
279
- users.first.username.should == 'pengwynn'
280
- end
281
-
282
- should "should search users by email" do
283
- stub_get("user/email/wynn.netherland@gmail.com", "search-email.json")
284
- users = Octokit.search_users("wynn.netherland@gmail.com")
285
- users.login.should == 'pengwynn'
286
- end
287
-
288
- should "return user info" do
289
- stub_get("user/show/pengwynn", "user.json")
290
- user = Octokit.user("pengwynn")
291
- user.login.should == 'pengwynn'
292
- user.blog.should == 'http://wynnnetherland.com'
293
- user.name.should == 'Wynn Netherland'
294
- end
295
-
296
- should "return followers for a user" do
297
- stub_get("user/show/pengwynn/followers", "followers.json")
298
- followers = Octokit.followers("pengwynn")
299
- followers.size.should == 21
300
- assert followers.include?("adamstac")
301
- end
302
-
303
- should "indicate if one user follows another" do
304
- stub_get("user/show/pengwynn/following", "followers.json")
305
- assert Octokit.follows?('pengwynn', 'adamstac')
306
- end
307
-
308
- should "return users a user follows" do
309
- stub_get("user/show/pengwynn/following", "followers.json")
310
- followers = Octokit.following("pengwynn")
311
- followers.size.should == 21
312
- assert followers.include?("adamstac")
313
- end
314
-
315
- should "return the repos a user watches" do
316
- stub_get("repos/watched/pengwynn", "repos.json")
317
- repos = Octokit.watched('pengwynn')
318
- repos.first.owner.should == 'jnunemaker'
319
- repos.first.forks.should == 120
320
- end
321
-
322
- should "search issues for a repo" do
323
- stub_get("issues/search/jnunemaker/twitter/open/httparty", "issues.json")
324
- issues = Octokit.search_issues({:username => 'jnunemaker', :repo => 'twitter'}, 'httparty')
325
- issues.first.title.should == 'Crack error when creating friendship'
326
- issues.first.votes.should == 2
327
- end
328
-
329
- should "list issues for a repo" do
330
- stub_get("issues/list/jnunemaker/twitter/open", "issues.json")
331
- issues = Octokit.issues({:username => 'jnunemaker', :repo => 'twitter'}, 'open')
332
- issues.first.title.should == 'Crack error when creating friendship'
333
- issues.first.votes.should == 2
334
- end
335
-
336
- should "return issue info" do
337
- stub_get("issues/show/jnunemaker/twitter/3", "issue.json")
338
- issue = Octokit.issue({:username => 'jnunemaker', :repo => 'twitter'}, 3)
339
- issue.title.should == 'Crack error when creating friendship'
340
- issue.votes.should == 2
341
- end
342
-
343
- # Repos
344
-
345
- should "search repos" do
346
- stub_get("repos/search/compass", "repo_search.json")
347
- repos = Octokit.search_repos("compass")
348
- repos.first.username.should == 'chriseppstein'
349
- repos.first.language.should == 'Ruby'
350
- end
351
-
352
- should "return repo information" do
353
- stub_get("repos/show/pengwynn/linkedin", "repo.json")
354
- repo = Octokit.repo({:username => "pengwynn", :repo => "linkedin"})
355
- repo.homepage.should == "http://bit.ly/ruby-linkedin"
356
- end
357
-
358
- should "return a repo's contributors list" do
359
- stub_get("repos/show/pengwynn/linkedin/contributors", "contributors.json")
360
- contributors_list = Octokit.contributors({:username => "pengwynn", :repo => "linkedin"})
361
- assert contributors_list.include?(["holman", 1])
362
- end
363
-
364
- should "list repos for a user" do
365
- stub_get("repos/show/pengwynn", "repos.json")
366
- repos = Octokit.list_repos('pengwynn')
367
- repos.first.name.should == 'twitter'
368
- repos.first.watchers.should == 609
369
- end
370
-
371
- should "list collaborators for a repo" do
372
- stub_get("repos/show/pengwynn/octokit/collaborators", "collaborators.json")
373
- users = Octokit.collaborators({:username => "pengwynn", :repo => "octokit"})
374
- users.last.should == 'adamstac'
375
- end
376
-
377
- should "show the network for a repo" do
378
- stub_get("repos/show/pengwynn/linkedin/network", "network.json")
379
- network = Octokit.network({:username => 'pengwynn', :repo => "linkedin"})
380
- network.last.owner.should == 'nfo'
381
- end
382
-
383
- should "show the language breakdown for a repo" do
384
- stub_get("repos/show/pengwynn/linkedin/languages", "languages.json")
385
- languages = Octokit.languages({:username => 'pengwynn', :repo => "linkedin"})
386
- languages['Ruby'].should == 21515
387
- end
388
-
389
- should "list all the tags in a repo" do
390
- stub_get("repos/show/pengwynn/linkedin/tags", "tags.json")
391
- tags = Octokit.tags(:username => 'pengwynn', :repo => "linkedin")
392
- assert tags.include?("v0.0.1")
393
- end
394
-
395
- should "list all the branches in a repo" do
396
- stub_get("repos/show/pengwynn/linkedin/branches", "branches.json")
397
- branches = Octokit.branches(:username => 'pengwynn', :repo => "linkedin")
398
- assert branches.include?("integration")
399
- end
400
-
401
- # network
402
- should "return network meta info for a repo" do
403
- stub_get("https://github.com/schacon/simplegit/network_meta", "network_meta.json")
404
- info = Octokit.network_meta(:username => "schacon", :repo => "simplegit")
405
- info.users.first.name.should == 'schacon'
406
- info.users.first.repo.should == 'simplegit'
407
- end
408
-
409
- should "return first 100 commits by branch" do
410
- stub_get("https://github.com/schacon/simplegit/network_data_chunk?nethash=fa8fe264b926cdebaab36420b6501bd74402a6ff", "network_data.json")
411
- info = Octokit.network_data({:username => "schacon", :repo => "simplegit"}, "fa8fe264b926cdebaab36420b6501bd74402a6ff")
412
- assert info.is_a?(Array)
413
- end
414
-
415
- # trees
416
- should "return contents of a tree by tree SHA" do
417
- stub_get("tree/show/defunkt/facebox/a47803c9ba26213ff194f042ab686a7749b17476", "trees.json")
418
- trees = Octokit.tree({:username => "defunkt", :repo => "facebox"}, "a47803c9ba26213ff194f042ab686a7749b17476")
419
- trees.first.name.should == '.gitignore'
420
- trees.first.sha.should == 'e43b0f988953ae3a84b00331d0ccf5f7d51cb3cf'
421
- end
422
-
423
- should "return data about a blob by tree SHA and path" do
424
- stub_get("blob/show/defunkt/facebox/d4fc2d5e810d9b4bc1ce67702603080e3086a4ed/README.txt", "blob.json")
425
- blob = Octokit.blob({:username => "defunkt", :repo => "facebox"}, "d4fc2d5e810d9b4bc1ce67702603080e3086a4ed", "README.txt")
426
- blob.name.should == 'README.txt'
427
- blob.sha.should == 'd4fc2d5e810d9b4bc1ce67702603080e3086a4ed'
428
- end
429
-
430
- should "return the contents of a blob with the blob's SHA" do
431
- begin
432
- Octokit.format = :yaml
433
- stub_get("blob/show/defunkt/facebox/4bf7a39e8c4ec54f8b4cd594a3616d69004aba69", "raw_git_data.yaml")
434
- raw_text = Octokit.raw({:username => "defunkt", :repo => "facebox"}, "4bf7a39e8c4ec54f8b4cd594a3616d69004aba69")
435
- ensure
436
- Octokit.format = :json
437
- end
438
- assert raw_text.include?("cd13d9a61288dceb0a7aa73b55ed2fd019f4f1f7")
439
- end
440
-
441
- #commits
442
- should "list commits for a repo's master branch by default" do
443
- stub_get("commits/list/defunkt/facebox/master", "commits.json")
444
- commits_list = Octokit.list_commits({:username => "defunkt", :repo => "facebox"})
445
- assert commits_list.any? { |c| c.message == "Fixed CSS expression, throwing errors in IE6." }
446
- end
447
-
448
- should "list commits for a repo on a given branch" do
449
- stub_get("commits/list/schacon/simplegit/m/dev/cp", "branch_commits.json")
450
- commits_list = Octokit.list_commits({:username => "schacon", :repo => "simplegit"}, "m/dev/cp")
451
- assert commits_list.any? { |c| c.message == "removed unnecessary test code" }
452
- end
453
-
454
- should "show a specific commit for a repo given its SHA" do
455
- sha = "1ff368f79b0f0aa0e1f1d78bcaa8691f94f9703e"
456
- stub_get("commits/show/defunkt/facebox/#{sha}", "show_commit.json")
457
- show_commit = Octokit.commit({:username => "defunkt", :repo => "facebox"}, sha)
458
- assert show_commit.message == "Fixed CSS expression, throwing errors in IE6."
459
- end
460
-
461
- #timeline
462
-
463
- should "fetch the public timeline" do
464
- stub_get("https://github.com/timeline.json", "timeline.json")
465
- events = Octokit.public_timeline
466
- events.first['type'].should == 'FollowEvent'
467
- events[1].repository.name.should == 'octokit'
468
- end
469
-
470
- should "fetch a user's public timeline" do
471
- stub_get("https://github.com/pengwynn.json", "timeline.json")
472
- events = Octokit.public_timeline('pengwynn')
473
- events.first['type'].should == 'FollowEvent'
474
- events[1].repository.name.should == 'octokit'
475
- end
476
-
477
- end
478
-
479
- context "when Github responds with an error" do
480
- {
481
- ["400", "BadRequest"] => Octokit::BadRequest,
482
- ["401", "Unauthorized"] => Octokit::Unauthorized,
483
- ["403", "Forbidden"] => Octokit::Forbidden,
484
- ["404", "NotFound"] => Octokit::NotFound,
485
- ["406", "NotAcceptable"] => Octokit::NotAcceptable,
486
- ["500", "InternalServerError"] => Octokit::InternalServerError,
487
- ["501", "NotImplemented"] => Octokit::NotImplemented,
488
- ["502", "BadGateway"] => Octokit::BadGateway,
489
- ["503", "ServiceUnavailable"] => Octokit::ServiceUnavailable,
490
- }.each do |status, exception|
491
- context "#{status.first}, a get" do
492
- should "raise an #{exception.name} error" do
493
- stub_get("user/show/pengwynn", nil, status)
494
- lambda { Octokit.user("pengwynn") }.should raise_error(exception)
495
- end
496
- end
497
-
498
- context "#{status.first}, a post" do
499
- should "raise an #{exception.name} error" do
500
- @client = Octokit::Client.new(:login => 'pengwynn', :token => 'OU812')
501
- stub_post("user/show/pengwynn", nil, status)
502
- lambda { @client.update_user(:location => "Dallas, TX") }.should raise_error(exception)
503
- end
504
- end
505
- end
506
- end
507
-
508
- context "when consuming feeds" do
509
-
510
- should "should set user, title, and published time for the event" do
511
- entry = Hashie::Mash.new({
512
- :id => 'tag:github.com,2008:CreateEvent/110645788',
513
- :published => '2009-12-12T11:24:14-08:00',
514
- :updated => '2009-12-12T11:24:14-08:00',
515
- :links => ['http://github.com/jnunemaker/twitter/tree/v0.7.10'],
516
- :title => 'pengwynn created tag v0.7.10 at jnunemaker/twitter',
517
- :author => 'pengwynn'
518
- })
519
-
520
- event = Octokit::Event.load_from_atom(entry)
521
- event.user.should == 'pengwynn'
522
- event.published.year.should == 2009
523
- event.published.month.should == 12
524
- event.id.should == 110645788
525
- event.title.should == 'pengwynn created tag v0.7.10 at jnunemaker/twitter'
526
- event.links.first.should == 'http://github.com/jnunemaker/twitter/tree/v0.7.10'
527
- end
528
-
529
- should "should create a repo event from an atom entry" do
530
- entry = Hashie::Mash.new({
531
- :id => 'tag:github.com,2008:CreateEvent/110645788',
532
- :published => '2009-12-12T11:24:14-08:00',
533
- :updated => '2009-12-12T11:24:14-08:00',
534
- :links => ['http://github.com/Tanner/Team-1261---Java'],
535
- :title => 'Tanner created repository Team-1261---Java',
536
- :author => 'Tanner'
537
- })
538
-
539
- event = Octokit::Event.load_from_atom(entry)
540
- event.event_type.should == 'repo'
541
- event.repo.username.should == 'Tanner'
542
- event.repo.name.should == 'Team-1261---Java'
543
- end
544
-
545
- should "should create a tag event from an atom entry" do
546
- entry = Hashie::Mash.new({
547
- :id => 'tag:github.com,2008:CreateEvent/110645788',
548
- :published => '2009-12-12T11:24:14-08:00',
549
- :updated => '2009-12-12T11:24:14-08:00',
550
- :links => ['http://github.com/jnunemaker/twitter/tree/v0.7.10'],
551
- :title => 'pengwynn created tag v0.7.10 at jnunemaker/twitter',
552
- :author => 'pengwynn'
553
- })
554
-
555
- event = Octokit::Event.load_from_atom(entry)
556
- event.event_type.should == 'tag'
557
- event.repo.username.should == 'jnunemaker'
558
- event.repo.name.should == 'twitter'
559
- event.tag.should == 'v0.7.10'
560
- end
561
-
562
- should "should create a branch event from an atom entry" do
563
- entry = Hashie::Mash.new({
564
- :id => 'tag:github.com,2008:CreateEvent/110645788',
565
- :published => '2009-12-12T11:24:14-08:00',
566
- :updated => '2009-12-12T11:24:14-08:00',
567
- :links => ['http://github.com/Fabi/cwcore/tree/cwcore-0.1'],
568
- :title => 'cwcore created branch cwcore-0.1 at Fabi/cwcore',
569
- :author => 'cwcore'
570
- })
571
-
572
- event = Octokit::Event.load_from_atom(entry)
573
- event.event_type.should == 'branch'
574
- event.repo.username.should == 'Fabi'
575
- event.repo.name.should == 'cwcore'
576
- event.user.should == 'cwcore'
577
- event.branch.should == 'cwcore-0.1'
578
- end
579
-
580
- should "should create a push event from an atom entry" do
581
- entry = Hashie::Mash.new({
582
- :id => 'tag:github.com,2008:PushEvent/110645788',
583
- :published => '2009-12-12T11:24:14-08:00',
584
- :updated => '2009-12-12T11:24:14-08:00',
585
- :links => ['http://github.com/jnunemaker/twitter/commits/master'],
586
- :title => 'pengwynn pushed to master at jnunemaker/twitter',
587
- :author => 'pengwynn'
588
- })
589
-
590
- event = Octokit::Event.load_from_atom(entry)
591
- event.event_type.should == 'push'
592
- event.repo.name.should == 'twitter'
593
- event.branch.should == 'master'
594
- end
595
-
596
- should "should create a fork event from an atom entry" do
597
- entry = Hashie::Mash.new({
598
- :id => 'tag:github.com,2008:ForkEvent/110645788',
599
- :published => '2009-12-12T11:24:14-08:00',
600
- :updated => '2009-12-12T11:24:14-08:00',
601
- :links => ['http://github.com/klauge/aeon/'],
602
- :title => 'klauge forked djh/aeon',
603
- :author => 'klauge'
604
- })
605
-
606
- event = Octokit::Event.load_from_atom(entry)
607
- event.event_type.should == 'fork'
608
- event.repo.username.should == 'klauge'
609
- event.repo.name.should == 'aeon'
610
- event.forked_from.username.should == 'djh'
611
- end
612
-
613
- should "should create a watch event from an atom entry" do
614
- entry = Hashie::Mash.new({
615
- :id => 'tag:github.com,2008:WatchEvent/110645788',
616
- :published => '2009-12-12T11:24:14-08:00',
617
- :updated => '2009-12-12T11:24:14-08:00',
618
- :links => ['http://github.com/bogolisk/egg'],
619
- :title => 'jpablobr started watching bogolisk/egg',
620
- :author => 'jpablobr'
621
- })
622
-
623
- event = Octokit::Event.load_from_atom(entry)
624
- event.event_type.should == 'watch'
625
- event.repo.username.should == 'bogolisk'
626
- event.repo.name.should == 'egg'
627
- end
628
-
629
- should "should create a follow event from an atom entry" do
630
- entry = Hashie::Mash.new({
631
- :id => 'tag:github.com,2008:FollowEvent/110645788',
632
- :published => '2009-12-12T11:24:14-08:00',
633
- :updated => '2009-12-12T11:24:14-08:00',
634
- :links => ['http://github.com/swistak'],
635
- :title => 'pengwynn started following swistak',
636
- :author => 'pengwynn'
637
- })
638
-
639
- event = Octokit::Event.load_from_atom(entry)
640
- event.event_type.should == 'follow'
641
- event.repo.should == nil
642
- event.target_user.should == 'swistak'
643
- end
644
-
645
- should "should create an issues event from an atom entry" do
646
- entry = Hashie::Mash.new({
647
- :id => 'tag:github.com,2008:IssuesEvent/110645788',
648
- :published => '2009-12-12T11:24:14-08:00',
649
- :updated => '2009-12-12T11:24:14-08:00',
650
- :links => ['http://github.com/jnunemaker/twitter/issues/19/find'],
651
- :title => 'pengwynn closed issue 19 on jnunemaker/twitter',
652
- :author => 'pengwynn'
653
- })
654
-
655
- event = Octokit::Event.load_from_atom(entry)
656
- event.event_type.should == 'issue'
657
- event.repo.name.should == 'twitter'
658
- event.action.should == 'closed'
659
- event.issue_number.should == 19
660
- end
661
-
662
- should "should create a gist event from an atom entry" do
663
- entry = Hashie::Mash.new({
664
- :id => 'tag:github.com,2008:GistEvent/110645788',
665
- :published => '2009-12-12T11:24:14-08:00',
666
- :updated => '2009-12-12T11:24:14-08:00',
667
- :links => ['http://gist.github.com/253987'],
668
- :title => 'pengwynn created gist: 253987',
669
- :author => 'pengwynn'
670
- })
671
-
672
- event = Octokit::Event.load_from_atom(entry)
673
- event.event_type.should == 'gist'
674
- event.repo.should == nil
675
- event.gist_number.should == 253987
676
- end
677
-
678
- should "should create a member event from an atom entry" do
679
- entry = Hashie::Mash.new({
680
- :id => 'tag:github.com,2008:MemberEvent/110645788',
681
- :published => '2009-12-12T11:24:14-08:00',
682
- :updated => '2009-12-12T11:24:14-08:00',
683
- :links => ['http://github.com/pengwynn/octokit'],
684
- :title => 'pengwynn added adamstac to octokit',
685
- :author => 'pengwynn'
686
- })
687
-
688
- event = Octokit::Event.load_from_atom(entry)
689
- event.event_type.should == 'member'
690
- event.repo.name.should == 'octokit'
691
- event.target_user.should == 'adamstac'
692
- end
693
-
694
- should "should create a fork_apply event from an atom entry" do
695
- entry = Hashie::Mash.new({
696
- :id => 'tag:github.com,2008:ForkApplyEvent/110645788',
697
- :published => '2009-12-12T11:24:14-08:00',
698
- :updated => '2009-12-12T11:24:14-08:00',
699
- :links => ['http://github.com/pengwynn/linkedin/tree/integration'],
700
- :title => 'pengwynn applied fork commits to linkedin/integration',
701
- :author => 'pengwynn'
702
- })
703
-
704
- event = Octokit::Event.load_from_atom(entry)
705
- event.event_type.should == 'fork_apply'
706
- event.repo.name.should == 'linkedin'
707
- event.branch.should == 'integration'
708
- end
709
-
710
- should "should create a wiki event from an atom entry" do
711
- entry = Hashie::Mash.new({
712
- :id => 'tag:github.com,2008:WikiEvent/110645788',
713
- :published => '2009-12-12T11:24:14-08:00',
714
- :updated => '2009-12-12T11:24:14-08:00',
715
- :links => ['http://github.com/dxw/Fammel/wikis/documentation'],
716
- :title => 'dxw edited a page in the dxw/Fammel wiki',
717
- :author => 'dxw'
718
- })
719
-
720
- event = Octokit::Event.load_from_atom(entry)
721
- event.event_type.should == 'wiki'
722
- event.repo.name.should == 'Fammel'
723
- event.page.should == 'documentation'
724
- end
725
-
726
- should "should create a comment event from an atom entry" do
727
- entry = Hashie::Mash.new({
728
- :id => 'tag:github.com,2008:CommitCommentEvent/110645788',
729
- :published => '2009-12-12T11:24:14-08:00',
730
- :updated => '2009-12-12T11:24:14-08:00',
731
- :links => ['http://github.com/fakechris/resque/commit/46f7ff1f73ae16ca8060fa3b051900562b51d5c2#-P0'],
732
- :title => 'defunkt commented on fakechris/resque',
733
- :author => 'defunkt'
734
- })
735
-
736
- event = Octokit::Event.load_from_atom(entry)
737
- event.event_type.should == 'comment'
738
- event.repo.name.should == 'resque'
739
- end
740
-
741
- should "should create a delete event from an atom entry" do
742
- entry = Hashie::Mash.new({
743
- :id => 'tag:github.com,2008:DeleteEvent/110645788',
744
- :published => '2009-12-12T11:24:14-08:00',
745
- :updated => '2009-12-12T11:24:14-08:00',
746
- :links => ['http://github.com/jinzhu'],
747
- :title => 'jinzhu deleted branch search at jinzhu/vimlike-smooziee',
748
- :author => 'jinzhu'
749
- })
750
-
751
- event = Octokit::Event.load_from_atom(entry)
752
- event.event_type.should == 'delete'
753
- event.repo.name.should == 'vimlike-smooziee'
754
- event.branch.should == 'search'
755
- end
756
-
757
- should "should create a public event from an atom entry" do
758
- entry = Hashie::Mash.new({
759
- :id => 'tag:github.com,2008:PublicEvent/110645788',
760
- :published => '2009-12-12T11:24:14-08:00',
761
- :updated => '2009-12-12T11:24:14-08:00',
762
- :links => ['http://github.com/intalio'],
763
- :title => 'intalio open sourced bpmn2',
764
- :author => 'intalio'
765
- })
766
-
767
- event = Octokit::Event.load_from_atom(entry)
768
- event.event_type.should == 'public'
769
- event.repo.name.should == 'bpmn2'
770
- end
771
-
772
- should "should create a download event from an atom entry" do
773
- entry = Hashie::Mash.new({
774
- :id => 'tag:github.com,2008:DownloadEvent/110645788',
775
- :published => '2009-12-12T11:24:14-08:00',
776
- :updated => '2009-12-12T11:24:14-08:00',
777
- :links => ['http://github.com/tobie'],
778
- :title => 'tobie uploaded a file to sstephenson/prototype',
779
- :author => 'tobie'
780
- })
781
-
782
- event = Octokit::Event.load_from_atom(entry)
783
- event.event_type.should == 'download'
784
- event.repo.name.should == 'prototype'
785
- end
786
-
787
- end
788
-
789
- end