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
+20 -2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Service;
use Psr\Log\LoggerInterface;
@@ -13,8 +15,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
*
* Required token scopes: read:user
*/
class GiteaProvider implements ProviderInterface
final class GiteaProvider implements ProviderInterface
{
use ProbeTrait;
public function __construct(
private readonly HttpClientInterface $client,
private readonly string $username,
@@ -23,17 +27,31 @@ class GiteaProvider implements ProviderInterface
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, '/');
$baseUrl = rtrim($this->baseUrl, '/');
$this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]);