Skip to content

Commit

Permalink
ENH Use new main branch of supported-modules data
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 7, 2024
1 parent baf2287 commit 78d046e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Tasks/UpdatePackageInfoTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ public function getPackageInfo($packageList)
}

/**
* Return an array of supported modules as fetched from silverstripe/supported-modules. Outputs a message and returns null
* if an error occurs
* Return an array of supported modules as fetched from silverstripe/supported-modules.
* Outputs a message and returns null if an error occurs
*
* @return null|array
*/
Expand All @@ -234,8 +234,8 @@ public function getSupportedPackages()
}

/**
* Return an array of module health information as fetched from addons.silverstripe.org. Outputs a message and
* returns null if an error occurs
* Return an array of module health information as fetched from addons.silverstripe.org.
* Outputs a message and returns null if an error occurs
*
* @param string[] $moduleNames
* @return null|array
Expand Down
6 changes: 5 additions & 1 deletion src/Util/ApiLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public function doRequest($endpoint, callable $callback)
$responseJson = $this->parseResponseContents($response->getBody()->getContents(), $failureMessage);

if (str_contains($endpoint, 'addons.silverstripe.org')) {
Deprecation::notice('3.2.0', 'addons.silverstripe.org is no longer operational. Use packagist instead.', Deprecation::SCOPE_GLOBAL);
Deprecation::notice(
'3.2.0',
'addons.silverstripe.org is no longer operational. Use packagist instead.',
Deprecation::SCOPE_GLOBAL
);
if (!isset($responseJson['success']) || !$responseJson['success']) {
throw new RuntimeException($failureMessage . 'Response returned unsuccessfully');
}
Expand Down
7 changes: 5 additions & 2 deletions src/Util/SupportedAddonsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ class SupportedAddonsLoader extends ApiLoader
*/
public function getAddonNames()
{
$endpoint = 'https://raw.githubusercontent.com/silverstripe/supported-modules/5/modules.json';
$endpoint = 'https://raw.githubusercontent.com/silverstripe/supported-modules/main/repositories.json';
return $this->doRequest($endpoint, function ($responseJson) {
return array_map(fn(array $item) => $item['composer'], $responseJson);
return array_filter(array_map(
fn(array $item) => isset($item['majorVersionMapping'][5]) ? $item['packagist'] : null,
$responseJson['supportedModules']
));
});
}

Expand Down
56 changes: 51 additions & 5 deletions tests/Util/SupportedAddonsLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void

public function testCallsSupportedAddonsEndpoint()
{
$endpoint = 'https://raw.githubusercontent.com/silverstripe/supported-modules/5/modules.json';
$endpoint = 'https://raw.githubusercontent.com/silverstripe/supported-modules/main/repositories.json';
$this->loader->expects($this->once())
->method('doRequest')
->with($endpoint, function () {
Expand All @@ -42,11 +42,57 @@ public function testCallbackReturnsAddonsFromBody()

$result = $this->loader->getAddonNames();
$mockResponse = [
[
'composer' => 'foo/bar'
'supportedModules' => [
[
'github' => 'some/repo1',
'packagist' => 'foo/bar',
'majorVersionMapping' => [
4 => [4],
5 => [5],
],
],
[
'github' => 'some/repo2',
'packagist' => 'bin/baz',
'majorVersionMapping' => [
5 => [5, 6],
],
],
[
'github' => 'some/repo3',
'packagist' => 'bin/baz2',
'majorVersionMapping' => [
4 => [4],
],
],
],
[
'composer' => 'bin/baz'
'workflow' => [
[
'github' => 'some/repo4',
'packagist' => 'bin/baz1',
'majorVersionMapping' => [
4 => [4],
5 => [5],
],
],
],
'tooling' => [
[
'github' => 'some/repo5',
'packagist' => 'bin/baz2',
'majorVersionMapping' => [
5 => [5, 6],
],
],
],
'misc' => [
[
'github' => 'some/repo6',
'packagist' => 'bin/baz3',
'majorVersionMapping' => [
4 => [4],
],
],
],
];

Expand Down

0 comments on commit 78d046e

Please sign in to comment.