dependabot-composer 0.286.0 → 0.287.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +0,0 @@
1
- parameters:
2
- inferPrivatePropertyTypeFromConstructor: true
3
- level: 5
4
- paths:
5
- - src
@@ -1,61 +0,0 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dependabot\Composer;
6
-
7
- use Composer\DependencyResolver\Operation\InstallOperation;
8
- use Composer\DependencyResolver\Operation\UninstallOperation;
9
- use Composer\DependencyResolver\Operation\UpdateOperation;
10
- use Composer\Installer\InstallationManager;
11
- use Composer\Package\PackageInterface;
12
- use Composer\Repository\RepositoryInterface;
13
-
14
- final class DependabotInstallationManager extends InstallationManager
15
- {
16
- private array $installed = [];
17
- private array $updated = [];
18
- private array $uninstalled = [];
19
-
20
- public function install(RepositoryInterface $repo, InstallOperation $operation): void
21
- {
22
- parent::install($repo, $operation);
23
- $this->installed[] = $operation->getPackage();
24
- }
25
-
26
- public function update(RepositoryInterface $repo, UpdateOperation $operation): void
27
- {
28
- parent::update($repo, $operation);
29
- $this->updated[] = [$operation->getInitialPackage(), $operation->getTargetPackage()];
30
- }
31
-
32
- public function uninstall(RepositoryInterface $repo, UninstallOperation $operation): void
33
- {
34
- parent::uninstall($repo, $operation);
35
- $this->uninstalled[] = $operation->getPackage();
36
- }
37
-
38
- /**
39
- * @return PackageInterface[]
40
- */
41
- public function getInstalledPackages(): array
42
- {
43
- return $this->installed;
44
- }
45
-
46
- /**
47
- * @return PackageInterface[]
48
- */
49
- public function getUpdatedPackages(): array
50
- {
51
- return $this->updated;
52
- }
53
-
54
- /**
55
- * @return PackageInterface[]
56
- */
57
- public function getUninstalledPackages(): array
58
- {
59
- return $this->uninstalled;
60
- }
61
- }
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dependabot\Composer;
6
-
7
- use Composer\Package\PackageInterface;
8
- use Composer\Plugin\PluginManager;
9
-
10
- final class DependabotPluginManager extends PluginManager
11
- {
12
- public function registerPackage(PackageInterface $package, $failOnMissingClasses = false): void
13
- {
14
- // This package does some setup for PHP_CodeSniffer, but errors out the
15
- // install if Symfony isn't installed (which it won't be for a lockfile
16
- // only install run). Safe to ignore
17
- if (strpos($package->getName(), 'phpcodesniffer') !== false) {
18
- return;
19
- }
20
-
21
- parent::registerPackage($package, $failOnMissingClasses);
22
- }
23
- }
@@ -1,25 +0,0 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dependabot\Composer;
6
-
7
- use Composer\IO\NullIO;
8
-
9
- final class ExceptionIO extends NullIO
10
- {
11
- private bool $raise_next_error = false;
12
-
13
- public function writeError($messages, $newline = true, $verbosity = self::NORMAL): void
14
- {
15
- if (is_array($messages)) {
16
- return;
17
- }
18
- if ($this->raise_next_error) {
19
- throw new \RuntimeException('Your requirements could not be resolved to an installable set of packages.' . $messages);
20
- }
21
- if (strpos($messages, 'Your requirements could not be resolved') !== false) {
22
- $this->raise_next_error = true;
23
- }
24
- }
25
- }
@@ -1,28 +0,0 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dependabot\Composer;
6
-
7
- use Composer\Package\Locker;
8
-
9
- final class Hasher
10
- {
11
- /**
12
- * @throws \RuntimeException
13
- */
14
- public static function getContentHash(array $args): string
15
- {
16
- [$workingDirectory] = $args;
17
-
18
- $config = $workingDirectory . '/composer.json';
19
-
20
- $contents = file_get_contents($config);
21
-
22
- if (!is_string($contents)) {
23
- throw new \RuntimeException(sprintf('Failed to load contents of "%s".', $config));
24
- }
25
-
26
- return Locker::getContentHash($contents);
27
- }
28
- }
@@ -1,121 +0,0 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dependabot\Composer;
6
-
7
- use Composer\Factory;
8
- use Composer\Installer;
9
- use Composer\Package\PackageInterface;
10
-
11
- final class UpdateChecker
12
- {
13
- public static function getLatestResolvableVersion(array $args): ?string
14
- {
15
- [$workingDirectory, $dependencyName, $gitCredentials, $registryCredentials] = $args;
16
-
17
- $httpBasicCredentials = [];
18
-
19
- foreach ($gitCredentials as $credentials) {
20
- $httpBasicCredentials[$credentials['host']] = [
21
- 'username' => $credentials['username'],
22
- 'password' => $credentials['password'],
23
- ];
24
- }
25
-
26
- foreach ($registryCredentials as $credentials) {
27
- $httpBasicCredentials[$credentials['registry']] = [
28
- 'username' => $credentials['username'],
29
- 'password' => $credentials['password'],
30
- ];
31
- }
32
-
33
- $io = new ExceptionIO();
34
-
35
- $composer = Factory::create($io, $workingDirectory . '/composer.json');
36
-
37
- $config = $composer->getConfig();
38
-
39
- if (0 < count($httpBasicCredentials)) {
40
- $config->merge([
41
- 'config' => [
42
- 'http-basic' => $httpBasicCredentials,
43
- ],
44
- ]);
45
-
46
- $io->loadConfiguration($config);
47
- }
48
-
49
- $installationManager = new DependabotInstallationManager();
50
-
51
- $install = new Installer(
52
- $io,
53
- $config,
54
- $composer->getPackage(),
55
- $composer->getDownloadManager(),
56
- $composer->getRepositoryManager(),
57
- $composer->getLocker(),
58
- $installationManager,
59
- $composer->getEventDispatcher(),
60
- $composer->getAutoloadGenerator()
61
- );
62
-
63
- // For all potential options, see UpdateCommand in composer
64
- $install
65
- ->setDryRun(true)
66
- ->setUpdate(true)
67
- ->setDevMode(true)
68
- ->setUpdateAllowList([$dependencyName])
69
- ->setAllowListTransitiveDependencies(true)
70
- ->setExecuteOperations(false)
71
- ->setDumpAutoloader(false)
72
- ->setRunScripts(false)
73
- ->setIgnorePlatformRequirements(false);
74
-
75
- $install->run();
76
-
77
- $installedPackages = $installationManager->getInstalledPackages();
78
-
79
- $updatedPackage = current(array_filter($installedPackages, static function (PackageInterface $package) use ($dependencyName): bool {
80
- return $package->getName() === $dependencyName;
81
- }));
82
-
83
- // We found the package in the list of updated packages. Return its version.
84
- if ($updatedPackage instanceof PackageInterface) {
85
- return ltrim($updatedPackage->getPrettyVersion(), 'v');
86
- }
87
-
88
- // We didn't find the package in the list of updated packages. Check if
89
- // it was replaced by another package (in which case we can ignore).
90
- foreach ($composer->getPackage()->getReplaces() as $link) {
91
- if ($link->getTarget() === $dependencyName) {
92
- return null;
93
- }
94
- }
95
-
96
- foreach ($installedPackages as $package) {
97
- foreach ($package->getReplaces() as $link) {
98
- if ($link->getTarget() === $dependencyName) {
99
- return null;
100
- }
101
- }
102
- }
103
-
104
- // Similarly, check if the package was provided by any other package.
105
- foreach ($composer->getPackage()->getProvides() as $link) {
106
- if ($link->getTarget() === $dependencyName) {
107
- return ltrim($link->getPrettyConstraint(), 'v');
108
- }
109
- }
110
-
111
- foreach ($installedPackages as $package) {
112
- foreach ($package->getProvides() as $link) {
113
- if ($link->getTarget() === $dependencyName) {
114
- return ltrim($link->getPrettyConstraint(), 'v');
115
- }
116
- }
117
- }
118
-
119
- throw new \RuntimeException('Package not found in updated packages!');
120
- }
121
- }
@@ -1,98 +0,0 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dependabot\Composer;
6
-
7
- use Composer\Factory;
8
- use Composer\Installer;
9
-
10
- final class Updater
11
- {
12
- /**
13
- * @throws \RuntimeException
14
- */
15
- public static function update(array $args): array
16
- {
17
- [$workingDirectory, $dependencyName, $dependencyVersion, $gitCredentials, $registryCredentials] = $args;
18
-
19
- // Change working directory to the one provided, this ensures that we
20
- // install dependencies into the working dir, rather than a vendor folder
21
- // in the root of the project
22
- $originalDir = getcwd();
23
-
24
- if (!is_string($originalDir)) {
25
- throw new \RuntimeException('Failed determining the current working directory.');
26
- }
27
-
28
- chdir($workingDirectory);
29
-
30
- $io = new ExceptionIO();
31
- $composer = Factory::create($io);
32
- $config = $composer->getConfig();
33
- $httpBasicCredentials = [];
34
-
35
- $pm = new DependabotPluginManager($io, $composer, null, false);
36
- $composer->setPluginManager($pm);
37
- $pm->loadInstalledPlugins();
38
-
39
- foreach ($gitCredentials as &$cred) {
40
- $httpBasicCredentials[$cred['host']] = [
41
- 'username' => $cred['username'],
42
- 'password' => $cred['password'],
43
- ];
44
- }
45
-
46
- foreach ($registryCredentials as &$cred) {
47
- $httpBasicCredentials[$cred['registry']] = [
48
- 'username' => $cred['username'],
49
- 'password' => $cred['password'],
50
- ];
51
- }
52
-
53
- if ($httpBasicCredentials) {
54
- $config->merge(
55
- [
56
- 'config' => [
57
- 'http-basic' => $httpBasicCredentials,
58
- ],
59
- ]
60
- );
61
- $io->loadConfiguration($config);
62
- }
63
-
64
- $install = new Installer(
65
- $io,
66
- $config,
67
- $composer->getPackage(),
68
- $composer->getDownloadManager(),
69
- $composer->getRepositoryManager(),
70
- $composer->getLocker(),
71
- $composer->getInstallationManager(),
72
- $composer->getEventDispatcher(),
73
- $composer->getAutoloadGenerator()
74
- );
75
-
76
- // For all potential options, see UpdateCommand in composer
77
- $install
78
- ->setWriteLock(true)
79
- ->setUpdate(true)
80
- ->setDevMode(true)
81
- ->setUpdateAllowList([$dependencyName])
82
- ->setAllowListTransitiveDependencies(true)
83
- ->setExecuteOperations(false)
84
- ->setDumpAutoloader(false)
85
- ->setRunScripts(false)
86
- ->setIgnorePlatformRequirements(false);
87
-
88
- $install->run();
89
-
90
- $result = [
91
- 'composer.lock' => file_get_contents('composer.lock'),
92
- ];
93
-
94
- chdir($originalDir);
95
-
96
- return $result;
97
- }
98
- }