Fix issue counts always returning zero - #830
Open
ruohai0925 wants to merge 1 commit into
Open
Conversation
GitHub migrated the repo issues list endpoint to cursor-based pagination. Its Link header now carries only a rel="next" entry with an opaque cursor and no rel="last", so the per_page=1 trick used by FetchIssueCount reads LastPage as 0 and returns 0 for every repository. This zeroes updated_issues_count and closed_issues_count, and because issue_comment_frequency divides the comment count by the updated count, that signal is zeroed too. Fall back to paging through the results and counting them when the total cannot be read off the Link header. The rel="last" fast path is kept for when the API still provides it, and the MaxIssuesLimit cap is preserved so large repositories do not page indefinitely. The comments and contributors endpoints still return rel="last", so FetchIssueCommentCount and FetchTotalContributors are unchanged. Adds httptest-backed tests for FetchIssueCount, which had no coverage. Signed-off-by: ruohai0925 <ruohai372@gmail.com>
ruohai0925
force-pushed
the
fix-issue-count-cursor-pagination
branch
from
August 2, 2026 06:23
76d4d77 to
7c6b1b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #816.
The three legacy issue signals —
updated_issues_count,closed_issues_countand
issue_comment_frequency— currently report0for every repository.GitHub has migrated
/repos/{owner}/{repo}/issuesto cursor-based pagination.Its
Linkheader now carries only arel="next"entry with an opaque cursor,and no
rel="last":FetchIssueCountrequestsper_page=1and reads the total offresp.LastPage,which is now always
0, so it returns0. Sinceissue_comment_frequencydivides the comment count by the updated-issues count, and
IssuesSource.Getshort-circuits when that count is zero, the comment signal is zeroed as well.
Change
When the total cannot be read off the
Linkheader, page through the resultsand count them instead. The
rel="last"fast path is kept for when the APIstill provides it, so nothing changes for endpoints or deployments that still
return it, and the
MaxIssuesLimitcap is preserved so large repositories stoppaging at 5000 rather than walking an unbounded number of pages.
FetchIssueCommentCountandFetchTotalContributorsare deliberately leftunchanged — I checked both endpoints and they still return
rel="last", so theper_page=1trick remains valid there:Testing
make testandmake lintboth pass.internal/collector/github/legacyhad no test coverage at all, so this addsissues_test.gowithhttptest-backed cases for the cursor-paginationfallback, the
rel="last"fast path, the single-result and empty cases, the5xx →
MaxIssuesLimitfallback, the paging cap (and its request count), andthe
sincelookback window.Verified end to end against two repositories, with
-depsdev-disable:BLAST-WarpX/warpxupdated_issues_countclosed_issues_countissue_comment_frequencydefault_scoreruohai0925/IAMReXupdated_issues_countclosed_issues_countissue_comment_frequencydefault_scoreThe counts match what the GitHub search API reports for the same 90-day window
(e.g. 690 issues + PRs updated for WarpX).
Relationship to #829
#829 fixes the same bug by switching to the search API, which is a cleaner and
cheaper approach — one request instead of up to 50. This PR takes the paging
route, which keeps the existing endpoint and its exact semantics and avoids the
search API's separate rate limit, and additionally adds test coverage for the
package.
I have no attachment to my version: if maintainers prefer #829, I'm happy to
close this and port the tests over to that PR instead. Opening this mainly
because #829 has been sitting unreviewed since July and the bug silently
distorts every published score.