Skip to content

Fix failure when last_url not present#7

Merged
schneems merged 3 commits intomainfrom
schneems/fix-response-no-last-url
Feb 2, 2026
Merged

Fix failure when last_url not present#7
schneems merged 3 commits intomainfrom
schneems/fix-response-no-last-url

Conversation

@schneems
Copy link
Member

@schneems schneems commented Feb 2, 2026

The last_url is not always available. From https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api?apiVersion=2022-11-28

In some cases, only a subset of these links are available. For example, the link to the previous page won't be included if you are on the first page of results, and the link to the last page won't be included if it can't be calculated.

This causes failures reproduced in this test:

$ be rake test
...
Cause0: NoMethodError: undefined method 'to_str' for nil
/Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/4.0.0/uri/rfc3986_parser.rb:79:in 'URI::RFC3986_Parser#split'
/Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/4.0.0/uri/rfc3986_parser.rb:135:in 'URI::RFC3986_Parser#parse'
/Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/4.0.0/uri/common.rb:247:in 'URI.parse'
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:88:in 'GitHubBub::Response#page_number_from_url'
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:77:in 'GitHubBub::Response#last_page?'
/Users/rschneeman/Documents/projects/git_hub_bub/test/git_hub_bub/response_test.rb:82:in 'ResponseTest#test_last_page_with_next_but_no_last_url'
     79:     assert_nil response.last_url
     80:
     81:     # This will fail because last_page? tries to parse last_url when it's nil
  => 82:     refute response.last_page?
     83:   end
     84:
     85:   def test_rate_limit_sleep
============================================================================================================================================================================
====
E
============================================================================================================================================================================
====
Error: test_pagination(ResponseTest): NoMethodError: undefined method 'parse' for class CGI
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:89:in 'GitHubBub::Response#page_number_from_url'
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:77:in 'GitHubBub::Response#last_page?'
/Users/rschneeman/Documents/projects/git_hub_bub/test/git_hub_bub/response_test.rb:15:in 'ResponseTest#test_pagination'
     12:     assert_equal nil, response.prev_url
     13:     assert_equal nil, response.first_url
     14:
  => 15:     refute response.last_page?
     16:     assert response.first_page?
     17:
     18:     response = GitHubBub::Response.new(rails_issues_data(:second))
============================================================================================================================================================================
====
Finished in 0.03191 seconds.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----
15 tests, 34 assertions, 0 failures, 2 errors, 0 pendings, 0 omissions, 0 notifications
86.6667% passed
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----
470.07 tests/s, 1065.50 assertions/s
rake aborted!
Command failed with status (1): [ruby -w -I"lib:lib:test" /Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb "test/git_h
ub_bub/request_test.rb" "test/git_hub_bub/response_test.rb" "test/git_hub_bub/valid_token_test.rb" ]
/Users/rschneeman/.rubies/ruby-4.0.1/bin/bundle:25:in '<main>'
Tasks: TOP => test

A failing test was added and then fixed.

From https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api?apiVersion=2022-11-28


> In some cases, only a subset of these links are available. For example, the link to the previous page won't be included if you are on the first page of results, and the link to the last page won't be included if it can't be calculated.

```
$ be rake test
...
Cause0: NoMethodError: undefined method 'to_str' for nil
/Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/4.0.0/uri/rfc3986_parser.rb:79:in 'URI::RFC3986_Parser#split'
/Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/4.0.0/uri/rfc3986_parser.rb:135:in 'URI::RFC3986_Parser#parse'
/Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/4.0.0/uri/common.rb:247:in 'URI.parse'
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:88:in 'GitHubBub::Response#page_number_from_url'
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:77:in 'GitHubBub::Response#last_page?'
/Users/rschneeman/Documents/projects/git_hub_bub/test/git_hub_bub/response_test.rb:82:in 'ResponseTest#test_last_page_with_next_but_no_last_url'
     79:     assert_nil response.last_url
     80: 
     81:     # This will fail because last_page? tries to parse last_url when it's nil
  => 82:     refute response.last_page?
     83:   end
     84: 
     85:   def test_rate_limit_sleep
================================================================================================================================================================================
E
================================================================================================================================================================================
Error: test_pagination(ResponseTest): NoMethodError: undefined method 'parse' for class CGI
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:89:in 'GitHubBub::Response#page_number_from_url'
/Users/rschneeman/Documents/projects/git_hub_bub/lib/git_hub_bub/response.rb:77:in 'GitHubBub::Response#last_page?'
/Users/rschneeman/Documents/projects/git_hub_bub/test/git_hub_bub/response_test.rb:15:in 'ResponseTest#test_pagination'
     12:     assert_equal nil, response.prev_url
     13:     assert_equal nil, response.first_url
     14: 
  => 15:     refute response.last_page?
     16:     assert response.first_page?
     17: 
     18:     response = GitHubBub::Response.new(rails_issues_data(:second))
================================================================================================================================================================================
Finished in 0.03191 seconds.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
15 tests, 34 assertions, 0 failures, 2 errors, 0 pendings, 0 omissions, 0 notifications
86.6667% passed
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
470.07 tests/s, 1065.50 assertions/s
rake aborted!
Command failed with status (1): [ruby -w -I"lib:lib:test" /Users/rschneeman/.rubies/ruby-4.0.1/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb "test/git_hub_bub/request_test.rb" "test/git_hub_bub/response_test.rb" "test/git_hub_bub/valid_token_test.rb" ]
/Users/rschneeman/.rubies/ruby-4.0.1/bin/bundle:25:in '<main>'
Tasks: TOP => test
```
@schneems schneems merged commit 0ddaf88 into main Feb 2, 2026
5 checks passed
schneems added a commit to codetriage/CodeTriage that referenced this pull request Feb 2, 2026
Issue pulling was failing due to zombocom/git_hub_bub#7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant