Initialize git-contribution-graph project with Docker setup, environment configuration, and core functionality for merging contributions from GitHub, GitLab, and Gitea into an SVG heatmap.

This commit is contained in:
2026-05-28 19:35:44 +02:00
commit 342490035b
17 changed files with 881 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Service;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* Fetches contribution data from the Gitea heatmap endpoint.
*
* Endpoint: GET /api/v1/users/{username}/heatmap
* Returns: [{"timestamp": 1234567890, "contributions": 3}, ...]
*
* Required token scopes: read:user
*/
class GiteaProvider
{
public function __construct(private readonly HttpClientInterface $client) {}
/**
* @return array<string, int> date (Y-m-d) => contribution count
*/
public function fetch(string $username, string $token, string $baseUrl): array
{
$baseUrl = rtrim($baseUrl, '/');
$response = $this->client->request('GET', "$baseUrl/api/v1/users/$username/heatmap", [
'headers' => ['Authorization' => "token $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'];
}
return $result;
}
}