diff --git a/src/DiffRecipeVersionsCommand.php b/src/DiffRecipeVersionsCommand.php index 669bb2d..82b20ba 100644 --- a/src/DiffRecipeVersionsCommand.php +++ b/src/DiffRecipeVersionsCommand.php @@ -30,13 +30,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $packages = []; $requires = []; - while (false !== $package = fgets(STDIN)) { + while (false !== $package = fgets(\STDIN)) { $package = substr($package, 0, -1); - $versions = scandir($package, SCANDIR_SORT_NONE); + $versions = scandir($package, \SCANDIR_SORT_NONE); usort($versions, 'version_compare'); - if (!$versions = array_slice($versions, 2)) { + if (!$versions = \array_slice($versions, 2)) { continue; } @@ -102,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($versions as $version) { $diff = shell_exec(sprintf('LC_ALL=C git diff --color=never --no-index %s/%s %1$s/%s', $package, $previousVersion, $version)); - $output->writeln("
"); + $output->writeln('
'); $output->writeln(sprintf("%s vs %s\n", $previousVersion, $version)); $output->writeln("```diff\n$diff```"); $output->writeln("\n
\n"); diff --git a/src/GenerateFlexEndpointCommand.php b/src/GenerateFlexEndpointCommand.php index cb47e0e..84be3c7 100644 --- a/src/GenerateFlexEndpointCommand.php +++ b/src/GenerateFlexEndpointCommand.php @@ -14,7 +14,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\HttpClient\HttpClient; #[AsCommand(name: 'generate:flex-endpoint', description: 'Generates the json files required by Flex')] class GenerateFlexEndpointCommand extends Command @@ -56,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // stdin usually generated by `git ls-tree HEAD */*/*` - while (false !== $line = fgets(STDIN)) { + while (false !== $line = fgets(\STDIN)) { [$tree, $package] = explode("\t", trim($line)); [,, $tree] = explode(' ', $tree); @@ -98,8 +97,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'repository' => sprintf('github.com/%s', $repository), 'origin_template' => sprintf('{package}:{version}@github.com/%s:%s', $repository, $sourceBranch), 'recipe_template' => sprintf('https://raw.githubusercontent.com/%s/%s/{package_dotted}.{version}.json', $repository, $flexBranch), + 'archived_recipes_template' => sprintf('https://raw.githubusercontent.com/%s/%s/archived/{package_dotted}/{ref}.json', $repository, $flexBranch), ], - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); + ], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)."\n"); return 0; } @@ -138,15 +138,26 @@ private function generatePackageJson(string $package, string $version, array $ma ksort($files, \SORT_NATURAL); - file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), json_encode([ - 'manifests' => [ - $package => [ - 'manifest' => $manifest, - 'files' => $files, - 'ref' => $tree, + $contents = json_encode( + [ + 'manifests' => [ + $package => [ + 'manifest' => $manifest, + 'files' => $files, + 'ref' => $tree, + ], ], ], - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); + \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES + )."\n"; + file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), $contents); + + // save another version for the archives + $archivedPath = sprintf('%s/archived/%s.%s/%s.json', $outputDir, str_replace('/', '.', $package), $version, $tree); + if (!file_exists(\dirname($archivedPath))) { + mkdir(\dirname($archivedPath), 0777, true); + } + file_put_contents($archivedPath, $contents); return true; } diff --git a/src/LintYamlCommand.php b/src/LintYamlCommand.php index 2061042..fa59962 100644 --- a/src/LintYamlCommand.php +++ b/src/LintYamlCommand.php @@ -24,7 +24,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $exit = 0; - while (false !== $file = fgets(STDIN)) { + while (false !== $file = fgets(\STDIN)) { $file = substr($file, 0, -1); $this->validate($file, $output, $exit); } diff --git a/src/ListUnpatchedPackagesCommand.php b/src/ListUnpatchedPackagesCommand.php index 2afb4d9..354a800 100644 --- a/src/ListUnpatchedPackagesCommand.php +++ b/src/ListUnpatchedPackagesCommand.php @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $client = HttpClient::create(); $diff = $client->request('GET', $data['pull_request']['diff_url'], ['auth_bearer' => $input->getArgument('github_token')])->getContent(); - preg_match_all('{^diff --git a/(([^/]++/[^/]++)/.*) b/\1$}m', $diff, $matches, PREG_PATTERN_ORDER); + preg_match_all('{^diff --git a/(([^/]++/[^/]++)/.*) b/\1$}m', $diff, $matches, \PREG_PATTERN_ORDER); $patchedPackages = array_flip($matches[2]);