date (Y-m-d) => contribution count */ public function fetch(string $username, string $token): array { $from = (new \DateTimeImmutable('-365 days'))->format('Y-m-d\T00:00:00\Z'); $to = (new \DateTimeImmutable())->format('Y-m-d\T23:59:59\Z'); $response = $this->client->request('POST', self::GRAPHQL_URL, [ 'headers' => [ 'Authorization' => "Bearer $token", 'Content-Type' => 'application/json', ], 'json' => [ 'query' => self::QUERY, 'variables' => ['username' => $username, 'from' => $from, 'to' => $to], ], ]); $data = $response->toArray(); if (isset($data['errors'])) { throw new \RuntimeException('GitHub GraphQL error: ' . json_encode($data['errors'])); } $result = []; $weeks = $data['data']['user']['contributionsCollection']['contributionCalendar']['weeks'] ?? []; foreach ($weeks as $week) { foreach ($week['contributionDays'] as $day) { if ($day['contributionCount'] > 0) { $result[$day['date']] = $day['contributionCount']; } } } return $result; } }