feat: implement multi-provider architecture for contribution fetching and add Docker support
This commit is contained in:
@@ -11,19 +11,26 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
*
|
||||
* Required token scopes: read:user
|
||||
*/
|
||||
class GitHubProvider
|
||||
class GitHubProvider implements ProviderInterface
|
||||
{
|
||||
private const GRAPHQL_URL = 'https://api.github.com/graphql';
|
||||
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $client,
|
||||
private readonly GraphQLApiClientRegistryInterface $registry,
|
||||
private readonly string $username,
|
||||
private readonly string $token,
|
||||
) {}
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return $this->username !== '' && $this->token !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int> date (Y-m-d) => contribution count
|
||||
*/
|
||||
public function fetch(string $username, string $token): array
|
||||
public function fetch(): array
|
||||
{
|
||||
$from = (new \DateTimeImmutable('-365 days'))->format('Y-m-d\T00:00:00\Z');
|
||||
$to = (new \DateTimeImmutable())->format('Y-m-d\T23:59:59\Z');
|
||||
@@ -32,7 +39,7 @@ class GitHubProvider
|
||||
$graphqlClient = $this->registry->get('github');
|
||||
|
||||
$query = $graphqlClient->buildQuery(
|
||||
['user' => ['login' => $username]],
|
||||
['user' => ['login' => $this->username]],
|
||||
[
|
||||
'contributionsCollection' => [
|
||||
'_parameters' => ['from' => $from, 'to' => $to],
|
||||
@@ -49,7 +56,7 @@ class GitHubProvider
|
||||
// transport sends form_params, so we use Symfony HttpClient here instead.
|
||||
$response = $this->client->request('POST', self::GRAPHQL_URL, [
|
||||
'headers' => [
|
||||
'Authorization' => "Bearer $token",
|
||||
'Authorization' => "Bearer {$this->token}",
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => ['query' => $query],
|
||||
|
||||
Reference in New Issue
Block a user