dependabot-composer 0.292.0 → 0.293.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/helpers/v1/build +34 -0
- data/helpers/v1/composer.json +26 -0
- data/helpers/v1/composer.lock +2649 -0
- data/helpers/v1/src/UpdateChecker.php +129 -0
- data/helpers/v2/composer.json +1 -1
- data/helpers/v2/composer.lock +436 -806
- metadata +9 -5
@@ -0,0 +1,129 @@
|
|
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
|
+
// TODO surprisingly the returned result of getPrettyVersion depends on the PHP version:
|
86
|
+
// - PHP 7 returns: "2.4.1"
|
87
|
+
// - PHP 8 returns: "2.4.1@stable"
|
88
|
+
// file_put_contents('php://stdout', $updatedPackage->getPrettyVersion());
|
89
|
+
//
|
90
|
+
// return ltrim($updatedPackage->getPrettyVersion(), 'v');
|
91
|
+
$pretty = $updatedPackage->getPrettyVersion();
|
92
|
+
|
93
|
+
return rtrim(ltrim($pretty, 'v'), '@stable');
|
94
|
+
}
|
95
|
+
|
96
|
+
// We didn't find the package in the list of updated packages. Check if
|
97
|
+
// it was replaced by another package (in which case we can ignore).
|
98
|
+
foreach ($composer->getPackage()->getReplaces() as $link) {
|
99
|
+
if ($link->getTarget() === $dependencyName) {
|
100
|
+
return null;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
foreach ($installedPackages as $package) {
|
105
|
+
foreach ($package->getReplaces() as $link) {
|
106
|
+
if ($link->getTarget() === $dependencyName) {
|
107
|
+
return null;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
// Similarly, check if the package was provided by any other package.
|
113
|
+
foreach ($composer->getPackage()->getProvides() as $link) {
|
114
|
+
if ($link->getTarget() === $dependencyName) {
|
115
|
+
return ltrim($link->getPrettyConstraint(), 'v');
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
foreach ($installedPackages as $package) {
|
120
|
+
foreach ($package->getProvides() as $link) {
|
121
|
+
if ($link->getTarget() === $dependencyName) {
|
122
|
+
return ltrim($link->getPrettyConstraint(), 'v');
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
throw new \RuntimeException('Package not found in updated packages!');
|
128
|
+
}
|
129
|
+
}
|