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 7, 2024
1 parent b41956b commit 1918d01
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 224 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
39 changes: 39 additions & 0 deletions app/src/Misc/SupportedModulesManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Misc;

use SilverStripe\Control\Controller;

class SupportedModulesManager
{
public function getSupportedModules(): array
{
$path = Controller::join_links(
BASE_PATH,
'vendor',
'silverstripe',
'supported-modules',
'repositories.json'
);
$json = json_decode(file_get_contents($path), true);
$ret = [
'regular' => [],
'tooling' => [],
];
// Adapt json keys to the keys used in rhino
$types = [
'supportedModules' => 'regular',
'workflow' => 'tooling',
'tooling' => 'tooling',
'misc' => 'tooling'
];
foreach ($types as $jsonKey => $type) {
foreach ($json[$jsonKey] as $module) {
[$account, $repo] = explode('/', $module['github']);
$ret[$type][$account] ??= [];
$ret[$type][$account][] = $repo;
}
}
return $ret;
}
}
4 changes: 4 additions & 0 deletions app/src/Pages/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace {

use App\Misc\SupportedModulesManager;

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

Expand All @@ -10,6 +12,8 @@ class PageController extends ContentController
protected function init()
{
parent::init();
$manager = new SupportedModulesManager();
$manager->getSupportedModules();
}
}
}
5 changes: 3 additions & 2 deletions app/src/Processors/BuildsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Processors;

use App\DataFetcher\Apis\GitHubApiConfig;
use App\DataFetcher\Misc\Consts;
use App\DataFetcher\Requesters\RestRequester;
use App\Misc\SupportedModulesManager;

class BuildsProcessor extends AbstractProcessor
{
Expand Down Expand Up @@ -44,7 +44,8 @@ public function getHtmlTableScript(): string

public function process(bool $refetch): array
{
$modules = Consts::MODULES;
$manager = new SupportedModulesManager();
$modules = $manager->getSupportedModules();

$apiConfig = new GitHubApiConfig();
$requester = new RestRequester($apiConfig);
Expand Down
5 changes: 3 additions & 2 deletions app/src/Processors/IssuesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use App\Utils\DateTimeUtil;
use App\Utils\MiscUtil;
use App\DataFetcher\Apis\GitHubApiConfig;
use App\DataFetcher\Misc\Consts;
use App\DataFetcher\Requesters\RestRequester;
use App\Misc\SupportedModulesManager;

class IssuesProcessor extends AbstractProcessor
{
Expand Down Expand Up @@ -47,7 +47,8 @@ public function process(bool $refetch): array
{
$apiConfig = new GitHubApiConfig();
$requester = new RestRequester($apiConfig);
$modules = Consts::MODULES;
$manager = new SupportedModulesManager();
$modules = $manager->getSupportedModules();

$rows = [];

Expand Down
5 changes: 3 additions & 2 deletions app/src/Processors/MergeUpsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace App\Processors;

use App\DataFetcher\Apis\GitHubApiConfig;
use App\DataFetcher\Misc\Consts;
use App\DataFetcher\Requesters\AbstractRequester;
use App\DataFetcher\Requesters\RestRequester;
use SilverStripe\SupportedModules\BranchLogic;
use SilverStripe\SupportedModules\MetaData;
use App\Misc\SupportedModulesManager;

class MergeUpsProcessor extends AbstractProcessor
{
Expand Down Expand Up @@ -64,7 +64,8 @@ public function process(bool $refetch): array
{
$apiConfig = new GitHubApiConfig();
$requester = new RestRequester($apiConfig);
$modules = Consts::MODULES;
$manager = new SupportedModulesManager();
$modules = $manager->getSupportedModules();

$repoList = [];
foreach (['regular', 'tooling'] as $moduleType) {
Expand Down
5 changes: 3 additions & 2 deletions app/src/Processors/OpenPrsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use App\Utils\MiscUtil;
use App\Utils\PullRequestUtil;
use App\DataFetcher\Apis\GitHubApiConfig;
use App\DataFetcher\Misc\Consts;
use App\DataFetcher\Misc\Logger;
use App\DataFetcher\Requesters\GraphQLRequester;
use stdClass;
use App\Misc\SupportedModulesManager;

class OpenPrsProcessor extends AbstractProcessor
{
Expand Down Expand Up @@ -50,7 +50,8 @@ public function process(bool $refetch): array
{
$apiConfig = new GitHubApiConfig();
$requester = new GraphQLRequester($apiConfig);
$modules = Consts::MODULES;
$manager = new SupportedModulesManager();
$modules = $manager->getSupportedModules();

$rows = [];

Expand Down
Loading

0 comments on commit 1918d01

Please sign in to comment.