Skip to content

Commit

Permalink
Merge branch 'master' into feat/close-outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Jul 9, 2022
2 parents 60cd9f7 + 9627bc8 commit e59b64b
Show file tree
Hide file tree
Showing 9 changed files with 11,196 additions and 18 deletions.
25 changes: 19 additions & 6 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,10 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
$updater->setRunScripts($config->shouldRunScripts());
if ($config->shouldUpdateIndirectWithDirect()) {
$updater->setShouldThrowOnUnupdated(false);
if (!empty($item->child_with_update)) {
$updater->setShouldThrowOnUnupdated(true);
$updater->setPackageToCheckHasUpdated($item->child_with_update);
}
}
if (!$lock_file_contents || ($should_update_beyond && $can_update_beyond)) {
$updater->executeRequire($version_to);
Expand Down Expand Up @@ -1529,21 +1533,30 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
} catch (NotUpdatedException $e) {
// Not updated because of the composer command, not the
// restriction itself.
$command = sprintf('composer why-not %s "%s"', $item->name, $item->latest);
$why_not_name = $original_name = $item->name;
$why_not_version = $item->latest;
$not_updated_context = [
'package' => $why_not_name,
];
if (!empty($item->child_latest) && !empty($item->child_with_update)) {
$why_not_name = $item->child_with_update;
$why_not_version = $item->child_latest;
$not_updated_context['package'] = $why_not_name;
$not_updated_context['parent_package'] = $original_name;
}
$command = sprintf('composer why-not %s "%s"', $why_not_name, $why_not_version);
$this->execCommand(sprintf('%s', $command), false);
$this->log($this->getLastStdErr(), Message::COMMAND, [
'command' => $command,
'package' => $item->name,
'package' => $why_not_name,
'type' => 'stderr',
]);
$this->log($this->getLastStdOut(), Message::COMMAND, [
'command' => $command,
'package' => $item->name,
'package' => $why_not_name,
'type' => 'stdout',
]);
$this->log("$package_name was not updated running composer update", Message::NOT_UPDATED, [
'package' => $package_name,
]);
$this->log("$package_name was not updated running composer update", Message::NOT_UPDATED, $not_updated_context);
} catch (ValidationFailedException $e) {
// @todo: Do some better checking. Could be several things, this.
$this->handlePossibleUpdatePrScenario($e, $branch_name, $pr_params, $prs_named, $config, $security_update);
Expand Down
32 changes: 32 additions & 0 deletions src/IndirectWithDirectFilterListItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace eiriksm\CosyComposer;

class IndirectWithDirectFilterListItem
{
private $name = '';
private $reason = [];
private $latestVersion = '';

public function __construct($package_name, $indirect_list, $latest_version)
{
$this->name = $package_name;
$this->reason = $indirect_list;
$this->latestVersion = $latest_version;
}

public function getLatestVersion() : string
{
return $this->latestVersion;
}

public function getReasons() : array
{
return $this->reason;
}

public function getName() : string
{
return $this->name;
}
}
38 changes: 29 additions & 9 deletions src/ListFilterer/IndirectWithDirectFilterer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace eiriksm\CosyComposer\ListFilterer;

use eiriksm\CosyComposer\IndirectWithDirectFilterListItem;
use Violinist\ComposerLockData\ComposerLockData;

class IndirectWithDirectFilterer implements FilterInterface
Expand Down Expand Up @@ -34,22 +35,41 @@ public static function create($composer_lock, $composer_json)
*/
public function filter(array $list) : array
{
/** @var IndirectWithDirectFilterListItem $new_list */
$new_list = [];
foreach ($list as $value) {
// Find the reason we have this.
$new_list = array_merge($this->findRequiresForPackage($value), $new_list);
$list_additions = $this->findRequiresForPackage($value, $value->name);
$item = new IndirectWithDirectFilterListItem($value->name, $list_additions, $value->latest);
$new_list[] = $item;
}
// So, let's create just a fake report of the ones we want. They should for sure be "semver safe update",
// either way.
$lock_data = ComposerLockData::createFromString(json_encode($this->lockData));
return array_map(function ($item) use ($lock_data) {
$package = $lock_data->getPackageData($item->name);
return (object) [
'name' => $item->name,
'version' => $package->version,
'latest' => $item->latest ?? 'dependencies',
'latest-status' => $item->{"latest-status"} ?? 'semver-safe-update',
];
$list_of_lists = array_map(function (IndirectWithDirectFilterListItem $list_item) use ($lock_data) {
$return = [];
foreach ($list_item->getReasons() as $reason) {
if (!$this->isInComposerJson($reason->name)) {
continue;
}
$package = $lock_data->getPackageData($reason->name);
$return[] = (object) [
'name' => $reason->name,
'version' => $package->version,
'latest' => $reason->latest ?? 'dependencies',
'latest-status' => $reason->{"latest-status"} ?? 'semver-safe-update',
'child_with_update' => $list_item->getName(),
'child_latest' => $list_item->getLatestVersion(),
];
}
return $return;
}, $new_list);
$return = [];
foreach ($list_of_lists as $list_list) {
foreach ($list_list as $item) {
$return[] = $item;
}
}
return $return;
}
}
11 changes: 9 additions & 2 deletions src/ListFilterer/RequiresForPackageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ trait RequiresForPackageTrait
{
private $scannedCache = [];

protected function findRequiresForPackage($package_obj)
protected function findRequiresForPackage($package_obj, $initial_package = null)
{
$package_name = mb_strtolower($package_obj->name);
$key = $package_name;
if (!empty($initial_package)) {
$key = $initial_package;
}
if (empty($this->scannedCache[$key])) {
$this->scannedCache[$key] = [];
}
// Loop over all packages, and see if any of the hits actually are required as top level require or require-dev.
$types = [
'packages',
Expand Down Expand Up @@ -47,7 +54,7 @@ protected function findRequiresForPackage($package_obj)
'name' => $candidate,
];
} else {
$requires = array_merge($requires, $this->findRequiresForPackage($package));
$requires = array_merge($requires, $this->findRequiresForPackage($package, $initial_package));
}
}
}
Expand Down
144 changes: 144 additions & 0 deletions test/fixtures/composer.actual_project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"name": "acquia/drupal-recommended-project",
"description": "Acquia-compatible Drupal application based on the Drupal Recommended Project",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Acquia Engineering",
"homepage": "https://www.acquia.com",
"role": "Maintainer"
}
],
"require": {
"php": ">=7.4",
"acquia/acquia-cms-starterkit": "^1",
"acquia/drupal-environment-detector": "^1",
"acquia/http-hmac-php": "3.4.0",
"acquia/memcache-settings": "^1",
"composer/installers": "^1.9",
"cweagans/composer-patches": "^1.6",
"drupal/core-composer-scaffold": "^9",
"drupal/core-recommended": "^9",
"drupal/upgrade_status": "^3.13",
"drush/drush": "^10.6 || ^11",
"oomphinc/composer-installers-extender": "^1.1 || ^2"
},
"require-dev": {
"acquia/coding-standards": "^0.8.0",
"mglaman/phpstan-drupal": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.6",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"drupal/core-composer-scaffold": true,
"ergebnis/composer-normalize": true,
"oomphinc/composer-installers-extender": true,
"phpstan/extension-installer": true
},
"platform": {
"php": "7.4"
},
"sort-packages": true
},
"extra": {
"composer-exit-on-patch-failure": true,
"drupal-scaffold": {
"allowed-packages": [
"acquia/acquia_cms"
],
"file-mapping": {
"[profile-root]/.editorconfig": false,
"[profile-root]/.gitattributes": false,
"[profile-root]/.travis.yml": false,
"[profile-root]/acquia-pipelines.yml": false,
"[web-root]/sites/default/default.services.yml": {
"mode": "replace",
"overwrite": false,
"path": "docroot/core/assets/scaffold/files/default.services.yml"
},
"[web-root]/sites/default/default.settings.php": {
"mode": "replace",
"overwrite": false,
"path": "docroot/core/assets/scaffold/files/default.settings.php"
}
},
"gitignore": true,
"locations": {
"profile-root": "docroot/profiles/contrib/acquia_cms",
"web-root": "docroot/"
}
},
"enable-patching": true,
"installer-paths": {
"docroot/core": [
"type:drupal-core"
],
"docroot/libraries/{$name}": [
"type:drupal-library",
"type:bower-asset",
"type:npm-asset"
],
"docroot/modules/contrib/{$name}": [
"type:drupal-module"
],
"docroot/modules/custom/{$name}": [
"type:drupal-custom-module"
],
"docroot/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"docroot/themes/contrib/{$name}": [
"type:drupal-theme"
],
"docroot/themes/custom/{$name}": [
"type:drupal-custom-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
]
},
"installer-types": [
"bower-asset",
"npm-asset"
],
"patchLevel": {
"drupal/core": "-p2"
},
"patches": {},
"violinist": {
"allow_update_indirect_with_direct": 1,
"allow_updates_beyond_constraint": 0,
"blocklist": [
"drupal/core-composer-scaffold"
],
"bundled_packages": {
"drupal/core-recommended": [
"drupal/core-composer-scaffold"
]
}
}
},
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"acms:install": [
"bash ./docroot/profiles/contrib/acquia_cms/install-acms"
],
"nuke": [
"rm -rf docroot vendor composer.lock"
]
}
}

0 comments on commit e59b64b

Please sign in to comment.