refactor: reorganise Service/ into Provider/ and Renderer/ sub-namespaces

Move all provider-related classes, enums, interface and trait into
App\Service\Provider; move SvgRenderer into App\Service\Renderer.
ContributionAggregator stays at the Service root as the orchestrator.
Test namespaces and use statements updated to match.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 00:10:09 +02:00
co-authored by Claude-Bot
parent fad176419c
commit 2f3268c0b7
20 changed files with 37 additions and 36 deletions
+82
View File
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace App\Service\Provider;
use Psr\Log\LoggerInterface;
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
*/
final class GiteaProvider implements ProviderInterface
{
use ProbeTrait;
public function __construct(
private readonly HttpClientInterface $client,
private readonly string $username,
private readonly string $token,
private readonly string $baseUrl,
private readonly LoggerInterface $logger,
) {}
public function getName(): string
{
return 'gitea';
}
public function isConfigured(): bool
{
return $this->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<string, int> 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;
}
}