Skip to content

Commit

Permalink
ENH Add param to not make network request
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 17, 2024
1 parent 32a718e commit 513f3b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
Metadata and some supporting PHP logic for determining which branches of various GitHub repositories relate to which versions of Silverstripe CMS.

> [!IMPORTANT]
> Only the `main` branch of this repository is maintained.
> Only the `main` branch of this repository is maintained. Stable tags must be manually created from the `main` branch. There is no auto tagging via a GitHub action. All branches other than `main` are legacy and should not be referenced going forward.
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.
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. There is a local copy of `repositories.json` in the module, though it is not guaranteed to be up to date, so only use this if fetching a fresh copy of this file is not viable.

## Format

Expand Down
6 changes: 4 additions & 2 deletions src/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ public static function removeReposNotInCmsMajor(array $metadata, string|int $cms
/**
* Get all metadata about all repositories we have information about.
* @param bool $categorised If true, output is grouped by category.
* @param bool $doFetch If true, make a network request to fetch a fresh version of the data
* from the supported-modules repository. If false, use the local copy.
*/
public static function getAllRepositoryMetaData(bool $categorised = true): array
public static function getAllRepositoryMetaData(bool $categorised = true, bool $doFetch = true): array
{
if (empty(self::$repositoryMetaData)) {
if (self::$isRunningUnitTests) {
if (self::$isRunningUnitTests || !$doFetch) {
$rawJson = file_get_contents(__DIR__ . '/../repositories.json');
} else {
// Dynamicallly fetch the latest data from the supported-modules repository
Expand Down

0 comments on commit 513f3b1

Please sign in to comment.