1
0

Added fetchLimit overrides to EGG
All checks were successful
Build Docker and Deploy / Build Docker (push) Successful in 18s
Build Docker and Deploy / Deploy to Server (push) Successful in 17s

This commit is contained in:
2025-12-15 12:14:42 +01:00
parent e818013438
commit fcc10e1d70
8 changed files with 69 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
<?php
require_once 'IConfigSource.php';
require_once 'Logger.php';
require_once 'EGGException.php';
require_once 'RemoteSource.php';
@@ -9,7 +10,7 @@ require_once 'OutputGenerator.php';
require_once 'EGGDatabase.php';
require_once 'Utils.php';
class ExtendedGitGraph2 implements ILogger
class ExtendedGitGraph2 implements ILogger, IConfigSource
{
/** @var ILogger[] **/
private $logger;
@@ -23,6 +24,11 @@ class ExtendedGitGraph2 implements ILogger
/** @var EGGDatabase **/
private $db;
public int $fetchLimitCommits = 1024;
public int $fetchLimitBranches = 64;
public int $fetchLimitRepos = 64;
public int $fetchLimitOrgs = 64;
/**
* @param array $config
* @throws Exception
@@ -35,6 +41,11 @@ class ExtendedGitGraph2 implements ILogger
if ($config['output_logfile']) $this->logger []= new FileLogger($config['logfile'], $config['logfile_count']);
if ($config['output_file']) $this->logger []= new SingleFileLogger($config['output_filepath']);
if (isset($config['fetchlimit_commits'])) $this->fetchLimitCommits = intval($config['fetchlimit_commits']);
if (isset($config['fetchlimit_branches'])) $this->fetchLimitBranches = intval($config['fetchlimit_branches']);
if (isset($config['fetchlimit_repos'])) $this->fetchLimitRepos = intval($config['fetchlimit_repos']);
if (isset($config['fetchlimit_orgs'])) $this->fetchLimitOrgs = intval($config['fetchlimit_orgs']);
$this->sources = [];
$sourcenames = [];
@@ -42,9 +53,9 @@ class ExtendedGitGraph2 implements ILogger
{
$newsrc = null;
if ($rmt['type'] === 'github')
$newsrc = new GithubConnection($this, $rmt['name'], $rmt['url'], $rmt['filter'], $rmt['exclusions'], $rmt['oauth_id'], $rmt['oauth_secret'], $rmt['token_cache'] );
$newsrc = new GithubConnection($this, $this, $rmt['name'], $rmt['url'], $rmt['filter'], $rmt['exclusions'], $rmt['oauth_id'], $rmt['oauth_secret'], $rmt['token_cache'] );
else if ($rmt['type'] === 'gitea')
$newsrc = new GiteaConnection($this, $rmt['name'], $rmt['url'], $rmt['filter'], $rmt['exclusions'], $rmt['username'], $rmt['password'] );
$newsrc = new GiteaConnection($this, $this, $rmt['name'], $rmt['url'], $rmt['filter'], $rmt['exclusions'], $rmt['username'], $rmt['password'] );
else
throw new EGGException("Unknown remote-type: " . $rmt['type']);
@@ -59,6 +70,11 @@ class ExtendedGitGraph2 implements ILogger
$this->outputter = new FullRenderer($this, $config['identities'], $config['output_cache_files']);
}
public function getFetchLimitCommits(): int { return $this->fetchLimitCommits; }
public function getFetchLimitBranches(): int { return $this->fetchLimitBranches; }
public function getFetchLimitRepos(): int { return $this->fetchLimitRepos; }
public function getFetchLimitOrgs(): int { return $this->fetchLimitOrgs; }
public function update()
{
try

9
www/extern/egg/IConfigSource.php vendored Normal file
View File

@@ -0,0 +1,9 @@
<?php
interface IConfigSource
{
public function getFetchLimitCommits(): int;
public function getFetchLimitBranches(): int;
public function getFetchLimitRepos(): int;
public function getFetchLimitOrgs(): int;
}

View File

@@ -1,5 +1,6 @@
<?php
require_once 'IConfigSource.php';
require_once 'Utils.php';
require_once 'EGGDatabase.php';
@@ -21,6 +22,9 @@ abstract class StandardGitConnection implements IRemoteSource
/** @var ILogger $logger */
protected $logger;
/** @var IConfigSource $cfgSource */
protected $cfgSource;
/** @var string $name */
protected $name;
@@ -32,13 +36,15 @@ abstract class StandardGitConnection implements IRemoteSource
/**
* @param ILogger $logger
* @param IConfigSource $cfg
* @param string $name
* @param string $filter
* @param string[] exclusions
*/
public function __construct(ILogger $logger, string $name, string $filter, array $exclusions)
public function __construct(ILogger $logger, IConfigSource $cfg, string $name, string $filter, array $exclusions)
{
$this->logger = $logger;
$this->cfgSource = $cfg;
$this->name = $name;
$this->filter = $filter;
$this->exclusions = $exclusions;

View File

@@ -1,5 +1,6 @@
<?php
require_once 'IConfigSource.php';
require_once 'Utils.php';
require_once 'EGGDatabase.php';
require_once 'RemoteSource.php';
@@ -31,9 +32,9 @@ class GiteaConnection extends StandardGitConnection
* @param string $username
* @param string $password
*/
public function __construct(ILogger $logger, string $name, string $url, string $filter, array $exclusions, string $username, string $password)
public function __construct(ILogger $logger, IConfigSource $cfg, string $name, string $url, string $filter, array $exclusions, string $username, string $password)
{
parent::__construct($logger, $name, $filter, $exclusions);
parent::__construct($logger, $cfg, $name, $filter, $exclusions);
$this->url = $url;
$this->username = $username;
@@ -55,28 +56,28 @@ class GiteaConnection extends StandardGitConnection
/** @inheritDoc */
protected function queryOrganizations($page)
{
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_USER_ORG_LIST), ['page'=>$page, 'limit'=>64 ]);
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_USER_ORG_LIST), ['page'=>$page, 'limit'=>$this->cfgSource->getFetchLimitOrgs() ]);
return Utils::getJSONWithTokenBasicAuth($this->logger, $url, $this->username, $this->password);
}
/** @inheritDoc */
protected function queryRepositories($user, $page)
{
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_USER_REPO_LIST), ['user'=>$user, 'page'=>$page, 'limit'=>64 ]);
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_USER_REPO_LIST), ['user'=>$user, 'page'=>$page, 'limit'=>$this->cfgSource->getFetchLimitRepos() ]);
return Utils::getJSONWithTokenBasicAuth($this->logger, $url, $this->username, $this->password);
}
/** @inheritDoc */
protected function queryBranches($reponame, $page)
{
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_BRANCH_LIST), ['repo'=>$reponame, 'page'=>$page, 'limit'=>64]);
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_BRANCH_LIST), ['repo'=>$reponame, 'page'=>$page, 'limit'=>$this->cfgSource->getFetchLimitBranches()]);
return Utils::getJSONWithTokenBasicAuth($this->logger, $url, $this->username, $this->password);
}
/** @inheritDoc */
protected function queryCommits($reponame, $branchname, $startsha)
{
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_COMMIT_LIST), [ 'repo'=>$reponame, 'sha'=>$startsha, 'limit'=>1024 ]);
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_COMMIT_LIST), [ 'repo'=>$reponame, 'sha'=>$startsha, 'limit'=>$this->cfgSource->getFetchLimitCommits() ]);
return Utils::getJSONWithTokenBasicAuth($this->logger, $url, $this->username, $this->password);
}

