Skip to content

Commit

Permalink
Adds releases and updates team
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Jun 11, 2024
1 parent 2883438 commit f85ab64
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/app/src/Endpoint/Http/Controller/SettingsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
],
]);
Expand Down
8 changes: 7 additions & 1 deletion app/app/src/Endpoint/Http/Controller/TeamAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
12 changes: 6 additions & 6 deletions app/app/src/Github/CacheableClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Github;

use App\Github\Entity\Release;
use Psr\SimpleCache\CacheInterface;

final readonly class CacheableClient implements ClientInterface
Expand All @@ -12,8 +13,7 @@ public function __construct(
private ClientInterface $client,
private CacheInterface $cache,
private int $ttl = 300,
) {
}
) {}

public function getStars(string $repository): int
{
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions app/app/src/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,8 +15,7 @@
public function __construct(
private \Psr\Http\Client\ClientInterface $client,
private LoggerInterface $logger,
) {
}
) {}

public function getStars(string $repository): int
{
Expand All @@ -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(
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/app/src/Github/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
23 changes: 23 additions & 0 deletions app/app/src/Github/Entity/Release.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Github\Entity;

final readonly class Release implements \JsonSerializable
{
public function __construct(
public string $repository,
public string $version,
public \DateTimeInterface $createdAt,
) {}

public function jsonSerialize(): array
{
return [
'repository' => $this->repository,
'version' => $this->version,
'createdAt' => $this->createdAt->format(\DateTimeInterface::ATOM),
];
}
}

0 comments on commit f85ab64

Please sign in to comment.