Skip to content

Commit

Permalink
ENH Update reference to supported modules data
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 8, 2024
1 parent d273eee commit f68ded1
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ generated through [Doctum](https://github.com/code-lts/doctum#readme).
### Add a new major ersion

* Add a new version in the `'versions'` key in `conf/doctum.json`
* Make sure https://github.com/silverstripe/supported-modules has been updated with a new branch for the new major version with correct branch mapping
* Make sure https://github.com/silverstripe/supported-modules has been updated with correct branch mapping
* Run `makedoc.sh` and confirm the generation runs through properly
* Make a commit of the updated `conf/doctum.json`
* Update the redirections in `.htaccess` to the stable version number (if releasing a new stable major version)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"require": {
"php": "^8.1",
"gitonomy/gitlib": "^1.2",
"silverstripe/supported-modules": "dev-main",
"symfony/console": "^6.2",
"code-lts/doctum": "^5.5.3",
"psr/log": "^3.0"
Expand Down
126 changes: 123 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 50 additions & 10 deletions src/Console/CheckoutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use RuntimeException;
use SilverStripe\ApiDocs\Data\Config;
use SilverStripe\ApiDocs\Data\RepoFactory;
use SilverStripe\SupportedModules\MetaData;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -17,6 +18,7 @@ class CheckoutCommand extends Command
/**
* Regex patterns for github repositories that should be ignored.
* These are repositories that don't have relevant API.
* The patterns are matched against the packagist name for the module.
*/
private array $ignoreModulePatterns = [
'/^silverstripe\/developer-docs$/',
Expand Down Expand Up @@ -162,21 +164,43 @@ private function buildVersionMap(array $config, OutputInterface $output)
$map = [];
$versions = array_keys($config['versions']);

foreach ($versions as $version) {
$modulesUrl = "https://raw.githubusercontent.com/silverstripe/supported-modules/$version/modules.json";
$repos = MetaData::getAllRepositoryMetaData()[MetaData::CATEGORY_SUPPORTED];
foreach ($repos as $repo) {
if ($this->shouldIgnoreModule($repo)) {
continue;
}
$githubName = $repo['github'];
$moduleName = $repo['packagist'];
$versionMap = $repo['majorVersionMapping'];
// Remove any wildcards, and make sure we only have one branch for each cms major
foreach ($versionMap as $cmsMajor => $branches) {
if ($cmsMajor === '*') {
unset($$versionMap[$cmsMajor]);
continue;
}
$versionMap[$cmsMajor] = end($branches);
}
$map[$moduleName] = [
'repository' => "https://github.com/$githubName.git",
'versionmap' => $versionMap,
];
}

// CMS 3 isn't in the main branch of silverstripe/supported-modules - we have to use a legacy branch for that data.
if (in_array(3, $versions)) {
$modulesUrl = "https://raw.githubusercontent.com/silverstripe/supported-modules/3/modules.json";
$modulesJson = json_decode(file_get_contents($modulesUrl) ?: 'null', true);

if ($modulesJson === null) {
throw new RuntimeException('Modules data could not be retrieved for version ' . $version);
throw new RuntimeException('Modules data could not be retrieved for version 3');
}

foreach ($modulesJson as $module) {
$moduleName = $module['composer'];

if ($this->shouldIgnoreModule($module)) {
if ($this->shouldIgnoreModuleLegacy($module, true)) {
continue;
}

$moduleName = $module['composer'];
if (!array_key_exists($moduleName, $map)) {
$githubName = $module['github'];
$map[$moduleName] = [
Expand All @@ -187,22 +211,23 @@ private function buildVersionMap(array $config, OutputInterface $output)

$branches = $module['branches'];
sort($branches);
$map[$moduleName]['versionmap'][$version] = end($branches);
$map[$moduleName]['versionmap'][3] = end($branches);
}
}

foreach ($map as &$data) {
// Add a null entry for anything that's not supported for a given version
foreach ($map as $index => $data) {
foreach ($versions as $version) {
if (!isset($data['versionmap'][$version])) {
$data['versionmap'][$version] = null;
$map[$index]['versionmap'][$version] = null;
}
}
}

return $map;
}

private function shouldIgnoreModule(array $module)
private function shouldIgnoreModuleLegacy(array $module)
{
if ($module['type'] !== 'supported-module' || empty($module['branches'])) {
return true;
Expand All @@ -216,4 +241,19 @@ private function shouldIgnoreModule(array $module)

return false;
}

private function shouldIgnoreModule(array $module)
{
if ($module['type'] === 'other' || empty($module['majorVersionMapping'])) {
return true;
}

foreach ($this->ignoreModulePatterns as $regex) {
if (preg_match($regex, $module['packagist'])) {
return true;
}
}

return false;
}
}

0 comments on commit f68ded1

Please sign in to comment.