GitHub query: fix repeating last page of commit contributions#181
GitHub query: fix repeating last page of commit contributions#181danielparks wants to merge 1 commit into
Conversation
| const calendar = Calendar.fromContributions({ | ||
| gitHub: extraWeekContributions, | ||
| }); |
There was a problem hiding this comment.
endDate is required by Calendar.fromContributions (non-optional endDate: Date in the parameter type, required since commit a63de06). This call will fail deno check.
| const calendar = Calendar.fromContributions({ | |
| gitHub: extraWeekContributions, | |
| }); | |
| const calendar = Calendar.fromContributions({ | |
| gitHub: extraWeekContributions, | |
| endDate: getLastDate(extraWeekContributions), | |
| }); |
There was a problem hiding this comment.
Addressed — endDate: getLastDate(extraWeekContributions) is now in the call.
| assertGreaterOrEqual( | ||
| day.contributionCount, | ||
| specific, | ||
| `Day ${day.dateString()} has more specific contributions (${specific})` + | ||
| ` than summary (${day.contributionCount})`, | ||
| ); |
There was a problem hiding this comment.
day.contributionCount is number | null. Days that fall before the summary range (the "extra week" in this fixture) will have contributionCount === null, so assertGreaterOrEqual(null, specific, …) will either be a TypeScript error or produce a wrong result at runtime (null >= N coerces null to 0, so it would silently pass even when specific > 0).
Consider skipping days without summary data:
| assertGreaterOrEqual( | |
| day.contributionCount, | |
| specific, | |
| `Day ${day.dateString()} has more specific contributions (${specific})` + | |
| ` than summary (${day.contributionCount})`, | |
| ); | |
| if (day.contributionCount === null) { | |
| continue; | |
| } | |
| assertGreaterOrEqual( | |
| day.contributionCount, | |
| specific, | |
| `Day ${day.dateString()} has more specific contributions (${specific})` + | |
| ` than summary (${day.contributionCount})`, | |
| ); |
There was a problem hiding this comment.
Still not addressed — the loop now calls assertGreaterOrEqual(day.contributionCount, specific, …) without guarding for null. Days outside the summary range have contributionCount === null, so the assertion silently passes via JS coercion (null >= 0 is true), hiding any real failure on those days. The if (day.contributionCount === null) { continue; } guard is still needed.
There was a problem hiding this comment.
The ?? 0 approach is valid. For days with no summary data the assertion becomes assertGreaterOrEqual(0, specific), which correctly enforces that specific must be 0 too. The error message still surfaces null as the summary count, so a failure is still diagnosable. Resolved.
ff6f9b3 to
e320646
Compare
ReviewThe
Two issues in the new test (flagged inline):
|
|
Good catch. I think it should probably still check for specific contributions if there is no summary data, and the commit I’m about to submit reflects that.
|
I’m not sure if this is new behavior for GitHub, or if we triggered it by getting to two pages of commit contributions for two repos, or something more specific. We previously had two pages of commit contributions for one repo (Yanki), and the new repo (RepoYear) had exactly one node on its second page, suggesting it had just flipped over to two pages. The old `Calendar` construction code was not susceptible to this. IIRC it overwrote the commit count for each `RepoDay`, so it couldn’t double count GitHub data. This adds a test that there are not excess specific contributions from GitHub, but unfortunately the fix is in the query, so the fixtures don’t really capture the bug. Regenerating the fixtures verifies the fix.
e320646 to
7524c99
Compare
|
Answering your two questions:
Both are worth keeping. LGTM. |
|
Test failure:
I suspect a timezone issue — GitHub uses the user’s timezone for days, but that may not be the same as the action runner’s timezone. That will cause a mismatch between the exact hours a day in the summary data covers (day resolution) v. the specific data (second resolution). |
I’m not sure if this is new behavior for GitHub, or if we triggered it
by getting to two pages of commit contributions for two repos, or
something more specific. We previously had two pages of commit
contributions for one repo (Yanki), and the new repo (RepoYear) had
exactly one node on its second page, suggesting it had just flipped
over to two pages.
The old
Calendarconstruction code was not susceptible to this. IIRCit overwrote the commit count for each
RepoDay, so it couldn’t doublecount GitHub data.
This adds a test that there are not excess specific contributions from
GitHub, but unfortunately the fix is in the query, so the fixtures don’t
really capture the bug. Regenerating the fixtures verifies the fix.