Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#114 skip pre-release versions when picking the last minor release #118

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
#114 skip pre-release (alpha/beta) versions from "last minor" sel…
…ection logic

Pre-releases are not to be considered for default stability checks.
  • Loading branch information
Ocramius committed Feb 11, 2019
commit 2661f847b9b76dbba5cdd94fde6a73b8e837059e
12 changes: 10 additions & 2 deletions src/Git/PickLastMinorVersionFromCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Process\Exception\RuntimeException;
use Version\Constraint\ComparisonConstraint;
use Version\Constraint\CompositeConstraint;
use Version\Constraint\ConstraintInterface;
use Version\Version;
use Version\VersionsCollection;
use function array_values;
Expand All @@ -26,12 +27,19 @@ public function forVersions(VersionsCollection $versions) : Version
Assert::that($versions->count())
->greaterThan(0, 'Cannot determine latest minor version from an empty collection');

$versionsSortedDescending = $versions->sortedDescending();
$stableVersions = $versions->matching(new class implements ConstraintInterface {
public function assert(Version $version) : bool
{
return ! $version->isPreRelease();
}
});

$versionsSortedDescending = $stableVersions->sortedDescending();

/** @var Version $lastVersion */
$lastVersion = array_values(iterator_to_array($versionsSortedDescending))[0];

$matchingMinorVersions = $versions
$matchingMinorVersions = $stableVersions
->matching(new CompositeConstraint(
CompositeConstraint::OPERATOR_AND,
new ComparisonConstraint(ComparisonConstraint::OPERATOR_LTE, $lastVersion),
Expand Down