From 713d06ba08b289e8e0fcf4f08e8ab1b8530037e7 Mon Sep 17 00:00:00 2001 From: Mynacol Date: Sun, 5 Jun 2022 18:39:54 +0200 Subject: [PATCH] [GitlabIssueBridge] Code cleanup (#2780) - Rename parseMRDescription() -> parseMergeRequestDescription() - Move parseMergeRequestDescription() below parseIssueDescription() - Inline getProjectURI() --- bridges/GitlabIssueBridge.php | 52 ++++++++++++++++------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/bridges/GitlabIssueBridge.php b/bridges/GitlabIssueBridge.php index caf94568..ce3ab08b 100644 --- a/bridges/GitlabIssueBridge.php +++ b/bridges/GitlabIssueBridge.php @@ -60,14 +60,10 @@ class GitlabIssueBridge extends BridgeAbstract { return $name; } - private function getProjectURI() { - $host = $this->getInput('h') ?? 'gitlab.com'; - return 'https://' . $host . '/' . $this->getInput('u') . '/' - . $this->getInput('p') . '/'; - } - public function getURI() { - $uri = $this->getProjectURI(); + $host = $this->getInput('h') ?? 'gitlab.com'; + $uri = 'https://' . $host . '/' . $this->getInput('u') . '/' + . $this->getInput('p') . '/'; switch ($this->queriedContext) { case 'Issue comments': $uri .= '-/issues'; @@ -92,7 +88,7 @@ class GitlabIssueBridge extends BridgeAbstract { $this->items[] = $this->parseIssueDescription(); break; case 'Merge Request comments': - $this->items[] = $this->parseMRDescription(); + $this->items[] = $this->parseMergeRequestDescription(); break; default: break; @@ -164,6 +160,26 @@ class GitlabIssueBridge extends BridgeAbstract { return $item; } + private function parseMergeRequestDescription() { + $description_uri = $this->getURI() . '/cached_widget.json'; + $description = getContents($description_uri); + $description = json_decode($description, false); + $description_html = getSimpleHtmlDomCached($this->getURI()); + + $item = array(); + $item['uri'] = $this->getURI(); + $item['uid'] = $item['uri']; + + $item['timestamp'] = $description_html->find('.merge-request-details time', 0)->datetime; + + $item['author'] = $this->parseAuthor($description_html); + + $item['title'] = 'Merge Request ' . $description->title; + $item['content'] = markdownToHtml($description->description); + + return $item; + } + private function fixImgSrc($html) { if (is_string($html)) { $html = str_get_html($html); @@ -186,24 +202,4 @@ class GitlabIssueBridge extends BridgeAbstract { } return defaultLinkTo($author_str, 'https://' . $this->getInput('h') . '/'); } - - private function parseMRDescription() { - $description_uri = $this->getURI() . '/cached_widget.json'; - $description = getContents($description_uri); - $description = json_decode($description, false); - $description_html = getSimpleHtmlDomCached($this->getURI()); - - $item = array(); - $item['uri'] = $this->getURI(); - $item['uid'] = $item['uri']; - - $item['timestamp'] = $description_html->find('.merge-request-details time', 0)->datetime; - - $item['author'] = $this->parseAuthor($description_html); - - $item['title'] = 'Merge Request ' . $description->title; - $item['content'] = markdownToHtml($description->description); - - return $item; - } }