username !== '' && $this->token !== '' && $this->baseUrl !== ''; } public function ping(): void { $baseUrl = rtrim($this->baseUrl, '/'); $this->client->request('GET', "$baseUrl/api/v1/user", [ 'headers' => ['Authorization' => "token {$this->token}"], ])->getContent(); } /** * @return array date (Y-m-d) => contribution count */ public function fetch(): array { $baseUrl = rtrim($this->baseUrl, '/'); $this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]); $response = $this->client->request('GET', "$baseUrl/api/v1/users/{$this->username}/heatmap", [ 'headers' => ['Authorization' => "token {$this->token}"], ]); $data = $response->toArray(); $cutoff = (new \DateTimeImmutable('-365 days'))->getTimestamp(); $result = []; foreach ($data as $entry) { if ($entry['timestamp'] < $cutoff) { continue; } $date = date('Y-m-d', $entry['timestamp']); $result[$date] = ($result[$date] ?? 0) + (int) $entry['contributions']; } $this->logger->info('GiteaProvider: fetched contributions', [ 'user' => $this->username, 'days' => count($result), 'total' => array_sum($result), ]); return $result; } }