Skip to content

Commit

Permalink
Channel version type is an Enum (LycheeOrg#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Apr 6, 2024
1 parent d80662b commit 86222ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
50 changes: 29 additions & 21 deletions app/Actions/Diagnostics/Pipes/Infos/VersionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Actions\Diagnostics\Diagnostics;
use App\Contracts\DiagnosticPipe;
use App\DTO\LycheeGitInfo;
use App\Enum\VersionChannelType;
use App\Metadata\Versions\FileVersion;
use App\Metadata\Versions\GitHubVersion;
use App\Metadata\Versions\InstalledVersion;
Expand All @@ -14,36 +15,26 @@
*/
class VersionInfo implements DiagnosticPipe
{
private InstalledVersion $installedVersion;

public function __construct(
InstalledVersion $installedVersion,
private InstalledVersion $installedVersion,
public FileVersion $fileVersion,
public GitHubVersion $gitHubFunctions,
) {
$this->installedVersion = $installedVersion;
$this->fileVersion->hydrate(withRemote: false);
}

/**
* {@inheritDoc}
*/
public function handle(array &$data, \Closure $next): array
{
if ($this->installedVersion->isRelease()) {
// @codeCoverageIgnoreStart
$lycheeChannelName = 'release';

$fileVersion = resolve(FileVersion::class);
$fileVersion->hydrate(false, false);

$lycheeInfoString = $fileVersion->getVersion()->toString();
// @codeCoverageIgnoreEnd
} else {
$gitHubFunctions = resolve(GitHubVersion::class);
$gitHubFunctions->hydrate();
/** @var VersionChannelType $channelName */
$channelName = $this->getChannelName();
$lycheeInfoString = $this->fileVersion->getVersion()->toString();

$lycheeChannelName = $gitHubFunctions->isRelease() ? 'tags' : 'git';

if ($gitHubFunctions->localHead !== null) {
$gitInfo = new LycheeGitInfo($gitHubFunctions);
if ($channelName !== VersionChannelType::RELEASE) {
if ($this->gitHubFunctions->localHead !== null) {
$gitInfo = new LycheeGitInfo($this->gitHubFunctions);
$lycheeInfoString = $gitInfo->toString();
} else {
// @codeCoverageIgnoreStart
Expand All @@ -52,10 +43,27 @@ public function handle(array &$data, \Closure $next): array
}
}

$data[] = Diagnostics::line('Lychee Version (' . $lycheeChannelName . '):', $lycheeInfoString);
$data[] = Diagnostics::line('Lychee Version (' . $channelName->value . '):', $lycheeInfoString);
$data[] = Diagnostics::line('DB Version:', $this->installedVersion->getVersion()->toString());
$data[] = '';

return $next($data);
}

/**
* Get channel name.
*
* @return VersionChannelType
*/
public function getChannelName()
{
$lycheeChannelName = VersionChannelType::RELEASE;

if (!$this->installedVersion->isRelease()) {
$this->gitHubFunctions->hydrate(withRemote: true, useCache: true);
$lycheeChannelName = $this->gitHubFunctions->isRelease() ? VersionChannelType::TAG : VersionChannelType::GIT;
}

return $lycheeChannelName;
}
}
13 changes: 13 additions & 0 deletions app/Enum/VersionChannelType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Enum;

/**
* Channel types used by Lychee.
*/
enum VersionChannelType: string
{
case RELEASE = 'release';
case GIT = 'git';
case TAG = 'tag';
}

0 comments on commit 86222ab

Please sign in to comment.