From ea2c571a851e19f98f421bbe59d92c56c1743c72 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+github@gmail.com>
Date: Mon, 8 Apr 2024 23:36:11 +0200
Subject: [PATCH] re #53

---
 controllers/dashboard.php     |  4 ++--
 controllers/labels.php        | 12 ++++++++----
 controllers/merge.php         |  2 +-
 controllers/mergerequests.php |  2 +-
 lib/GitlabController.php      |  9 +++++++--
 lib/Plugin.php                |  8 +-------
 6 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/controllers/dashboard.php b/controllers/dashboard.php
index c75a1ea..3e34583 100644
--- a/controllers/dashboard.php
+++ b/controllers/dashboard.php
@@ -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]
diff --git a/controllers/labels.php b/controllers/labels.php
index 8a9a52c..aa881d0 100644
--- a/controllers/labels.php
+++ b/controllers/labels.php
@@ -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;
     }
diff --git a/controllers/merge.php b/controllers/merge.php
index d2b6046..03634a0 100644
--- a/controllers/merge.php
+++ b/controllers/merge.php
@@ -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',
             [
diff --git a/controllers/mergerequests.php b/controllers/mergerequests.php
index 66985de..d70c8c9 100644
--- a/controllers/mergerequests.php
+++ b/controllers/mergerequests.php
@@ -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',
             [
diff --git a/lib/GitlabController.php b/lib/GitlabController.php
index a1275d7..db12e19 100644
--- a/lib/GitlabController.php
+++ b/lib/GitlabController.php
@@ -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);
     }
 }
diff --git a/lib/Plugin.php b/lib/Plugin.php
index 8badf74..7df73c2 100644
--- a/lib/Plugin.php
+++ b/lib/Plugin.php
@@ -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);
-- 
GitLab