Skip to content

Commit

Permalink
ENH Use repositories from supported-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed May 8, 2024
1 parent b41956b commit a7bc573
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 266 deletions.
208 changes: 0 additions & 208 deletions app/src/DataFetcher/Misc/Consts.php

This file was deleted.

3 changes: 1 addition & 2 deletions app/src/DataFetcher/Requesters/AbstractRequester.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\DataFetcher\Requesters;

use App\DataFetcher\Apis\ApiConfigInterface;
use App\DataFetcher\Misc\Consts;
use App\DataFetcher\Models\ApiData;
use App\DataFetcher\Misc\Logger;
use App\DataFetcher\Interfaces\TypeInterface;
Expand Down Expand Up @@ -119,7 +118,7 @@ abstract protected function fetchDataFromApi(string $path, string $postBody = ''

protected function getMethod(string $postBody): string
{
return $postBody ? Consts::METHOD_POST : Consts::METHOD_GET;
return $postBody ? 'post' : 'get';
}

protected function waitUntilCanFetch()
Expand Down
3 changes: 1 addition & 2 deletions app/src/DataFetcher/Requesters/RestRequester.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\DataFetcher\Requesters;

use App\DataFetcher\Misc\Consts;
use App\DataFetcher\Misc\Logger;

class RestRequester extends AbstractRequester
Expand All @@ -29,7 +28,7 @@ protected function fetchDataFromApi(string $path, string $postBody = ''): string
$url = $apiConfig->deriveUrl($path, $offset);
Logger::singleton()->log("REST {$ucMethod} {$url}");
curl_setopt($ch, CURLOPT_URL, $url);
if ($method == Consts::METHOD_POST) {
if (strtolower($method) == 'post') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
}
Expand Down
58 changes: 58 additions & 0 deletions app/src/Misc/SupportedModulesManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Misc;

use SilverStripe\SupportedModules\MetaData;

class SupportedModulesManager
{
private array $modules = [];

private array $cmsMajorToBranches = [];

public function getModules(): array
{
if (!empty($this->modules)) {
return $this->modules;
}
$repoData = MetaData::getAllRepositoryMetaData();
$this->modules = [
'regular' => [],
'tooling' => [],
];
// Adapt json keys to the keys used in rhino
$types = [
MetaData::CATEGORY_SUPPORTED => 'regular',
MetaData::CATEGORY_WORKFLOW => 'tooling',
MetaData::CATEGORY_TOOLING => 'tooling',
MetaData::CATEGORY_MISC => 'tooling',
];
foreach ($types as $category => $type) {
foreach ($repoData[$category] as $module) {
[$account, $repo] = explode('/', $module['github']);
$this->modules[$type][$account] ??= [];
$this->modules[$type][$account][] = $repo;
$this->cmsMajorToBranches[$repo] = $module['majorVersionMapping'];
}
}
return $this->modules;
}

public function getMajorBranchIsSupported(string $repo, string $majorBranch): bool
{
if (empty($this->cmsMajorToBranches)) {
$this->getModules();
}
$cmsMajorToBranches = $this->cmsMajorToBranches[$repo] ?? [];
foreach ($cmsMajorToBranches as $cmsMajor => $branches) {
if ($cmsMajor === '*') {
return true;
}
if (in_array($majorBranch, $branches)) {
return true;
break;
}
}
return false;
}
}
1 change: 0 additions & 1 deletion app/src/Pages/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace {

use App\DataFetcher\Models\ApiData;
use SilverStripe\CMS\Controllers\ContentController;

class PageController extends ContentController
Expand Down
Loading

0 comments on commit a7bc573

Please sign in to comment.