gh 0.13.0 → 0.13.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gh/error.rb +2 -2
  3. data/lib/gh/response.rb +1 -1
  4. data/lib/gh/version.rb +1 -1
  5. metadata +6 -94
  6. data/.gitignore +0 -4
  7. data/.travis.yml +0 -19
  8. data/Gemfile +0 -6
  9. data/README.md +0 -117
  10. data/Rakefile +0 -6
  11. data/gh.gemspec +0 -28
  12. data/spec/cache_spec.rb +0 -28
  13. data/spec/custom_limit_spec.rb +0 -23
  14. data/spec/error_spec.rb +0 -55
  15. data/spec/gh_spec.rb +0 -32
  16. data/spec/instrumentation_spec.rb +0 -30
  17. data/spec/lazy_loader_spec.rb +0 -63
  18. data/spec/link_follower_spec.rb +0 -24
  19. data/spec/merge_commit_spec.rb +0 -24
  20. data/spec/normalizer_spec.rb +0 -319
  21. data/spec/pagination_spec.rb +0 -32
  22. data/spec/parallel_spec.rb +0 -95
  23. data/spec/payloads/.yml +0 -3
  24. data/spec/payloads/repos/rkh/gh/contents/README.md_per_page_100.yml +0 -15
  25. data/spec/payloads/repos/rkh/test-project-1.yml +0 -23
  26. data/spec/payloads/repos/sinatra/sinatra/issues/56/comments.yml +0 -36
  27. data/spec/payloads/repos/sinatra/sinatra/issues/comments/383214.yml +0 -21
  28. data/spec/payloads/repos/sinatra/sinatra/pulls/56.yml +0 -23
  29. data/spec/payloads/repos/travis-repos/test-project-1.yml +0 -21
  30. data/spec/payloads/repos/travis-repos/test-project-1/git/commits/ca3c0a44ec1d9bf8557d2653aa1b79fcc9ff5f5d.yml +0 -23
  31. data/spec/payloads/repos/travis-repos/test-project-1/git/refs/pull/1.yml +0 -20
  32. data/spec/payloads/repos/travis-repos/test-project-1/pulls/1.yml +0 -24
  33. data/spec/payloads/users/rkh.yml +0 -22
  34. data/spec/payloads/users/rkh/repos.yml +0 -52
  35. data/spec/payloads/users/rkh/repos_page_2&per_page=100.yml +0 -49
  36. data/spec/payloads/users/rkh/repos_page_2.yml +0 -54
  37. data/spec/payloads/users/rkh/repos_page_2_per_page_100.yml +0 -49
  38. data/spec/payloads/users/rkh/repos_page_3.yml +0 -57
  39. data/spec/payloads/users/rkh/repos_page_4.yml +0 -56
  40. data/spec/payloads/users/rkh/repos_page_5.yml +0 -28
  41. data/spec/payloads/users/rkh/repos_per_page_100.yml +0 -121
  42. data/spec/payloads/users/rkh_per_page_100.yml +0 -21
  43. data/spec/payloads/users/rtomayko.yml +0 -21
  44. data/spec/payloads/users/svenfuchs.yml +0 -21
  45. data/spec/payloads/users/travis-repos.yml +0 -21
  46. data/spec/pull_request_hook.json +0 -181
  47. data/spec/remote_spec.rb +0 -48
  48. data/spec/response_spec.rb +0 -19
  49. data/spec/spec_helper.rb +0 -88
  50. data/spec/stack_spec.rb +0 -5
  51. data/spec/token_check_spec.rb +0 -27
  52. data/spec/wrapper_spec.rb +0 -5
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GH do
4
- it 'allows doing requests right from the GH object' do
5
- GH['users/rkh']['name'].should be == "Konstantin Haase"
6
- end
7
-
8
- it 'allows posting to github' do
9
- stub_request(:post, "https://api.github.com/somewhere").
10
- with(:body => "{\"foo\":\"bar\"}").to_return(:status => 200, :body => '{"hi": "ho"}', :headers => {})
11
- response = GH.post "somewhere", "foo" => "bar"
12
- response['hi'].should be == 'ho'
13
- end
14
-
15
- describe 'with' do
16
- it 'returns the GH instance if no block is given' do
17
- GH.with(:token => "...").should be_a(GH::Wrapper)
18
- end
19
-
20
- it 'returns the block value if block is given' do
21
- GH.with(:token => "...") { 42 }.should be == 42
22
- end
23
-
24
- it 'propagates options' do
25
- GH.with(:a => :b) do
26
- GH.with(:b => :c) do
27
- GH.options.should be == {:a => :b, :b => :c}
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GH::Instrumentation do
4
- before do
5
- @events = []
6
- subject.instrumenter = proc { |*a, &b| @events << a and b[] }
7
- stub_request(:get, "https://api.github.com/").to_return :body => "{}"
8
- end
9
-
10
- it 'instruments http' do
11
- subject.http :get, '/'
12
- @events.size.should be == 1
13
- @events.first.should be == ['http.gh', {:verb => :get, :url => '/', :gh => subject}]
14
- end
15
-
16
- it 'instruments []' do
17
- subject['/']
18
- @events.size.should be == 2
19
- @events.should be == [
20
- ['access.gh', {:key => '/', :gh => subject}],
21
- ['http.gh', {:verb => :get, :url => '/', :gh => subject}]
22
- ]
23
- end
24
-
25
- it 'instruments load' do
26
- subject.load("[]")
27
- @events.size.should be == 1
28
- @events.first.should be == ['load.gh', {:data => "[]", :gh => subject}]
29
- end
30
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GH::LazyLoader do
4
- before { subject.backend = GH::Normalizer.new(GH::MockBackend.new) }
5
-
6
- let! :raw do
7
- hash = subject.backend['users/rkh'].to_hash
8
- hash.delete 'name'
9
- hash
10
- end
11
-
12
- let :rkh do
13
- subject.load(raw)
14
- end
15
-
16
- it 'wraps normalizer by default' do
17
- GH::LazyLoader.new.backend.should be_a(GH::Normalizer)
18
- end
19
-
20
- it 'send http requests for missing fields' do
21
- should_request(1) { rkh['name'].should be == 'Konstantin Haase' }
22
- end
23
-
24
- it 'does not send http requests for existing fields' do
25
- should_not_request { rkh['login'].should be == 'rkh' }
26
- end
27
-
28
- it 'allows traversing into nested structures' do
29
- sven = subject.backend['users/svenfuchs'].to_hash
30
- sven['friends'] = [raw]
31
- sven.delete 'name'
32
-
33
- sven = subject.load(sven)
34
- should_request(1) { sven['friends'][0]['name'].should be == 'Konstantin Haase' }
35
- end
36
-
37
- it 'does not request twice if the field does not exist upstream' do
38
- should_request(1) { 2.times { rkh['foo'] } }
39
- end
40
-
41
- it 'does not skip an already existing default proc' do
42
- count = 0
43
- raw.default_proc = proc { |hash, key| count += 1 if key == 'foo' }
44
- rkh = subject.load(raw)
45
-
46
- should_not_request do
47
- rkh['foo'].should be == 1
48
- rkh['foo'].should be == 2
49
- end
50
- end
51
-
52
- it 'is still loading missing fields, even if a default proc is set' do
53
- count = 0
54
- raw.default_proc = proc { |hash, key| count += 1 if key == 'foo' }
55
- rkh = subject.load(raw)
56
-
57
- should_request 1 do
58
- rkh['foo'].should be == 1
59
- rkh['name'].should be == 'Konstantin Haase'
60
- rkh['foo'].should be == 2
61
- end
62
- end
63
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GH::LinkFollower do
4
- before { subject.backend = GH::Normalizer.new(GH::MockBackend.new) }
5
-
6
- let(:pull_request) { subject['/repos/sinatra/sinatra/pulls/56'] }
7
- let(:comments) { pull_request['comments'] }
8
- let(:comment) { comments.first }
9
- let(:commentator) { comment['owner'] }
10
-
11
- it 'follows links' do
12
- commentator['login'].should be == 'rtomayko'
13
- end
14
-
15
- it 'works with lazy loading' do
16
- subject.backend = GH::LazyLoader.new(subject.backend)
17
- # location is not included in the comment payload
18
- commentator["location"].should be == "San Francisco"
19
- end
20
-
21
- it 'does not raise exceptions for unknown fields' do
22
- commentator["location"].should be_nil
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GH::MergeCommit do
4
- let(:file) { File.expand_path('../pull_request_hook.json', __FILE__) }
5
- let(:payload) { File.read file }
6
- let(:gh) { GH.load payload }
7
- let(:pull_request) { gh['pull_request'] }
8
-
9
- it 'adds merge commits' do
10
- pull_request['merge_commit']['sha'].should_not be_nil
11
- end
12
-
13
- it 'adds base commits' do
14
- pull_request['base_commit']['sha'].should_not be_nil
15
- end
16
-
17
- it 'adds head commits' do
18
- pull_request['head_commit']['sha'].should_not be_nil
19
- end
20
-
21
- it 'allows lazy loading on the commit' do
22
- pull_request['merge_commit']['committer']['name'] == 'GitHub Merge Button'
23
- end
24
- end
@@ -1,319 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GH::Normalizer do
4
- before { subject.backend = GH::MockBackend.new }
5
-
6
- def normalize(payload)
7
- data[subject.path_for('/payload')] = payload
8
- end
9
-
10
- def with_headers(headers = {})
11
- response = GH::Response.new("{}", headers)
12
- data[subject.path_for('/payload')], response.data = response, data[subject.path_for('/payload')]
13
- end
14
-
15
- def normalized
16
- subject[subject.path_for('/payload')]
17
- end
18
-
19
- it 'is set up properly' do
20
- backend.frontend.should be_a(GH::Normalizer)
21
- end
22
-
23
- it 'leaves unknown fields in place' do
24
- normalize 'foo' => 'bar'
25
- normalized['foo'].should be == 'bar'
26
- end
27
-
28
- it 'allows normalization with #load' do
29
- result = subject.load("org" => "foo")
30
- result.should_not include("org")
31
- result["organization"].should be == "foo"
32
- end
33
-
34
- it 'works for deeply nested fields'
35
- it 'works for lists'
36
-
37
- context 'date fields' do
38
- it 'generates date from timestamp'
39
- end
40
-
41
- context 'renaming' do
42
- def self.renames(a, b)
43
- it "renames #{a} to #{b}" do
44
- normalize a => "foo"
45
- normalized.should_not include(a)
46
- normalized.should include(b)
47
- normalized[b].should be == "foo"
48
- end
49
- end
50
-
51
- renames 'org', 'organization'
52
- renames 'orgs', 'organizations'
53
- renames 'username', 'login'
54
- renames 'repo', 'repository'
55
- renames 'repos', 'repositories'
56
- renames 'repo_foo', 'repository_foo'
57
- renames 'repos_foo', 'repository_foo'
58
- renames 'foo_repo', 'foo_repository'
59
- renames 'foo_repos', 'foo_repositories'
60
-
61
- it 'renames commit to sha if value is a sha' do
62
- normalize 'commit' => 'd0f4aa01f100c26c6eae17ea637f46cf150d9c1f'
63
- normalized.should_not include('commit')
64
- normalized.should include('sha')
65
- normalized['sha'].should be == 'd0f4aa01f100c26c6eae17ea637f46cf150d9c1f'
66
- end
67
-
68
- it 'does not rename commit to sha if value is not a sha' do
69
- normalize 'commit' => 'foo'
70
- normalized.should include('commit')
71
- normalized.should_not include('sha')
72
- normalized['commit'].should be == 'foo'
73
- end
74
-
75
- it 'renames commit_id to sha if value is a sha' do
76
- normalize 'commit_id' => 'd0f4aa01f100c26c6eae17ea637f46cf150d9c1f'
77
- normalized.should_not include('commit_id')
78
- normalized.should include('sha')
79
- normalized['sha'].should be == 'd0f4aa01f100c26c6eae17ea637f46cf150d9c1f'
80
- end
81
-
82
- it 'does not rename commit_id to sha if value is not a sha' do
83
- normalize 'commit_id' => 'foo'
84
- normalized.should include('commit_id')
85
- normalized.should_not include('sha')
86
- normalized['commit_id'].should be == 'foo'
87
- end
88
-
89
- it 'renames comments to comment_count if content is a number' do
90
- normalize 'comments' => 42
91
- normalized.should include('comment_count')
92
- normalized.should_not include('comments')
93
- normalized['comment_count'].should be == 42
94
- end
95
-
96
- it 'renames repositories to repository_count if content is a number' do
97
- normalize 'repositories' => 42
98
- normalized.should include('repository_count')
99
- normalized.should_not include('repositories')
100
- normalized['repository_count'].should be == 42
101
- end
102
-
103
- it 'renames repos to repository_count if content is a number' do
104
- normalize 'repos' => 42
105
- normalized.should include('repository_count')
106
- normalized.should_not include('repos')
107
- normalized['repository_count'].should be == 42
108
- end
109
-
110
- it 'renames forks to fork_count if content is a number' do
111
- normalize 'forks' => 42
112
- normalized.should include('fork_count')
113
- normalized.should_not include('forks')
114
- normalized['fork_count'].should be == 42
115
- end
116
-
117
- it 'does not rename comments to comment_count if content is not a number' do
118
- normalize 'comments' => 'foo'
119
- normalized.should include('comments')
120
- normalized.should_not include('comment_count')
121
- normalized['comments'].should be == 'foo'
122
- end
123
-
124
- it 'does not rename repositories to repository_count if content is not a number' do
125
- normalize 'repositories' => 'foo'
126
- normalized.should include('repositories')
127
- normalized.should_not include('repository_count')
128
- normalized['repositories'].should be == 'foo'
129
- end
130
-
131
- it 'does not rename repos to repository_count if content is not a number' do
132
- normalize 'repos' => 'foo'
133
- normalized.should include('repositories')
134
- normalized.should_not include('repository_count')
135
- normalized['repositories'].should be == 'foo'
136
- end
137
-
138
- it 'does not rename forks to fork_count if content is not a number' do
139
- normalize 'forks' => 'foo'
140
- normalized.should include('forks')
141
- normalized.should_not include('fork_count')
142
- normalized['forks'].should be == 'foo'
143
- end
144
-
145
- it 'renames user to owner if appropriate' do
146
- normalize 'user' => 'me', 'created_at' => Time.now.xmlschema
147
- normalized.should_not include('user')
148
- normalized.should include('owner')
149
- normalized['owner'].should be == 'me'
150
- end
151
-
152
- it 'renames user to author if appropriate' do
153
- normalize 'user' => 'me', 'committed_at' => Time.now.xmlschema
154
- normalized.should_not include('user')
155
- normalized.should include('author')
156
- normalized['author'].should be == 'me'
157
- end
158
-
159
- it 'leaves user in place if owner exists' do
160
- normalize 'user' => 'me', 'created_at' => Time.now.xmlschema, 'owner' => 'you'
161
- normalized.should include('user')
162
- normalized.should include('owner')
163
- normalized['user'].should be == 'me'
164
- normalized['owner'].should be == 'you'
165
- end
166
-
167
- it 'leaves user in place if author exists' do
168
- normalize 'user' => 'me', 'committed_at' => Time.now.xmlschema, 'author' => 'you'
169
- normalized.should include('user')
170
- normalized.should include('author')
171
- normalized['user'].should be == 'me'
172
- normalized['author'].should be == 'you'
173
- end
174
-
175
- it 'leaves user in place if no indication what kind of user' do
176
- normalize 'user' => 'me'
177
- normalized.should_not include('owner')
178
- normalized.should_not include('author')
179
- normalized.should include('user')
180
- normalized['user'].should be == 'me'
181
- end
182
-
183
- it 'copies author to committer' do
184
- normalize 'author' => 'me'
185
- normalized.should include('author')
186
- normalized.should include('committer')
187
- normalized['author'].should be == 'me'
188
- end
189
-
190
- it 'copies committer to author' do
191
- normalize 'committer' => 'me'
192
- normalized.should include('author')
193
- normalized.should include('committer')
194
- normalized['author'].should be == 'me'
195
- end
196
-
197
- it 'does not override committer or author if both exist' do
198
- normalize 'committer' => 'me', 'author' => 'you'
199
- normalized.should include('author')
200
- normalized.should include('committer')
201
- normalized['author'].should be == 'you'
202
- normalized['committer'].should be == 'me'
203
- end
204
- end
205
-
206
- context 'time' do
207
- it 'transforms timestamps stored in "timestamp" to a date in "date"' do
208
- normalize 'timestamp' => 1234
209
- normalized['date'].should be == "1970-01-01T00:20:34Z"
210
- end
211
-
212
- it 'transforms dates stored in "timestamp" to a date in "date"' do
213
- normalize 'timestamp' => "2012-04-12T17:29:51+02:00"
214
- normalized['date'].should be == "2012-04-12T15:29:51Z"
215
- end
216
-
217
- it 'changes date to UTC' do
218
- normalize 'date' => "2012-04-12T17:29:51+02:00"
219
- normalized['date'].should be == "2012-04-12T15:29:51Z"
220
- end
221
-
222
- it 'changes any time entry to UTC' do
223
- normalize 'foo' => "2012-04-12T17:29:51+02:00"
224
- normalized['foo'].should be == "2012-04-12T15:29:51Z"
225
- end
226
-
227
- it 'does not choke on empty values' do
228
- normalize 'date' => ""
229
- normalized['date'].should be == ""
230
- end
231
- end
232
-
233
- context 'links' do
234
- it 'does not normalize config' do
235
- normalize 'config' => {'url' => 'http://localhost'}
236
- normalized['config'].should be == {'url' => 'http://localhost'}
237
- end
238
-
239
- it 'generates link entries from link headers' do
240
- pending
241
- normalize '_links' => {'href' => 'foo'}
242
- with_headers
243
-
244
- normalized.headers.should include("Link")
245
- normalized.headers["Link"].should be == "something something"
246
- end
247
-
248
- it 'generates link headers from link entries'
249
- it 'does not discard existing link entires'
250
- it 'does not discard existing link headers'
251
-
252
- it 'identifies _url suffix as link' do
253
- normalize 'foo_url' => 'http://lmgtfy.com/?q=foo'
254
- normalized.should_not include('foo_url')
255
- normalized.should include("_links")
256
- normalized["_links"].should include("foo")
257
- normalized["_links"]["foo"].should be_a(Hash)
258
- normalized["_links"]["foo"]["href"].should be == 'http://lmgtfy.com/?q=foo'
259
- end
260
-
261
- it 'identifies blog as link' do
262
- normalize 'blog' => 'http://rkh.im'
263
- normalized.should_not include('blog')
264
- normalized.should include("_links")
265
- normalized["_links"].should include("blog")
266
- normalized["_links"]["blog"].should be_a(Hash)
267
- normalized["_links"]["blog"]["href"].should be == 'http://rkh.im'
268
- end
269
-
270
- it 'detects avatar links from gravatar_url' do
271
- normalize 'gravatar_url' => 'http://gravatar.com/avatar/93c02710978db9979064630900741691?size=50'
272
- normalized.should_not include('gravatar_url')
273
- normalized.should include("_links")
274
- normalized["_links"].should include("avatar")
275
- normalized["_links"]["avatar"].should be_a(Hash)
276
- normalized["_links"]["avatar"]["href"].should be == 'http://gravatar.com/avatar/93c02710978db9979064630900741691?size=50'
277
- end
278
-
279
- it 'detects html urls in url field' do
280
- normalize 'url' => 'http://github.com/foo'
281
- normalized.should_not include('url')
282
- normalized.should include('_links')
283
- normalized['_links'].should include('html')
284
- normalized['_links']['html']['href'].should be == 'http://github.com/foo'
285
- end
286
-
287
- it 'detects self urls in url field' do
288
- normalize 'url' => 'https://api.github.com/foo'
289
- normalized.should_not include('url')
290
- normalized.should include('_links')
291
- normalized['_links'].should include('self')
292
- normalized['_links'].should_not include('html')
293
- normalized['_links']['self']['href'].should be == 'https://api.github.com/foo'
294
- end
295
-
296
- it 'passes through true' do
297
- normalize 'foo' => true
298
- normalized['foo'].should be == true
299
- end
300
-
301
- it 'properly detects html links when api is served from same host' do
302
- subject.backend.setup("http://localhost/api/v3", {})
303
- normalize 'url' => 'http://localhost/foo'
304
- normalized.should_not include('url')
305
- normalized.should include('_links')
306
- normalized['_links'].should include('html')
307
- normalized['_links']['html']['href'].should be == 'http://localhost/foo'
308
- end
309
-
310
- it 'properly detects self links when api is served from same host' do
311
- subject.backend.setup("http://localhost/api/v3", {})
312
- normalize 'url' => 'http://localhost/api/v3/foo'
313
- normalized.should_not include('url')
314
- normalized.should include('_links')
315
- normalized['_links'].should include('self')
316
- normalized['_links']['self']['href'].should be == 'http://localhost/api/v3/foo'
317
- end
318
- end
319
- end