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

Show merge infos

parent 3a60e043
No related branches found
No related tags found
1 merge request!4Show merge infos
...@@ -13,7 +13,6 @@ final class TracToGitlabPlugin extends StudIPPlugin implements StandardPlugin, S ...@@ -13,7 +13,6 @@ final class TracToGitlabPlugin extends StudIPPlugin implements StandardPlugin, S
return; return;
} }
$this->buildNavigation(); $this->buildNavigation();
} }
...@@ -120,6 +119,10 @@ final class TracToGitlabPlugin extends StudIPPlugin implements StandardPlugin, S ...@@ -120,6 +119,10 @@ final class TracToGitlabPlugin extends StudIPPlugin implements StandardPlugin, S
'translations', 'translations',
new Navigation(_('Übersetzungen'), PluginEngine::getURL($this, [], 'translations')) new Navigation(_('Übersetzungen'), PluginEngine::getURL($this, [], 'translations'))
); );
$navigation->addSubNavigation(
'merge',
new Navigation(_('Zu portierende Bugfixes'), PluginEngine::getURL($this, [], 'merge'))
);
Navigation::addItem('/gitlab-dashboard', $navigation); Navigation::addItem('/gitlab-dashboard', $navigation);
} }
......
...@@ -17,6 +17,7 @@ final class DashboardController extends TracToGitlab\Controller ...@@ -17,6 +17,7 @@ final class DashboardController extends TracToGitlab\Controller
Navigation::activateItem('/gitlab-dashboard/dashboard'); Navigation::activateItem('/gitlab-dashboard/dashboard');
PageLayout::setTitle(_('Übersicht der Issues in gitlab')); PageLayout::setTitle(_('Übersicht der Issues in gitlab'));
$this->activateNavigation('dashboard');
$this->setupSidebar(); $this->setupSidebar();
} }
...@@ -100,6 +101,7 @@ final class DashboardController extends TracToGitlab\Controller ...@@ -100,6 +101,7 @@ final class DashboardController extends TracToGitlab\Controller
usort($issues, function ($a, $b) { usort($issues, function ($a, $b) {
return $a['id'] - $b['id']; return $a['id'] - $b['id'];
}); });
return array_map(function ($issue) { return array_map(function ($issue) {
return new TracToGitlab\GitlabIssue($issue); return new TracToGitlab\GitlabIssue($issue);
}, $issues); }, $issues);
......
<?php
final class MergeController extends TracToGitlab\GitlabController
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
PageLayout::setTitle(_('Übersicht noch zu portierender Bugfixes'));
$this->activateNavigation('merge');
}
public function index_action()
{
$data = $this->readFromCache('issues-to-merge', true);
if ($data === false) {
$this->issues = $this->fetchIssues();
$this->writeToCache('issues-to-merge', $this->issues);
} else {
$this->issues = $data['data'];
Sidebar::get()->addWidget(new TemplateWidget(
'Aus dem Cache',
$this->get_template_factory()->open(
$this->get_default_template('sidebar'),
),
['time' => time()]
));
}
}
public function diff_action($mr_iid)
{
// $versions = $this->gitlab->mergeRequests()->
}
private function fetchIssues(): array
{
$issues = $this->gitlabPager->fetchAll(
$this->gitlab->issues(),
'all',
[
$this->gitlabProjectId,
[
'sort' => 'asc',
'scope' => 'all',
'milestone' => 'None',
'labels' => 'BIEST',
'state' => 'closed',
]
]
);
$issues = array_filter($issues, function ($issue) {
foreach (['worksforme', 'wontfix', 'Duplicate', 'invalid'] as $label) {
if (in_array($label, $issue['labels'])) {
return false;
}
}
$has_version = array_reduce($issue['labels'], function ($has_version, $label) {
return $has_version || strpos($label, 'Version::') === 0;
}, false);
return $has_version;
});
$issues = array_map(function ($issue) {
$issue['studip_version'] = $this->extractVersion($issue['labels']);
$issue['mr'] = $this->fetchRelatedMergeRequest($issue['iid']);
return $issue;
}, $issues);
usort($issues, function ($a, $b) {
return strcmp($b['studip_version'], $a['studip_version']);
});
return $issues;
}
private function fetchRelatedMergeRequest(int $issue_id)
{
$mrs = $this->gitlab->issues()->closedByMergeRequests(
$this->gitlabProjectId,
$issue_id
);
foreach ($mrs as $mr) {
if ($mr['state'] === 'merged') {
return $mr['iid'];
}
}
return null;
}
private function extractVersion(array $labels): string
{
$version = '';
foreach ($labels as $label) {
if (strpos($label, 'Version::') === 0) {
$v = substr($label, 9);
if (!$version || $v < $version) {
$version = $v;
}
}
}
return $version;
}
}
...@@ -20,4 +20,9 @@ abstract class Controller extends \PluginController ...@@ -20,4 +20,9 @@ abstract class Controller extends \PluginController
return $container[$offset]; return $container[$offset];
} }
protected function activateNavigation(string ...$path): void
{
\Navigation::activateItem('/gitlab-dashboard/' . implode('/', $path));
}
} }
<?php
namespace TracToGitlab;
use Gitlab\Api\AbstractApi;
abstract class GitlabController extends Controller
{
private $gitlabCache;
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$this->gitlabCache = \StudipCacheFactory::getCache();
}
protected function readFromCache(string $key, bool $raw = false)
{
$cached = $this->gitlabCache->read($key);
if (!$cached) {
return false;
}
$data = json_decode($cached, true);
return $raw ? $data : $data['data'];
}
protected function writeToCache(string $key, $data, $expire = 5 * 60)
{
$this->gitlabCache->write($key, json_encode([
'data' => $data,
'time' => time(),
]), $expire);
}
protected function getCachedDate(string $key)
{
$data = $this->readFromCache($key, true);
if ($data === false) {
return false;
}
return $data['time'] ?? false;
}
}
<?php
/**
* @var array<string, string> $mapping
* @var array<int, TracToGitlab\GitlabIssue> $issues
*/
?>
<table class="default"> <table class="default">
<thead> <thead>
<tr> <tr>
......
<?php
/**
* @var array<int, array> $issues
*/
?>
<table class="default">
<thead>
<tr>
<th><?= _('Issue') ?></th>
<th><?= _('Autor') ?></th>
<th><?= _('Bearbeiter') ?></th>
<th><?= _('Version') ?></th>
<!-- <th></th>-->
</tr>
</thead>
<tbody>
<? if (!$issues): ?>
<tr>
<td colspan="4" style="text-align: center">
<?= _('Keine portierbaren Bugfixes vorhanden 🥳🍺') ?>
</td>
</tr>
<? endif; ?>
<? foreach ($issues as $issue): ?>
<tr>
<td>
<a href="<?= htmlReady($issue['web_url']) ?>" target="_blank">
#<?= htmlReady($issue['iid']) ?>:
<?= htmlReady($issue['title']) ?>
</td>
<td><?= htmlReady($issue['author']['username']) ?></td>
<td><?= htmlReady(implode(',', array_column($issue['assignees'], 'username'))) ?></td>
<td><?= htmlReady($issue['studip_version']) ?></td>
<!-- <td>-->
<!-- --><?// if ($issue['mr']): ?>
<!-- <a href="--><?//= $controller->diff($issue['mr']) ?><!--" target="_blank">-->
<!-- --><?//= Icon::create('file-generic') ?>
<!-- </a>-->
<!-- --><?// endif; ?>
<!-- </td>-->
</tr>
<? endforeach; ?>
</tbody>
</table>
Zeitpunkt: <?= date('d.m.Y H:i:s', $time) ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment