diff --git a/controllers/dashboard.php b/controllers/dashboard.php index 8954302ddc42cf9c9406671197035e9cb2cef8e3..c4ede9c43ae512c39950fc78cc6621642547cfbe 100644 --- a/controllers/dashboard.php +++ b/controllers/dashboard.php @@ -104,7 +104,11 @@ final class DashboardController extends TracToGitlab\Controller }); return array_map(function ($issue) { - return new TracToGitlab\GitlabIssue($issue); + $mrs = []; + if ($issue['merge_requests_count'] > 0) { + $mrs = $this->gitlab->issues()->relatedMergeRequests($this->gitlabProjectId, $issue['iid']); + } + return new TracToGitlab\GitlabIssue($issue, $mrs); }, $issues); } diff --git a/lib/GitlabIssue.php b/lib/GitlabIssue.php index 0d72c60246b66ca688ed6efdf95251d24eb553a1..e87f1ca9956f9edbae39d06357b89d1c3b91af67 100644 --- a/lib/GitlabIssue.php +++ b/lib/GitlabIssue.php @@ -4,10 +4,12 @@ namespace TracToGitlab; final class GitlabIssue { private $issue; + private $mrs; - public function __construct(array $issue) + public function __construct(array $issue, array $mrs = []) { $this->issue = $issue; + $this->mrs = $mrs; } public function __get($offset) @@ -17,6 +19,7 @@ final class GitlabIssue return $assignee['username']; }, $this->issue['assignees'])); } + if ($offset === 'type') { if ($this->isBiest()) { return 'BIEST'; @@ -29,6 +32,7 @@ final class GitlabIssue } return '?'; } + return $this->issue[$offset] ?? null; } @@ -37,6 +41,19 @@ final class GitlabIssue return $this->issue['state'] !== 'opened'; } + public function hasMergeRequests(): bool + { + return $this->issue['merge_requests_count'] > 0; + } + + public function isMerged() + { + return $this->hasMergeRequests() + && count(array_filter($this->mrs, function ($mr) { + return $mr['state'] !== 'merged'; + })) === 0; + } + public function isBiest() { return in_array('BIEST', $this->issue['labels']); diff --git a/views/dashboard/index.php b/views/dashboard/index.php index 34066f81cd8de68cf9bcbabdb02f7cf43c99f068..32ef334f25e87451766efec4367545866682ec43 100644 --- a/views/dashboard/index.php +++ b/views/dashboard/index.php @@ -10,6 +10,7 @@ <th><?= _('Issue') ?></th> <th><?= _('Typ') ?></th> <th><?= _('Status') ?></th> + <th><?= _('MR') ?></th> <th><?= _('Titel') ?></th> <th><?= _('Autor') ?></th> <th><?= _('Bearbeiter') ?></th> @@ -25,7 +26,7 @@ <tbody> <? if (!$issues): ?> <tr> - <td colspan="<?= 6 + count($mapping) ?>" style="text-align: center"> + <td colspan="<?= 7 + count($mapping) ?>" style="text-align: center"> <?= _('Keine Issues für diesen Meilenstein und Typ') ?> </td> </tr> @@ -45,6 +46,21 @@ open <? endif; ?> </td> + <td> + <? if (!$issue->hasMergeRequests()): ?> + <abbr title="<?= _('Kein MR') ?>"> + <?= Icon::create('decline', Icon::ROLE_STATUS_RED) ?> + </abbr> + <? elseif ($issue->isMerged()): ?> + <abbr title="<?= _('MR bereits gemerget') ?>"> + <?= Icon::create('accept', Icon::ROLE_STATUS_GREEN) ?> + </abbr> + <? else: ?> + <abbr title="<?= _('MR noch nicht gemerget') ?>"> + <?= Icon::create('date', Icon::ROLE_STATUS_YELLOW) ?> + </abbr> + <? endif; ?> + </td> <td> <a href="<?= htmlReady($issue->web_url) ?>" target="_blank"> <?= htmlReady($issue->title) ?>