diff --git a/app/app/src/Endpoint/Http/Controller/SettingsAction.php b/app/app/src/Endpoint/Http/Controller/SettingsAction.php index 0db393e..ee394b8 100644 --- a/app/app/src/Endpoint/Http/Controller/SettingsAction.php +++ b/app/app/src/Endpoint/Http/Controller/SettingsAction.php @@ -18,15 +18,15 @@ public function __invoke(ClientInterface $client): ResourceInterface 'github' => [ 'server' => [ 'stars' => $client->getStars('buggregator/server'), - 'last_version' => $client->getLastVersion('buggregator/server'), + 'latest_release' => $client->getLatestRelease('buggregator/server'), ], 'trap' => [ 'stars' => $client->getStars('buggregator/trap'), - 'last_version' => $client->getLastVersion('buggregator/trap'), + 'latest_release' => $client->getLatestRelease('buggregator/trap'), ], 'phpstorm-plugin' => [ 'stars' => $client->getStars('buggregator/phpstorm-plugin'), - 'last_version' => $client->getLastVersion('buggregator/phpstorm-plugin'), + 'latest_release' => $client->getLatestRelease('buggregator/phpstorm-plugin'), ], ], ]); diff --git a/app/app/src/Endpoint/Http/Controller/TeamAction.php b/app/app/src/Endpoint/Http/Controller/TeamAction.php index 3dd387e..88f7d52 100644 --- a/app/app/src/Endpoint/Http/Controller/TeamAction.php +++ b/app/app/src/Endpoint/Http/Controller/TeamAction.php @@ -33,6 +33,12 @@ public function __invoke(): ResourceInterface 'avatar' => 'https://avatars.githubusercontent.com/u/13301570?v=4', 'github' => 'https://github.com/Kreezag', ], + [ + 'name' => 'Artūrs Terehovičs', + 'role' => 'PHP developer', + 'avatar' => 'https://avatars.githubusercontent.com/u/94047334?v=4', + 'github' => 'https://github.com/lotyp', + ], ], TeamResource::class); - } +} } diff --git a/app/app/src/Github/CacheableClient.php b/app/app/src/Github/CacheableClient.php index a3f79c6..9d61b91 100644 --- a/app/app/src/Github/CacheableClient.php +++ b/app/app/src/Github/CacheableClient.php @@ -4,6 +4,7 @@ namespace App\Github; +use App\Github\Entity\Release; use Psr\SimpleCache\CacheInterface; final readonly class CacheableClient implements ClientInterface @@ -12,8 +13,7 @@ public function __construct( private ClientInterface $client, private CacheInterface $cache, private int $ttl = 300, - ) { - } + ) {} public function getStars(string $repository): int { @@ -29,18 +29,18 @@ public function getStars(string $repository): int return $stars; } - public function getLastVersion(string $repository): string + public function getLatestRelease(string $repository): Release { $cacheKey = $this->getCacheKey($repository, __METHOD__); if ($this->cache->has($cacheKey)) { return $this->cache->get($cacheKey); } - $version = $this->client->getLastVersion($repository); + $release = $this->client->getLatestRelease($repository); - $this->cache->set($cacheKey, $version, $this->ttl); + $this->cache->set($cacheKey, $release, $this->ttl); - return $version; + return $release; } public function getIssuesForContributors(): array diff --git a/app/app/src/Github/Client.php b/app/app/src/Github/Client.php index 792a12b..e74ec53 100644 --- a/app/app/src/Github/Client.php +++ b/app/app/src/Github/Client.php @@ -5,6 +5,7 @@ namespace App\Github; use App\Github\Entity\Issue; +use App\Github\Entity\Release; use Carbon\Carbon; use GuzzleHttp\Psr7\Request; use Psr\Log\LoggerInterface; @@ -14,8 +15,7 @@ public function __construct( private \Psr\Http\Client\ClientInterface $client, private LoggerInterface $logger, - ) { - } + ) {} public function getStars(string $repository): int { @@ -31,7 +31,7 @@ public function getStars(string $repository): int return $data['stargazers_count'] ?? 0; } - public function getLastVersion(string $repository): string + public function getLatestRelease(string $repository): Release { $response = $this->client->sendRequest( new Request( @@ -42,7 +42,11 @@ public function getLastVersion(string $repository): string $data = \json_decode($response->getBody()->getContents(), true); - return $data['tag_name'] ?? '0.0.0'; + return new Release( + repository: $repository, + version: $data['tag_name'], + createdAt: Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $data['created_at']), + ); } public function getIssuesForContributors(): array diff --git a/app/app/src/Github/ClientInterface.php b/app/app/src/Github/ClientInterface.php index eefa210..6e009a5 100644 --- a/app/app/src/Github/ClientInterface.php +++ b/app/app/src/Github/ClientInterface.php @@ -5,12 +5,13 @@ namespace App\Github; use App\Github\Entity\Issue; +use App\Github\Entity\Release; interface ClientInterface { public function getStars(string $repository): int; - public function getLastVersion(string $repository): string; + public function getLatestRelease(string $repository): Release; /** * @return Issue[] diff --git a/app/app/src/Github/Entity/Release.php b/app/app/src/Github/Entity/Release.php new file mode 100644 index 0000000..dbe3f91 --- /dev/null +++ b/app/app/src/Github/Entity/Release.php @@ -0,0 +1,23 @@ + $this->repository, + 'version' => $this->version, + 'createdAt' => $this->createdAt->format(\DateTimeInterface::ATOM), + ]; + } +}