From 5e27a5bc934238596fe4c55703157dfe748a70d4 Mon Sep 17 00:00:00 2001 From: Haylan Date: Wed, 8 Jul 2026 06:50:25 +0200 Subject: [PATCH] fix(provider): dedoupet base URL is properly formatted in GitLab and Gitea providers --- src/Service/Provider/GitLabProvider.php | 22 +++++++++++----------- src/Service/Provider/GiteaProvider.php | 14 ++++++++------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Service/Provider/GitLabProvider.php b/src/Service/Provider/GitLabProvider.php index 3ddf9fd..4dc1ade 100644 --- a/src/Service/Provider/GitLabProvider.php +++ b/src/Service/Provider/GitLabProvider.php @@ -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' => $this->baseUrl]); - $this->logger->debug('GitLabProvider: fetching contributions', ['user' => $this->username, 'url' => $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]; } /** diff --git a/src/Service/Provider/GiteaProvider.php b/src/Service/Provider/GiteaProvider.php index 050b319..5183c25 100644 --- a/src/Service/Provider/GiteaProvider.php +++ b/src/Service/Provider/GiteaProvider.php @@ -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]); + $this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $this->baseUrl]); - return $this->client->request('GET', "$baseUrl/api/v1/users/{$this->username}/heatmap", [ + return $this->client->request('GET', "$this->baseUrl/api/v1/users/{$this->username}/heatmap", [ 'headers' => ['Authorization' => "token {$this->token}"], ]); }