Skip to content

Commit

Permalink
feat: Project::getUnstableDependencies consideration of transitive de…
Browse files Browse the repository at this point in the history
…pendencies
  • Loading branch information
sitepark-veltrup committed May 14, 2024
1 parent a5478b5 commit 354ec54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
26 changes: 11 additions & 15 deletions src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SP\Composer\Project;

use Composer\InstalledVersions;
use Composer\Package\RootPackageInterface;
use Composer\Semver\Comparator;
use Composer\Semver\VersionParser;
Expand Down Expand Up @@ -200,20 +201,15 @@ public function isRelease(): bool
public function getUnstableDependencies(array $excludes = []): array
{

// TODO: Also check entries from the lock file?
// composer show --locked -D -f json

/* @var $allRequires \Composer\Package\Link[] */
$allRequires = array_merge(
$this->package->getRequires(),
$this->package->getDevRequires()
);

$unstable = [];
foreach ($allRequires as $req) {
$stability = VersionParser::parseStability($req->getPrettyConstraint());
if ($stability !== 'stable' && !in_array($req->getTarget(), $excludes, true)) {
$unstable[] = $req->getTarget() . ':' . $req->getPrettyConstraint();
foreach (InstalledVersions::getInstalledPackages() as $package) {
if ($package === $this->package->getName()) {
continue;
}
$version = InstalledVersions::getVersion($package);
$stability = VersionParser::parseStability($version);
if ($stability !== 'stable' && !in_array($package, $excludes, true)) {
$unstable[] = $package . ':' . $version;
}
}

Expand All @@ -223,11 +219,11 @@ public function getUnstableDependencies(array $excludes = []): array
public function getLatestReleaseVersion(): ?string
{
if ($this->isSupportBranch()) {
[$major]= $this->parseVersionFromBranch($this->getBranch());
[$major] = $this->parseVersionFromBranch($this->getBranch());
return $this->getLatestReleaseFromMajor((int)$major);
}
if ($this->isHotfixBranch()) {
[$major, $minor]= $this->parseVersionFromBranch($this->getBranch());
[$major, $minor] = $this->parseVersionFromBranch($this->getBranch());
return $this->getLatestReleaseFromMinor((int)$major, (int)$minor);
}

Expand Down
7 changes: 6 additions & 1 deletion src/ReleaseManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public function verifyRelease(): void
'roave/security-advisories'
]);
if (count($unstable) > 0) {
throw new \RuntimeException('There are unstable dependencies:' . "\n\n" . implode("\n", $unstable));
throw new \RuntimeException(
'There are unstable dependencies:' . "\n\n" .
implode("\n", $unstable) . "\n\n" .
"Show with:\n\n" .
"composer show"
);
}
}

Expand Down

0 comments on commit 354ec54

Please sign in to comment.