Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function buildContributionGraphQuery(string $user, int $year): string
}
}
}
repositoryContributions(first: 100) {
nodes {
occurredAt
}
}
}
}
}";
Expand Down Expand Up @@ -275,7 +280,15 @@ function getContributionDates(array $contributionGraphs): array
}
}
}
$repositoryContributions = $graph->data->user->contributionsCollection->repositoryContributions->nodes ?? [];
foreach ($repositoryContributions as $repositoryContribution) {
$date = substr($repositoryContribution->occurredAt, 0, 10);
if ($date <= $today || $date == $tomorrow) {
$contributions[$date] = max($contributions[$date] ?? 0, 1);
}
}
}
ksort($contributions);
return $contributions;
}

Expand Down
66 changes: 66 additions & 0 deletions tests/StatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,72 @@ public function testFutureCommits(): void
$this->assertEquals($expected, $stats);
}

/**
* Test repository creation keeps daily streak active
*/
public function testRepositoryCreationContribution(): void
{
$contributionGraphs = [
(object) [
"data" => (object) [
"user" => (object) [
"contributionsCollection" => (object) [
"contributionCalendar" => (object) [
"weeks" => (object) [
(object) [
"contributionDays" => (object) [
(object) [
"contributionCount" => 2,
"date" => "2026-07-08",
],
(object) [
"contributionCount" => 0,
"date" => "2026-07-09",
],
(object) [
"contributionCount" => 3,
"date" => "2026-07-10",
],
],
],
],
],
"repositoryContributions" => (object) [
"nodes" => [
(object) [
"occurredAt" => "2026-07-09T12:00:00Z",
],
],
],
],
],
],
],
];

$contributions = getContributionDates($contributionGraphs);
$stats = getContributionStats($contributions);

$expected = [
"mode" => "daily",
"totalContributions" => 6,
"firstContribution" => "2026-07-08",
"longestStreak" => [
"start" => "2026-07-08",
"end" => "2026-07-10",
"length" => 3,
],
"currentStreak" => [
"start" => "2026-07-08",
"end" => "2026-07-10",
"length" => 3,
],
"excludedDays" => [],
];
$this->assertEquals(["2026-07-08" => 2, "2026-07-09" => 1, "2026-07-10" => 3], $contributions);
$this->assertEquals($expected, $stats);
}

/**
* Test weekly stats
*/
Expand Down
Loading