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 Use repositories from supported-modules #24

Merged
merged 1 commit into from
May 8, 2024
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
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';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated refactoring

}

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') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated refactoring

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;
}
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
}
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated refactoring, unused import

use SilverStripe\CMS\Controllers\ContentController;

class PageController extends ContentController
Expand Down
Loading