Save to database #13
@@ -25,7 +25,9 @@ final class GitLabProvider implements ProviderInterface
|
||||
private readonly string $token,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly string $baseUrl = '',
|
||||
) {}
|
||||
) {
|
||||
$this->baseUrl = rtrim($this->baseUrl !== '' ? $this->baseUrl : 'https://gitlab.com', '/');
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
@@ -39,9 +41,8 @@ final class GitLabProvider implements ProviderInterface
|
||||
|
||||
public function ping(): void
|
||||
{
|
||||
$baseUrl = rtrim($this->baseUrl !== '' ? $this->baseUrl : 'https://gitlab.com', '/');
|
||||
|
||||
$this->client->request('GET', "$baseUrl/api/v4/user", [
|
||||
$this->client->request('GET', "$this->baseUrl/api/v4/user", [
|
||||
'headers' => ['PRIVATE-TOKEN' => $this->token],
|
||||
])->getContent();
|
||||
}
|
||||
@@ -56,23 +57,22 @@ final class GitLabProvider implements ProviderInterface
|
||||
*/
|
||||
public function startFetch(): array
|
||||
{
|
||||
$baseUrl = rtrim($this->baseUrl !== '' ? $this->baseUrl : 'https://gitlab.com', '/');
|
||||
|
||||
$this->logger->debug('GitLabProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]);
|
||||
$this->logger->debug('GitLabProvider: fetching contributions', ['user' => $this->username, 'url' => $this->baseUrl]);
|
||||
|
||||
$userResponse = $this->client->request('GET', "$baseUrl/api/v4/users", [
|
||||
$userResponse = $this->client->request('GET', "$this->baseUrl/api/v4/users", [
|
||||
'headers' => ['PRIVATE-TOKEN' => $this->token],
|
||||
'query' => ['username' => $this->username],
|
||||
]);
|
||||
|
||||
$users = $userResponse->toArray();
|
||||
if (empty($users)) {
|
||||
throw new NotFoundHttpException("GitLab: user '{$this->username}' not found on $baseUrl");
|
||||
throw new NotFoundHttpException("GitLab: user '{$this->username}' not found on $this->baseUrl");
|
||||
}
|
||||
$userId = $users[0]['id'];
|
||||
$after = (new \DateTimeImmutable('-365 days'))->format('Y-m-d');
|
||||
|
||||
$response = $this->client->request('GET', "$baseUrl/api/v4/users/$userId/events", [
|
||||
$response = $this->client->request('GET', "$this->baseUrl/api/v4/users/$userId/events", [
|
||||
'headers' => ['PRIVATE-TOKEN' => $this->token],
|
||||
'query' => [
|
||||
'after' => $after,
|
||||
@@ -81,7 +81,7 @@ final class GitLabProvider implements ProviderInterface
|
||||
],
|
||||
]);
|
||||
|
||||
return ['baseUrl' => $baseUrl, 'userId' => $userId, 'after' => $after, 'page' => 1, 'response' => $response];
|
||||
return ['baseUrl' => $this->baseUrl, 'userId' => $userId, 'after' => $after, 'page' => 1, 'response' => $response];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,9 @@ final class GiteaProvider implements ProviderInterface
|
||||
private readonly string $token,
|
||||
private readonly string $baseUrl,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {}
|
||||
) {
|
||||
$this->baseUrl = rtrim($this->baseUrl, '/');
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
@@ -40,20 +42,20 @@ final class GiteaProvider implements ProviderInterface
|
||||
|
||||
public function ping(): void
|
||||
{
|
||||
$baseUrl = rtrim($this->baseUrl, '/');
|
||||
|
||||
$this->client->request('GET', "$baseUrl/api/v1/user", [
|
||||
|
||||
$this->client->request('GET', "$this->baseUrl/api/v1/user", [
|
||||
'headers' => ['Authorization' => "token {$this->token}"],
|
||||
])->getContent();
|
||||
}
|
||||
|
||||
public function startFetch(): ResponseInterface
|
||||
{
|
||||
$baseUrl = rtrim($this->baseUrl, '/');
|
||||
|
||||
$this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]);
|
||||
|
||||
return $this->client->request('GET', "$baseUrl/api/v1/users/{$this->username}/heatmap", [
|
||||
$this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $this->baseUrl]);
|
||||
|
||||
return $this->client->request('GET', "$this->baseUrl/api/v1/users/{$this->username}/heatmap", [
|
||||
'headers' => ['Authorization' => "token {$this->token}"],
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user