feat: implement multi-provider architecture for contribution fetching and add Docker support
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user