Skip to content
Snippets Groups Projects
Commit ea2c571a authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

re #53

parent 0e43b3b6
No related branches found
No related tags found
No related merge requests found
......@@ -126,7 +126,7 @@ final class DashboardController extends TracToGitlab\GitlabController
foreach (explode(',', $this->getSelected('types')) as $type) {
$issues = array_merge(
$issues,
$this->result_pager->fetchAll(
$this->fetchAll(
$this->gitlab->issues(),
'all',
[
......@@ -157,7 +157,7 @@ final class DashboardController extends TracToGitlab\GitlabController
private function getMilestones()
{
return $this->cached('milestones', function () {
$milestones = $this->result_pager->fetchAll(
$milestones = $this->fetchAll(
$this->gitlab->milestones(),
'all',
[Config::get()->TRAC2GITLAB_GITLAB_PROJECT_ID]
......
......@@ -12,11 +12,17 @@ final class LabelsController extends \TracToGitlab\GitlabController
public function index_action()
{
$this->labels = $this->cached('labels', fn() => $this->fetchLabels());
Sidebar::get()->addWidget(new TemplateWidget(
_('Stand der Daten'),
$this->get_template_factory()->open('sidebar'),
['time' => $this->getCachedDate('labels')]
));
}
private function fetchLabels(): array
{
$labels = $this->result_pager->fetchAll(
$labels = $this->fetchAll(
$this->gitlab->projects(),
'labels',
[
......@@ -25,9 +31,7 @@ final class LabelsController extends \TracToGitlab\GitlabController
]
);
usort($labels, function (array $a, array $b) {
return strnatcasecmp($a['name'], $b['name']);
});
usort($labels, fn(array $a, array $b) => strnatcasecmp($a['name'], $b['name']));
return $labels;
}
......
......@@ -22,7 +22,7 @@ final class MergeController extends TracToGitlab\GitlabController
private function fetchIssues(): array
{
$issues = $this->result_pager->fetchAll(
$issues = $this->fetchAll(
$this->gitlab->issues(),
'all',
[
......
......@@ -22,7 +22,7 @@ final class MergerequestsController extends TracToGitlab\GitlabController
private function fetchMergeRequests(): array
{
$mrs = $this->result_pager->fetchAll(
$mrs = $this->fetchAll(
$this->gitlab->mergeRequests(),
'all',
[
......
......@@ -3,6 +3,7 @@ namespace TracToGitlab;
use Config;
use Gitlab;
use Gitlab\Api\AbstractApi;
use TracToGitlab\Traits\Cached;
abstract class GitlabController extends Controller
......@@ -11,7 +12,6 @@ abstract class GitlabController extends Controller
protected int $gitlab_project_id;
protected Gitlab\Client $gitlab;
protected Gitlab\ResultPager $result_pager;
public function before_filter(&$action, &$args)
{
......@@ -21,6 +21,11 @@ abstract class GitlabController extends Controller
$this->gitlab_project_id = Config::get()->TRAC2GITLAB_GITLAB_PROJECT_ID;
$this->gitlab = app(Gitlab\Client::class);
$this->result_pager = app(Gitlab\ResultPager::class);
}
protected function fetchAll(AbstractApi $api, string $method, array $parameters = []): array
{
$pager = new \Gitlab\ResultPager($this->gitlab, 100);
return $pager->fetchAll($api, $method, $parameters);
}
}
......@@ -3,7 +3,7 @@ namespace TracToGitlab;
use Config;
use Gitlab;
use Pimple;
use Parsedown;
use Psr\Http\Client\ClientInterface;
use Studip\DIContainer;
......@@ -18,9 +18,6 @@ abstract class Plugin extends \StudIPPlugin
$container->set(ClientInterface::class, function () {
return new \GuzzleHttp\Client();
});
$container->set(TracLookup::class, function () {
return new TracLookup(Config::get()->TRAC2GITLAB_TRAC_URL);
});
$container->set(Gitlab\Client::class, function (ClientInterface $client) {
$builder = new Gitlab\HttpClient\Builder(
$client,
......@@ -34,9 +31,6 @@ abstract class Plugin extends \StudIPPlugin
$client->authenticate(Config::get()->TRAC2GITLAB_GITLAB_TOKEN, Gitlab\Client::AUTH_HTTP_TOKEN);
return $client;
});
$container->set(Gitlab\ResultPager::class, function (Gitlab\Client $client) {
return new Gitlab\ResultPager($client);
});
$container->set(Parsedown::class, function () {
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment