Skip to content

Commit

Permalink
ENH Fetch respositories.json from raw.githubusercontent.com
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed May 8, 2024
1 parent 08ca1f1 commit 4f59132
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
composer.lock
.phpunit.result.cache
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <https://raw.githubusercontent.com/silverstripe/supported-modules/main/repositories.json>, 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. <https://raw.githubusercontent.com/silverstripe/supported-modules/main/repositories.json>.

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

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
Expand Down
14 changes: 13 additions & 1 deletion src/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

final class MetaData
{
public static $isRunningUnitTests = false;

public const CATEGORY_SUPPORTED = 'supportedModules';

public const CATEGORY_WORKFLOW = 'workflow';
Expand Down Expand Up @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use SilverStripe\SupportedModules\MetaData;

require_once __DIR__ . '/../vendor/autoload.php';

MetaData::$isRunningUnitTests = true;

0 comments on commit 4f59132

Please sign in to comment.