View File

@@ -1,5 +1,6 @@
<?php
require_once 'IConfigSource.php';
require_once 'Utils.php';
require_once 'EGGDatabase.php';
require_once 'RemoteSource.php';
@@ -39,9 +40,9 @@ class GithubConnection extends StandardGitConnection
* @param string $oauth_secret
* @param string $apitokenpath
*/
public function __construct(ILogger $logger, string $name, string $url, string $filter, array $exclusions, string $oauth_id, string $oauth_secret, string $apitokenpath)
public function __construct(ILogger $logger, IConfigSource $cfg, string $name, string $url, string $filter, array $exclusions, string $oauth_id, string $oauth_secret, string $apitokenpath)
{
parent::__construct($logger, $name, $filter, $exclusions);
parent::__construct($logger, $cfg, $name, $filter, $exclusions);
$this->url = $url;
$this->oauth_id = $oauth_id;
@@ -95,21 +96,21 @@ class GithubConnection extends StandardGitConnection
/** @inheritDoc */
protected function queryRepositories($user, $page)
{
$url = Utils::sharpFormat(self::API_REPOSITORIESLIST, ['user'=>$user, 'page'=>$page]);
$url = Utils::sharpFormat(self::API_REPOSITORIESLIST, ['user'=>$user, 'page'=>$page, 'per_page'=>$this->cfgSource->getFetchLimitRepos() ]);
return Utils::getJSONWithTokenAuth($this->logger, $url, $this->apitoken);
}
/** @inheritDoc */
protected function queryBranches($reponame, $page)
{
$url = Utils::sharpFormat(self::API_BRANCHLIST, ['repo'=>$reponame, 'page'=>$page]);
$url = Utils::sharpFormat(self::API_BRANCHLIST, ['repo'=>$reponame, 'page'=>$page, 'per_page'=>$this->cfgSource->getFetchLimitBranches() ]);
return Utils::getJSONWithTokenAuth($this->logger, $url, $this->apitoken);
}
/** @inheritDoc */
protected function queryCommits($reponame, $branchname, $startsha)
{
$url = Utils::sharpFormat(self::API_COMMITSLIST, [ 'repo'=>$reponame, 'sha'=>$startsha ]);
$url = Utils::sharpFormat(self::API_COMMITSLIST, [ 'repo'=>$reponame, 'sha'=>$startsha, 'per_page'=>$this->cfgSource->getFetchLimitCommits() ]);
return Utils::getJSONWithTokenAuth($this->logger, $url, $this->apitoken);
}

View File

@@ -14,6 +14,11 @@ class MikescherGitGraph implements IWebsiteModule
$this->extgitgraph = new ExtendedGitGraph2($egh_conf);
}
public function setFetchLimitCommits(int $flo)
{
$this->extgitgraph->fetchLimitCommits = $flo;
}
public function getPathRenderedData(): string
{
return __DIR__ . '/../../dynamic/egg/cache_fullrenderer.html';

View File

@@ -21,10 +21,18 @@ try {
$config['output_file'] = false;
$config['output_stdout'] = true;
echo "ENV:\n" . print_r($_ENV, true) . "\n";
require_once __DIR__ .'/../internals/modules/mikeschergitgraph.php';
$egg = new MikescherGitGraph($config);
if (getenv('EGG_FETCHLIMITCOMMITS')) {
$v = intval(getenv('EGG_FETCHLIMITCOMMITS'));
$egg->setFetchLimitCommits($v);
echo "[*] EGG_FETCHLIMITCOMMITS override detected: $v\n";}
echo "\n";
echo "================================ Start Update ================================\n";
echo "\n";