Skip to content

Commit

Permalink
Fix VersionCreatedListener wrong stable version handling/parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Mar 25, 2022
1 parent 0934171 commit 9d8dc8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Application\Message\Event\Package\PackageUpdatedEvent;
use App\Domain\Package\PackageRepositoryInterface;
use Composer\Semver\Comparator;
use Composer\Semver\Semver;
use Composer\Semver\VersionParser;
use Courier\Client\Producer;
use Courier\Message\EventInterface;
Expand Down Expand Up @@ -41,8 +40,8 @@ public function __invoke(EventInterface $event): void {
$version = $event->getVersion();
// $this->logger->debug('Version created', [$version]);

// ignore non-release versions
if ($version->isRelease() === false) {
// ignore non-release or non-stable versions
if ($version->isRelease() === false || $version->isStable() === false) {
return;
}

Expand All @@ -51,13 +50,11 @@ public function __invoke(EventInterface $event): void {
);

$latestVersionNormalized = '0.0.0.0';
$latestVersionIsStable = false;
if ($package->getLatestVersion() !== '') {
$latestVersionNormalized = $this->versionParser->normalize($package->getLatestVersion());
$latestVersionIsStable = VersionParser::parseStability($latestVersionNormalized) === 'stable';
}

if ($latestVersionIsStable && Comparator::greaterThan($version->getNormalized(), $latestVersionNormalized)) {
if (Comparator::greaterThan($version->getNormalized(), $latestVersionNormalized)) {
$package = $package->withLatestVersion($version->getNumber());
$package = $this->packageRepository->update($package);

Expand Down
5 changes: 5 additions & 0 deletions src/Domain/Version/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace App\Domain\Version;

use Composer\Semver\VersionParser;
use DateTimeImmutable;
use JsonSerializable;
use ReturnTypeWillChange;
Expand Down Expand Up @@ -135,6 +136,10 @@ public function getUpdatedAt(): ?DateTimeImmutable {
return $this->updatedAt;
}

public function isStable(): bool {
return VersionParser::parseStability($this->normalized) === 'stable';
}

public function isDirty(): bool {
return $this->dirty;
}
Expand Down

0 comments on commit 9d8dc8d

Please sign in to comment.