feat: implement multi-provider architecture for contribution fetching and add Docker support

This commit is contained in:
2026-05-29 11:51:05 +02:00
parent 381b8f4489
commit 56035096c6
13 changed files with 272 additions and 89 deletions
+18 -8
View File
@@ -10,26 +10,36 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
* Required token scopes: read_user, read_api
* Works with both gitlab.com and self-hosted instances.
*/
class GitLabProvider
class GitLabProvider implements ProviderInterface
{
public function __construct(private readonly HttpClientInterface $client) {}
public function __construct(
private readonly HttpClientInterface $client,
private readonly string $username,
private readonly string $token,
private readonly string $baseUrl = '',
) {}
public function isConfigured(): bool
{
return $this->username !== '' && $this->token !== '';
}
/**
* @return array<string, int> date (Y-m-d) => event count
*/
public function fetch(string $username, string $token, string $baseUrl = 'https://gitlab.com'): array
public function fetch(): array
{
$baseUrl = rtrim($baseUrl, '/');
$baseUrl = rtrim($this->baseUrl !== '' ? $this->baseUrl : 'https://gitlab.com', '/');
// Resolve numeric user ID from username
$userResponse = $this->client->request('GET', "$baseUrl/api/v4/users", [
'headers' => ['PRIVATE-TOKEN' => $token],
'query' => ['username' => $username],
'headers' => ['PRIVATE-TOKEN' => $this->token],
'query' => ['username' => $this->username],
]);
$users = $userResponse->toArray();
if (empty($users)) {
throw new \RuntimeException("GitLab: user '$username' not found on $baseUrl");
throw new \RuntimeException("GitLab: user '{$this->username}' not found on $baseUrl");
}
$userId = $users[0]['id'];
@@ -39,7 +49,7 @@ class GitLabProvider
do {
$response = $this->client->request('GET', "$baseUrl/api/v4/users/$userId/events", [
'headers' => ['PRIVATE-TOKEN' => $token],
'headers' => ['PRIVATE-TOKEN' => $this->token],
'query' => [
'after' => $after,
'per_page' => 100,