Skip to content

Commit f8a2bc9

Browse files
Display real "composer require" on PR comment
1 parent cbe4fa5 commit f8a2bc9

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/DiffRecipeVersionsCommand.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,26 @@ protected function configure(): void
2727

2828
protected function execute(InputInterface $input, OutputInterface $output): int
2929
{
30+
$packages = [];
31+
$requires = [];
32+
33+
while (false !== $package = fgets(STDIN)) {
34+
$package = substr($package, 0, -1);
35+
36+
$versions = scandir($package, SCANDIR_SORT_NONE);
37+
usort($versions, 'version_compare');
38+
39+
if (!$versions = array_slice($versions, 2)) {
40+
continue;
41+
}
42+
43+
$packages[$package] = $versions;
44+
45+
$requires[] = escapeshellarg($package.':^'.array_pop($versions));
46+
}
47+
3048
if ($endpoint = $input->getArgument('endpoint')) {
49+
$requires = implode(' ', $requires);
3150
$endpoint = <<<EOMD
3251
3352
## How to test these changes in your application
@@ -40,7 +59,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4059
SET SYMFONY_ENDPOINT={$endpoint}
4160
```
4261
43-
2. Install the package(s) related to this recipe using `composer require`
62+
2. Install the package(s) related to this recipe:
63+
```sh
64+
composer req 'symfony/flex:^1.16'
65+
composer req {$requires}
66+
```
4467
4568
3. Don't forget to unset the `SYMFONY_ENDPOINT` environment variable when done:
4669
```sh
@@ -55,20 +78,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5578

5679
$head = <<<EOMD
5780
Thanks for the PR 😍
58-
81+
{$endpoint}
5982
## Diff between recipe versions
6083
6184
In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
6285
I'm going keep this comment up to date with any updates of the attached patch.
6386
6487
EOMD;
6588

66-
while (false !== $package = fgets(STDIN)) {
67-
$package = substr($package, 0, -1);
68-
69-
$versions = scandir($package, SCANDIR_SORT_NONE);
70-
usort($versions, 'version_compare');
71-
$versions = array_slice($versions, 2);
89+
foreach ($packages as $package => $versions) {
7290
$previousVersion = array_shift($versions);
7391

7492
if (!$versions) {

src/GenerateFlexEndpointCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8585
'origin_template' => sprintf('{package}:{version}@github.com/%s:%s', $repository, $sourceBranch),
8686
'recipe_template' => sprintf('https://api.github.com/repos/%s/contents/{package_dotted}.{version}.json?ref=%s', $repository, $flexBranch),
8787
],
88-
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
88+
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
8989

9090
return 0;
9191
}
@@ -124,6 +124,6 @@ private function generatePackageJson(string $package, string $version, array $ma
124124
'ref' => $tree,
125125
],
126126
],
127-
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
127+
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
128128
}
129129
}

0 commit comments

Comments
 (0)