Save to database #13

Merged
haylan merged 42 commits from save-to-database into main 2026-07-12 21:51:57 +00:00
Showing only changes of commit 9f3c54afd1 - Show all commits
+13 -6
View File
@@ -9,6 +9,7 @@ use IDCI\Bundle\GraphQLClientBundle\Client\GraphQLApiClientRegistryInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
/** /**
* Fetches the last 365 days of contributions from the GitHub GraphQL API. * Fetches the last 365 days of contributions from the GitHub GraphQL API.
@@ -46,10 +47,7 @@ final class GitHubProvider implements ProviderInterface
])->getContent(); ])->getContent();
} }
/** public function startFetch(): ResponseInterface
* @return array<string, int> date (Y-m-d) => contribution count
*/
public function fetch(): array
{ {
$this->logger->debug('GitHubProvider: fetching contributions', ['user' => $this->username]); $this->logger->debug('GitHubProvider: fetching contributions', ['user' => $this->username]);
@@ -75,15 +73,24 @@ final class GitHubProvider implements ProviderInterface
// GitHub's GraphQL API requires application/json — the bundle's built-in // GitHub's GraphQL API requires application/json — the bundle's built-in
// transport sends form_params, so we use Symfony HttpClient here instead. // transport sends form_params, so we use Symfony HttpClient here instead.
$response = $this->client->request('POST', self::GRAPHQL_URL, [ // request() doesn't block; the response is read in resolveFetch() so
// multiple providers' requests can be in flight at once.
return $this->client->request('POST', self::GRAPHQL_URL, [
'headers' => [ 'headers' => [
'Authorization' => "Bearer {$this->token}", 'Authorization' => "Bearer {$this->token}",
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
], ],
'json' => ['query' => $query], 'json' => ['query' => $query],
]); ]);
}
$data = $response->toArray(); /**
* @return array<string, int> date (Y-m-d) => contribution count
*/
public function resolveFetch(mixed $handle): array
{
/** @var ResponseInterface $handle */
$data = $handle->toArray();
if (isset($data['errors'])) { if (isset($data['errors'])) {
throw new ServiceUnavailableHttpException(null, 'GitHub GraphQL error: ' . json_encode($data['errors'])); throw new ServiceUnavailableHttpException(null, 'GitHub GraphQL error: ' . json_encode($data['errors']));