[GithubIssueBridge] Include issue author comment in the feed
- Add function to build an URL to the GitHub issue comment - Change scope of internal functions from protected to private - Use IDs instead of classes as comment selectors, to include the issue author in the output feed. References #1100
This commit is contained in:
parent
ba116d9ab6
commit
da339fd5cc
1 changed files with 35 additions and 17 deletions
|
@ -66,10 +66,21 @@ class GithubIssueBridge extends BridgeAbstract {
|
||||||
return parent::getURI();
|
return parent::getURI();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function extractIssueEvent($issueNbr, $title, $comment){
|
private function buildGitHubIssueCommentUri($issue_number, $comment_id) {
|
||||||
$comment = $comment->firstChild();
|
// https://github.com/<user>/<project>/issues/<issue-number>#<id>
|
||||||
$uri = static::URI . $this->getInput('u') . '/' . $this->getInput('p')
|
return static::URI
|
||||||
. '/issues/' . $issueNbr . '#' . $comment->getAttribute('id');
|
. $this->getInput('u')
|
||||||
|
. '/'
|
||||||
|
. $this->getInput('p')
|
||||||
|
. '/issues/'
|
||||||
|
. $issue_number
|
||||||
|
. '#'
|
||||||
|
. $comment_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function extractIssueEvent($issueNbr, $title, $comment){
|
||||||
|
|
||||||
|
$uri = buildGitHubIssueCommentUri($issueNbr, $comment->getAttribute('id'));
|
||||||
|
|
||||||
$author = $comment->find('.author', 0)->plaintext;
|
$author = $comment->find('.author', 0)->plaintext;
|
||||||
|
|
||||||
|
@ -94,22 +105,21 @@ class GithubIssueBridge extends BridgeAbstract {
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function extractIssueComment($issueNbr, $title, $comment){
|
private function extractIssueComment($issueNbr, $title, $comment){
|
||||||
$uri = static::URI . $this->getInput('u') . '/'
|
|
||||||
. $this->getInput('p') . '/issues/' . $issueNbr;
|
$uri = buildGitHubIssueCommentUri($issueNbr, $comment->id);
|
||||||
|
|
||||||
$author = $comment->find('.author', 0)->plaintext;
|
$author = $comment->find('.author', 0)->plaintext;
|
||||||
|
|
||||||
$title .= ' / ' . trim(
|
$title .= ' / ' . trim(
|
||||||
$comment->find('.comment .timeline-comment-header-text', 0)->plaintext
|
$comment->find('.timeline-comment-header-text', 0)->plaintext
|
||||||
);
|
);
|
||||||
|
|
||||||
$content = $comment->find('.comment-body', 0)->innertext;
|
$content = $comment->find('.comment-body', 0)->innertext;
|
||||||
|
|
||||||
$item = array();
|
$item = array();
|
||||||
$item['author'] = $author;
|
$item['author'] = $author;
|
||||||
$item['uri'] = $uri
|
$item['uri'] = $uri;
|
||||||
. '#' . $comment->firstChild()->nextSibling()->getAttribute('id');
|
|
||||||
$item['title'] = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
|
$item['title'] = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
|
||||||
$item['timestamp'] = strtotime(
|
$item['timestamp'] = strtotime(
|
||||||
$comment->find('relative-time', 0)->getAttribute('datetime')
|
$comment->find('relative-time', 0)->getAttribute('datetime')
|
||||||
|
@ -118,25 +128,32 @@ class GithubIssueBridge extends BridgeAbstract {
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function extractIssueComments($issue){
|
private function extractIssueComments($issue){
|
||||||
$items = array();
|
$items = array();
|
||||||
$title = $issue->find('.gh-header-title', 0)->plaintext;
|
$title = $issue->find('.gh-header-title', 0)->plaintext;
|
||||||
$issueNbr = trim(
|
$issueNbr = trim(
|
||||||
substr($issue->find('.gh-header-number', 0)->plaintext, 1)
|
substr($issue->find('.gh-header-number', 0)->plaintext, 1)
|
||||||
);
|
);
|
||||||
$comments = $issue->find('.js-discussion', 0);
|
|
||||||
foreach($comments->children() as $comment) {
|
$comments = $issue->find('
|
||||||
|
[id^="issue-"] > .comment,
|
||||||
|
[id^="issuecomment-"] > .comment,
|
||||||
|
[id^="event-"],
|
||||||
|
[id^="ref-"]
|
||||||
|
');
|
||||||
|
foreach($comments as $comment) {
|
||||||
|
|
||||||
if (!$comment->hasChildNodes()) {
|
if (!$comment->hasChildNodes()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$comment = $comment->firstChild();
|
|
||||||
$classes = explode(' ', $comment->getAttribute('class'));
|
if (!$comment->hasClass('discussion-item-header')) {
|
||||||
if (in_array('timeline-comment-wrapper', $classes)) {
|
|
||||||
$item = $this->extractIssueComment($issueNbr, $title, $comment);
|
$item = $this->extractIssueComment($issueNbr, $title, $comment);
|
||||||
$items[] = $item;
|
$items[] = $item;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while (in_array('discussion-item', $classes)) {
|
|
||||||
|
while ($comment->hasClass('discussion-item-header')) {
|
||||||
$item = $this->extractIssueEvent($issueNbr, $title, $comment);
|
$item = $this->extractIssueEvent($issueNbr, $title, $comment);
|
||||||
$items[] = $item;
|
$items[] = $item;
|
||||||
$comment = $comment->nextSibling();
|
$comment = $comment->nextSibling();
|
||||||
|
@ -145,6 +162,7 @@ class GithubIssueBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
$classes = explode(' ', $comment->getAttribute('class'));
|
$classes = explode(' ', $comment->getAttribute('class'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue