Permalink
Browse files

Adding work around for github api paging bug

  • Loading branch information...
1 parent 399cc69 commit d50a8adc9b1a12ef80b99f2f8e7269194603a005 @aubreyrhodes committed Feb 17, 2012
Showing with 4 additions and 5 deletions.
  1. +2 −2 lib/octokit/request.rb
  2. +2 −3 spec/octokit/client_spec.rb
View
@@ -41,8 +41,8 @@ def request(method, path, options, version, authenticate, raw, force_urlencoded)
if raw
response
- elsif auto_traversal && ( next_url = links(response)["next"] ) && links(response)["next"] != path
- response.body + request(method, next_url, options, version, authenticate, raw, force_urlencoded)
+ elsif auto_traversal && ( next_url = links(response)["next"])
+ response.body + request(method, next_url.gsub(/[&?]sha=.*(&|\z)/, ''), options, version, authenticate, raw, force_urlencoded)
else
response.body
end
@@ -13,16 +13,15 @@
it "should traverse a paginated response if auto_traversal is on" do
stub_get("https://api.github.com/foo/bar").
to_return(:status => 200, :body => %q{["stuff"]}, :headers =>
- { 'Link' => %q{<https://api.github.com/foo/bar?page=2>; rel="next", <https://api.github.com/foo/bar?page=3>; rel="last", <https://api.github.com/foo/bar?page=1>; rel="prev", <https://api.github.com/foo/bar?page=1>; rel="first"} })
-
+ { 'Link' => %q{<https://api.github.com/foo/bar?page=2>; rel="next", <https://api.github.com/foo/bar?page=3>; rel="last"} })
stub_get("https://api.github.com/foo/bar?page=2").
to_return(:status => 200, :body => %q{["even more stuff"]}, :headers =>
{ 'Link' => %q{<https://api.github.com/foo/bar?page=3>; rel="next", <https://api.github.com/foo/bar?page=3>; rel="last", <https://api.github.com/foo/bar?page=1>; rel="prev", <https://api.github.com/foo/bar?page=1>; rel="first"} })
stub_get("https://api.github.com/foo/bar?page=3").
to_return(:status => 200, :body => %q{["stuffapalooza"]}, :headers =>
- { 'Link' => %q{<https://api.github.com/foo/bar?page=2>; rel="prev", <https://api.github.com/foo/bar?page=1>; rel="first", <https://api.github.com/foo/bar?page=3>; rel="next", <https://api.github.com/foo/bar?page=3>; rel="last"} })
+ { 'Link' => %q{<https://api.github.com/foo/bar?page=2>; rel="prev", <https://api.github.com/foo/bar?page=1>; rel="first"} })
Octokit::Client.new(:auto_traversal => true).get("https://api.github.com/foo/bar", {}, 3).should == ['stuff', 'even more stuff', 'stuffapalooza']
end

0 comments on commit d50a8ad

Please sign in to comment.