From 0cf9da927e37f639ed6b40366a81798b53861c9d Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 23 Feb 2022 19:31:08 +0000 Subject: [PATCH] [CodebergBridge] Fix bridge (#2464) --- bridges/CodebergBridge.php | 95 ++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/bridges/CodebergBridge.php b/bridges/CodebergBridge.php index 20aa2821..0d441740 100644 --- a/bridges/CodebergBridge.php +++ b/bridges/CodebergBridge.php @@ -205,6 +205,9 @@ class CodebergBridge extends BridgeAbstract { return $this->getInput('username') . '/' . $this->getInput('repo'); } + /** + * Extract commits + */ private function extractCommits($html) { $table = $html->find('table#commits-table', 0); $tbody = $table->find('tbody.commit-list', 0); @@ -231,25 +234,27 @@ class CodebergBridge extends BridgeAbstract { } } + /** + * Extract issues + */ private function extractIssues($html) { - $div = $html->find('div.repository', 0); + $div = $html->find('div.issue.list', 0); foreach ($div->find('li.item') as $li) { $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['uri'] = $li->find('a.title', 0)->href; - $item['timestamp'] = $li->find('p.desc', 0)->find('span', 0)->title; - $item['author'] = $li->find('p.desc', 0)->find('a', 0)->plaintext; + $item['timestamp'] = $li->find('span.time-since', 0)->title; + $item['author'] = $li->find('div.desc', 0)->find('a', 1)->plaintext; // Fetch issue page $issuePage = getSimpleHTMLDOMCached($item['uri'], 3600); - $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) { $item['categories'][] = $label->plaintext; @@ -259,20 +264,23 @@ class CodebergBridge extends BridgeAbstract { } } + /** + * Extract issue comments + */ private function extractIssueComments($html) { $this->issueTitle = $html->find('span#issue-title', 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(); if ($div->class === 'timeline-item comment merge box') { 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['content'] = $div->find('div.render-content.markdown', 0); + $item['content'] = $div->find('div.render-content.markup', 0); if ($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) { - $div = $html->find('div.repository', 0); + $div = $html->find('div.issue.list', 0); foreach ($div->find('li.item') as $li) { $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['uri'] = $li->find('a.title', 0)->href; - $item['timestamp'] = $li->find('p.desc', 0)->find('span', 0)->title; - $item['author'] = $li->find('p.desc', 0)->find('a', 0)->plaintext; + $item['timestamp'] = $li->find('span.time-since', 0)->title; + $item['author'] = $li->find('div.desc', 0)->find('a', 1)->plaintext; // Fetch pull request page $pullRequestPage = getSimpleHTMLDOMCached($item['uri'], 3600); - $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) { $item['categories'][] = $label->plaintext; @@ -313,49 +323,40 @@ class CodebergBridge extends BridgeAbstract { } } + /** + * Extract releases + */ private function extractReleases($html) { $ul = $html->find('ul#release-list', 0); foreach ($ul->find('li.ui.grid') as $li) { $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 - $item['title'] = $li->find('h3', 0)->plaintext; - $item['uri'] = $li->find('h3', 0)->find('a', 0)->href; + $tag = $this->stripSvg($li->find('span.tag', 0)); + $commit = $this->stripSvg($li->find('span.commit', 0)); + $downloads = $this->extractDownloads($li->find('details.download', 0)); - $tag = $li->find('span.tag', 0)->find('a', 0); - $commit = $li->find('span.commit', 0); - $downloads = $this->extractDownloads($li->find('div.download', 0)); - - $item['content'] = $li->find('div.markdown', 0); - $item['content'] .= <<find('div.markup.desc', 0); + $item['content'] .= <<Tag

{$tag}

Commit

{$commit}

{$downloads} 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['title'] = $li->find('h4', 0)->plaintext; - $item['uri'] = $li->find('h4', 0)->find('a', 0)->href; - - $item['content'] = <<Commit -

{$li->find('div.download', 0)->find('a', 0)}

-HTML; - - $item['content'] .= $this->extractDownloads($li->find('div.download', 0), true); - $item['timestamp'] = $li->find('span.time', 0)->find('span', 0)->title; - } + $item['timestamp'] = $li->find('span.time', 0)->find('span', 0)->title; + $item['author'] = $li->find('span.author', 0)->find('a', 0)->plaintext; $this->items[] = $item; } } + /** + * Extract downloads for a releases + */ private function extractDownloads($html, $skipFirst = false) { $downloads = ''; @@ -365,7 +366,7 @@ HTML; } $downloads .= << +{$a->plaintext}
HTML; } @@ -375,6 +376,9 @@ HTML; EOD; } + /** + * Ellipsis title to first 100 characters + */ private function ellipsisTitle($text) { $length = 100; @@ -384,4 +388,15 @@ EOD; } return $text; } + + /** + * Strip SVG tag + */ + private function stripSvg($html) { + if ($html->find('svg', 0)) { + $html->find('svg', 0)->outertext = ''; + } + + return $html; + } }