feat(provider): implement ping and probe on GitHub, GitLab, and Gitea

Add getName() and ping() to each provider and wire ProbeTrait. Make
all classes final, add strict_types declarations, and replace generic
RuntimeException with typed HTTP exceptions so probe() can classify
auth failures and unreachable endpoints correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-30 14:13:14 +02:00
co-authored by Claude-Bot
parent 71bfb38028
commit d3b9463c57
3 changed files with 60 additions and 7 deletions
+21 -3
View File
@@ -1,8 +1,11 @@
<?php
declare(strict_types=1);
namespace App\Service;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
@@ -11,8 +14,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
* Required token scopes: read_user, read_api
* Works with both gitlab.com and self-hosted instances.
*/
class GitLabProvider implements ProviderInterface
final class GitLabProvider implements ProviderInterface
{
use ProbeTrait;
public function __construct(
private readonly HttpClientInterface $client,
private readonly string $username,
@@ -21,11 +26,25 @@ class GitLabProvider implements ProviderInterface
private readonly string $baseUrl = '',
) {}
public function getName(): string
{
return 'gitlab';
}
public function isConfigured(): bool
{
return $this->username !== '' && $this->token !== '';
}
public function ping(): void
{
$baseUrl = rtrim($this->baseUrl !== '' ? $this->baseUrl : 'https://gitlab.com', '/');
$this->client->request('GET', "$baseUrl/api/v4/user", [
'headers' => ['PRIVATE-TOKEN' => $this->token],
])->getContent();
}
/**
* @return array<string, int> date (Y-m-d) => event count
*/
@@ -35,7 +54,6 @@ class GitLabProvider implements ProviderInterface
$this->logger->debug('GitLabProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]);
// Resolve numeric user ID from username
$userResponse = $this->client->request('GET', "$baseUrl/api/v4/users", [
'headers' => ['PRIVATE-TOKEN' => $this->token],
'query' => ['username' => $this->username],
@@ -43,7 +61,7 @@ class GitLabProvider implements ProviderInterface
$users = $userResponse->toArray();
if (empty($users)) {
throw new \RuntimeException("GitLab: user '{$this->username}' not found on $baseUrl");
throw new NotFoundHttpException("GitLab: user '{$this->username}' not found on $baseUrl");
}
$userId = $users[0]['id'];