diff --git a/changelog.md b/changelog.md index 23f76c0..b612b64 100644 --- a/changelog.md +++ b/changelog.md @@ -2,7 +2,10 @@ ## Unreleased -- Minimum supported Ruby version updated to 3.2 +## 2.0.0 + +- Changed: Minimum supported Ruby version updated to 3.2. +- Fix: Responses that don't have a `last_url` in the link no longer error. ## 1.0.1 diff --git a/lib/git_hub_bub/response.rb b/lib/git_hub_bub/response.rb index e27de6d..1a20af6 100644 --- a/lib/git_hub_bub/response.rb +++ b/lib/git_hub_bub/response.rb @@ -74,6 +74,7 @@ def first_url def last_page? return true if next_url.nil? + return false if last_url.nil? # A next page exists, but no "last" page, keep going. last_page_number = page_number_from_url(last_url) next_page_number = page_number_from_url(next_url) next_page_number > last_page_number diff --git a/lib/git_hub_bub/version.rb b/lib/git_hub_bub/version.rb index b374a18..f911b84 100644 --- a/lib/git_hub_bub/version.rb +++ b/lib/git_hub_bub/version.rb @@ -1,3 +1,3 @@ module GitHubBub - VERSION = "1.0.1" + VERSION = "2.0.0" end diff --git a/test/git_hub_bub/response_test.rb b/test/git_hub_bub/response_test.rb index 4e50b7d..e3e6632 100644 --- a/test/git_hub_bub/response_test.rb +++ b/test/git_hub_bub/response_test.rb @@ -63,6 +63,25 @@ def test_rate_limit_reset_time_left end end + def test_last_page_with_next_but_no_last_url + # This reproduces a real response from the GitHub API where the Link header + # only contains rel="next" but no rel="last" + data = { + body: "[{\"url\":\"https://api.github.com/repos/puma/puma/issues/3643\"}]", + headers: { + "Link" => "; rel=\"next\"" + }, + status: 200 + } + response = GitHubBub::Response.new(data) + + assert_equal "https://api.github.com/repositories/2441517/issues?direction=desc&page=2&sort=comments&state=open&after=Y3Vyc29yOnYyOpIIzpU4Fek%3D&per_page=30", + response.next_url + assert_nil response.last_url + + refute response.last_page? + end + def test_rate_limit_sleep epoch_time = 1504196685