mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-29 06:38:51 +03:00
[CodebergBridge] Fix bridge (#2464)
This commit is contained in:
parent
73a5dd928a
commit
0cf9da927e
1 changed files with 55 additions and 40 deletions
|
@ -205,6 +205,9 @@ class CodebergBridge extends BridgeAbstract {
|
||||||
return $this->getInput('username') . '/' . $this->getInput('repo');
|
return $this->getInput('username') . '/' . $this->getInput('repo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract commits
|
||||||
|
*/
|
||||||
private function extractCommits($html) {
|
private function extractCommits($html) {
|
||||||
$table = $html->find('table#commits-table', 0);
|
$table = $html->find('table#commits-table', 0);
|
||||||
$tbody = $table->find('tbody.commit-list', 0);
|
$tbody = $table->find('tbody.commit-list', 0);
|
||||||
|
@ -231,25 +234,27 @@ class CodebergBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract issues
|
||||||
|
*/
|
||||||
private function extractIssues($html) {
|
private function extractIssues($html) {
|
||||||
$div = $html->find('div.repository', 0);
|
$div = $html->find('div.issue.list', 0);
|
||||||
|
|
||||||
foreach ($div->find('li.item') as $li) {
|
foreach ($div->find('li.item') as $li) {
|
||||||
$item = array();
|
$item = array();
|
||||||
|
|
||||||
$number = $li->find('div', 0)->plaintext;
|
$number = trim($li->find('a.index,ml-0.mr-2', 0)->plaintext);
|
||||||
|
|
||||||
$item['title'] = $li->find('a.title', 0)->plaintext . ' (' . $number . ')';
|
$item['title'] = $li->find('a.title', 0)->plaintext . ' (' . $number . ')';
|
||||||
$item['uri'] = $li->find('a.title', 0)->href;
|
$item['uri'] = $li->find('a.title', 0)->href;
|
||||||
$item['timestamp'] = $li->find('p.desc', 0)->find('span', 0)->title;
|
$item['timestamp'] = $li->find('span.time-since', 0)->title;
|
||||||
$item['author'] = $li->find('p.desc', 0)->find('a', 0)->plaintext;
|
$item['author'] = $li->find('div.desc', 0)->find('a', 1)->plaintext;
|
||||||
|
|
||||||
// Fetch issue page
|
// Fetch issue page
|
||||||
$issuePage = getSimpleHTMLDOMCached($item['uri'], 3600);
|
$issuePage = getSimpleHTMLDOMCached($item['uri'], 3600);
|
||||||
|
|
||||||
$issuePage = defaultLinkTo($issuePage, self::URI);
|
$issuePage = defaultLinkTo($issuePage, self::URI);
|
||||||
|
|
||||||
$item['content'] = $issuePage->find('ui.timeline', 0)->find('div.render-content.markdown', 0);
|
$item['content'] = $issuePage->find('div.timeline-item.comment.first', 0)->find('div.render-content.markup', 0);
|
||||||
|
|
||||||
foreach ($li->find('a.ui.label') as $label) {
|
foreach ($li->find('a.ui.label') as $label) {
|
||||||
$item['categories'][] = $label->plaintext;
|
$item['categories'][] = $label->plaintext;
|
||||||
|
@ -259,20 +264,23 @@ class CodebergBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract issue comments
|
||||||
|
*/
|
||||||
private function extractIssueComments($html) {
|
private function extractIssueComments($html) {
|
||||||
$this->issueTitle = $html->find('span#issue-title', 0)->plaintext
|
$this->issueTitle = $html->find('span#issue-title', 0)->plaintext
|
||||||
. ' (' . $html->find('span.index', 0)->plaintext . ')';
|
. ' (' . $html->find('span.index', 0)->plaintext . ')';
|
||||||
|
|
||||||
foreach ($html->find('ui.timeline > div.timeline-item.comment') as $div) {
|
foreach ($html->find('div.timeline-item.comment') as $div) {
|
||||||
$item = array();
|
$item = array();
|
||||||
|
|
||||||
if ($div->class === 'timeline-item comment merge box') {
|
if ($div->class === 'timeline-item comment merge box') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['title'] = $this->ellipsisTitle($div->find('div.render-content.markdown', 0)->plaintext);
|
$item['title'] = $this->ellipsisTitle($div->find('div.render-content.markup', 0)->plaintext);
|
||||||
$item['uri'] = $div->find('span.text.grey', 0)->find('a', 1)->href;
|
$item['uri'] = $div->find('span.text.grey', 0)->find('a', 1)->href;
|
||||||
$item['content'] = $div->find('div.render-content.markdown', 0);
|
$item['content'] = $div->find('div.render-content.markup', 0);
|
||||||
|
|
||||||
if ($div->find('div.dropzone-attachments', 0)) {
|
if ($div->find('div.dropzone-attachments', 0)) {
|
||||||
$item['content'] .= $div->find('div.dropzone-attachments', 0);
|
$item['content'] .= $div->find('div.dropzone-attachments', 0);
|
||||||
|
@ -285,25 +293,27 @@ class CodebergBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract pulls
|
||||||
|
*/
|
||||||
private function extractPulls($html) {
|
private function extractPulls($html) {
|
||||||
$div = $html->find('div.repository', 0);
|
$div = $html->find('div.issue.list', 0);
|
||||||
|
|
||||||
foreach ($div->find('li.item') as $li) {
|
foreach ($div->find('li.item') as $li) {
|
||||||
$item = array();
|
$item = array();
|
||||||
|
|
||||||
$number = $li->find('div', 0)->plaintext;
|
$number = trim($li->find('a.index,ml-0.mr-2', 0)->plaintext);
|
||||||
|
|
||||||
$item['title'] = $li->find('a.title', 0)->plaintext . ' (' . $number . ')';
|
$item['title'] = $li->find('a.title', 0)->plaintext . ' (' . $number . ')';
|
||||||
$item['uri'] = $li->find('a.title', 0)->href;
|
$item['uri'] = $li->find('a.title', 0)->href;
|
||||||
$item['timestamp'] = $li->find('p.desc', 0)->find('span', 0)->title;
|
$item['timestamp'] = $li->find('span.time-since', 0)->title;
|
||||||
$item['author'] = $li->find('p.desc', 0)->find('a', 0)->plaintext;
|
$item['author'] = $li->find('div.desc', 0)->find('a', 1)->plaintext;
|
||||||
|
|
||||||
// Fetch pull request page
|
// Fetch pull request page
|
||||||
$pullRequestPage = getSimpleHTMLDOMCached($item['uri'], 3600);
|
$pullRequestPage = getSimpleHTMLDOMCached($item['uri'], 3600);
|
||||||
|
|
||||||
$pullRequestPage = defaultLinkTo($pullRequestPage, self::URI);
|
$pullRequestPage = defaultLinkTo($pullRequestPage, self::URI);
|
||||||
|
|
||||||
$item['content'] = $pullRequestPage->find('ui.timeline', 0)->find('div.render-content.markdown', 0);
|
$item['content'] = $pullRequestPage->find('ui.timeline', 0)->find('div.render-content.markup', 0);
|
||||||
|
|
||||||
foreach ($li->find('a.ui.label') as $label) {
|
foreach ($li->find('a.ui.label') as $label) {
|
||||||
$item['categories'][] = $label->plaintext;
|
$item['categories'][] = $label->plaintext;
|
||||||
|
@ -313,49 +323,40 @@ class CodebergBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract releases
|
||||||
|
*/
|
||||||
private function extractReleases($html) {
|
private function extractReleases($html) {
|
||||||
$ul = $html->find('ul#release-list', 0);
|
$ul = $html->find('ul#release-list', 0);
|
||||||
|
|
||||||
foreach ($ul->find('li.ui.grid') as $li) {
|
foreach ($ul->find('li.ui.grid') as $li) {
|
||||||
$item = array();
|
$item = array();
|
||||||
|
$item['title'] = $li->find('h4', 0)->plaintext;
|
||||||
|
$item['uri'] = $li->find('h4', 0)->find('a', 0)->href;
|
||||||
|
|
||||||
if ($li->find('h3', 0)) { // Release
|
$tag = $this->stripSvg($li->find('span.tag', 0));
|
||||||
$item['title'] = $li->find('h3', 0)->plaintext;
|
$commit = $this->stripSvg($li->find('span.commit', 0));
|
||||||
$item['uri'] = $li->find('h3', 0)->find('a', 0)->href;
|
$downloads = $this->extractDownloads($li->find('details.download', 0));
|
||||||
|
|
||||||
$tag = $li->find('span.tag', 0)->find('a', 0);
|
$item['content'] = $li->find('div.markup.desc', 0);
|
||||||
$commit = $li->find('span.commit', 0);
|
$item['content'] .= <<<HTML
|
||||||
$downloads = $this->extractDownloads($li->find('div.download', 0));
|
|
||||||
|
|
||||||
$item['content'] = $li->find('div.markdown', 0);
|
|
||||||
$item['content'] .= <<<HTML
|
|
||||||
<strong>Tag</strong>
|
<strong>Tag</strong>
|
||||||
<p>{$tag}</p>
|
<p>{$tag}</p>
|
||||||
<strong>Commit</strong>
|
<strong>Commit</strong>
|
||||||
<p>{$commit}</p>
|
<p>{$commit}</p>
|
||||||
{$downloads}
|
{$downloads}
|
||||||
HTML;
|
HTML;
|
||||||
$item['timestamp'] = $li->find('span.time', 0)->find('span', 0)->title;
|
|
||||||
$item['author'] = $li->find('span.author', 0)->find('a', 0)->plaintext;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($li->find('h4', 0)) { // Tag
|
$item['timestamp'] = $li->find('span.time', 0)->find('span', 0)->title;
|
||||||
$item['title'] = $li->find('h4', 0)->plaintext;
|
$item['author'] = $li->find('span.author', 0)->find('a', 0)->plaintext;
|
||||||
$item['uri'] = $li->find('h4', 0)->find('a', 0)->href;
|
|
||||||
|
|
||||||
$item['content'] = <<<HTML
|
|
||||||
<strong>Commit</strong>
|
|
||||||
<p>{$li->find('div.download', 0)->find('a', 0)}</p>
|
|
||||||
HTML;
|
|
||||||
|
|
||||||
$item['content'] .= $this->extractDownloads($li->find('div.download', 0), true);
|
|
||||||
$item['timestamp'] = $li->find('span.time', 0)->find('span', 0)->title;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract downloads for a releases
|
||||||
|
*/
|
||||||
private function extractDownloads($html, $skipFirst = false) {
|
private function extractDownloads($html, $skipFirst = false) {
|
||||||
$downloads = '';
|
$downloads = '';
|
||||||
|
|
||||||
|
@ -365,7 +366,7 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
$downloads .= <<<HTML
|
$downloads .= <<<HTML
|
||||||
{$a}<br>
|
<a href="{$a->herf}">{$a->plaintext}</a><br>
|
||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,6 +376,9 @@ HTML;
|
||||||
EOD;
|
EOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ellipsis title to first 100 characters
|
||||||
|
*/
|
||||||
private function ellipsisTitle($text) {
|
private function ellipsisTitle($text) {
|
||||||
$length = 100;
|
$length = 100;
|
||||||
|
|
||||||
|
@ -384,4 +388,15 @@ EOD;
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip SVG tag
|
||||||
|
*/
|
||||||
|
private function stripSvg($html) {
|
||||||
|
if ($html->find('svg', 0)) {
|
||||||
|
$html->find('svg', 0)->outertext = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue