dependabot-composer 0.292.0 → 0.294.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.
@@ -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
+ }
@@ -3,7 +3,7 @@
3
3
  "description": "A helper package for Dependabot to perform updates using Composer",
4
4
  "license": "MIT",
5
5
  "require": {
6
- "php": "^7.4",
6
+ "php": "^8.2",
7
7
  "ext-json": "*",
8
8
  "composer/composer": "^2"
9
9
  },