diff --git a/.gitignore b/.gitignore index 55940e5..0794651 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache diff --git a/README.md b/README.md index 721de9b..f4fcdbc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ Metadata and some supporting PHP logic for determining which branches of various > [!IMPORTANT] > Only the `main` branch of this repository is maintained. -You can fetch the JSON by simply fetching the raw copy of `repositories.json` file, e.g. , though you're encouraged to use composer to pull in the data instead where appropriate. +You can fetch the JSON by simply fetching the raw copy of `repositories.json` file, e.g. . + +If you've included this module as a compser dependency then you can use `SilverStripe\SupportedModules\MetaData::getAllRepositoryMetaData()` which will fetch the latest version of the JSON file from raw.githubusercontent.com. ## Format diff --git a/phpunit.xml b/phpunit.xml index d797431..f5e111b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + tests diff --git a/src/MetaData.php b/src/MetaData.php index 41dd9d5..304e68e 100644 --- a/src/MetaData.php +++ b/src/MetaData.php @@ -6,6 +6,8 @@ final class MetaData { + public static $isRunningUnitTests = false; + public const CATEGORY_SUPPORTED = 'supportedModules'; public const CATEGORY_WORKFLOW = 'workflow'; @@ -175,7 +177,17 @@ public static function removeReposNotInCmsMajor(array $metadata, string|int $cms public static function getAllRepositoryMetaData(bool $categorised = true): array { if (empty(self::$repositoryMetaData)) { - $rawJson = file_get_contents(__DIR__ . '/../repositories.json'); + if (self::$isRunningUnitTests) { + $rawJson = file_get_contents(__DIR__ . '/../repositories.json'); + } else { + // Dynamicallly fetch the latest data from the supported-modules repository + // rather than reading it locally. This is done do that the data is always up-to-date + // and there's no need to run composer update and deploy the code to get the latest data. + $rawJson = file_get_contents('https://raw.githubusercontent.com/silverstripe/supported-modules/main/repositories.json'); + if (!$rawJson) { + throw new RuntimeException('Could not fetch repositories.json data'); + } + } $decodedJson = json_decode($rawJson, true); if ($decodedJson === null) { throw new RuntimeException('Could not parse repositories.json data: ' . json_last_error_msg()); diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..e96e7a1 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,7 @@ +