Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH New method to get metadata without a network request #43

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 composer 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
9 changes: 6 additions & 3 deletions src/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,16 @@ public static function removeReposNotInCmsMajor(array $metadata, string|int $cms
}

/**
* Get all metadata about all repositories we have information about.
* Get all metadata about all repositories we have information about. This will make a newtwork
* request to fetch the latest data from the supported-modules repository.
* @param bool $categorised If true, output is grouped by category.
* @param bool $fromRemote If true, fetch the data from the remote repository.
* If false, use the local file.
*/
public static function getAllRepositoryMetaData(bool $categorised = true): array
public static function getAllRepositoryMetaData(bool $categorised = true, $fromRemote = true): array
{
if (empty(self::$repositoryMetaData)) {
if (self::$isRunningUnitTests) {
if (self::$isRunningUnitTests || !$fromRemote) {
$rawJson = file_get_contents(__DIR__ . '/../repositories.json');
} else {
// Dynamicallly fetch the latest data from the supported-modules repository
Expand Down