mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[GitlabIssueBridge] Code cleanup (#2780)
- Rename parseMRDescription() -> parseMergeRequestDescription() - Move parseMergeRequestDescription() below parseIssueDescription() - Inline getProjectURI()
This commit is contained in:
parent
7256d1138b
commit
713d06ba08
@ -60,14 +60,10 @@ class GitlabIssueBridge extends BridgeAbstract {
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProjectURI() {
|
|
||||||
$host = $this->getInput('h') ?? 'gitlab.com';
|
|
||||||
return 'https://' . $host . '/' . $this->getInput('u') . '/'
|
|
||||||
. $this->getInput('p') . '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getURI() {
|
public function getURI() {
|
||||||
$uri = $this->getProjectURI();
|
$host = $this->getInput('h') ?? 'gitlab.com';
|
||||||
|
$uri = 'https://' . $host . '/' . $this->getInput('u') . '/'
|
||||||
|
. $this->getInput('p') . '/';
|
||||||
switch ($this->queriedContext) {
|
switch ($this->queriedContext) {
|
||||||
case 'Issue comments':
|
case 'Issue comments':
|
||||||
$uri .= '-/issues';
|
$uri .= '-/issues';
|
||||||
@ -92,7 +88,7 @@ class GitlabIssueBridge extends BridgeAbstract {
|
|||||||
$this->items[] = $this->parseIssueDescription();
|
$this->items[] = $this->parseIssueDescription();
|
||||||
break;
|
break;
|
||||||
case 'Merge Request comments':
|
case 'Merge Request comments':
|
||||||
$this->items[] = $this->parseMRDescription();
|
$this->items[] = $this->parseMergeRequestDescription();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -164,6 +160,26 @@ class GitlabIssueBridge extends BridgeAbstract {
|
|||||||
return $item;
|
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) {
|
private function fixImgSrc($html) {
|
||||||
if (is_string($html)) {
|
if (is_string($html)) {
|
||||||
$html = str_get_html($html);
|
$html = str_get_html($html);
|
||||||
@ -186,24 +202,4 @@ class GitlabIssueBridge extends BridgeAbstract {
|
|||||||
}
|
}
|
||||||
return defaultLinkTo($author_str, 'https://' . $this->getInput('h') . '/');
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user