forked from blallo/rss-bridge
Merge branch 'GithubIssuesBridge' of https://framagit.org/peetah/rss-bridge
This commit is contained in:
commit
99a416ebad
1 changed files with 33 additions and 20 deletions
|
@ -1,19 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* GithubIssueBridge
|
|
||||||
*
|
|
||||||
* @name GithubIssue Bridge
|
|
||||||
* @description Returns the comments of a github project issue
|
|
||||||
*/
|
|
||||||
class GithubIssueBridge extends BridgeAbstract{
|
class GithubIssueBridge extends BridgeAbstract{
|
||||||
public function loadMetadatas() {
|
public function loadMetadatas() {
|
||||||
|
|
||||||
$this->maintainer = 'Pierre Mazière';
|
$this->maintainer = 'Pierre Mazière';
|
||||||
$this->name = 'Github Issue';
|
$this->name = 'Github Issue';
|
||||||
$this->uri = '';
|
$this->uri = '';
|
||||||
$this->description = 'Returns the comments of a github project issue';
|
$this->description = 'Returns the issues or comments of an issue of a github project';
|
||||||
|
|
||||||
$this->parameters[]=array (
|
$this->parameters['global']=array (
|
||||||
'u'=>array(
|
'u'=>array(
|
||||||
'name'=>'User name',
|
'name'=>'User name',
|
||||||
'required'=>true
|
'required'=>true
|
||||||
|
@ -21,33 +15,52 @@ class GithubIssueBridge extends BridgeAbstract{
|
||||||
'p'=>array(
|
'p'=>array(
|
||||||
'name'=>'Project name',
|
'name'=>'Project name',
|
||||||
'required'=>true
|
'required'=>true
|
||||||
),
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->parameters['Project Issues']=array();
|
||||||
|
$this->parameters['Issue comments']=array(
|
||||||
'i'=>array(
|
'i'=>array(
|
||||||
'name'=>'Issue number',
|
'name'=>'Issue number',
|
||||||
'type'=>'number',
|
'type'=>'number',
|
||||||
'required'=>true
|
'required'=>'true'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function collectData(array $param){
|
public function collectData(array $param){
|
||||||
$uri = 'https://github.com/'.$param['u'].'/'.$param['p'].'/issues/'.$param['i'];
|
$uri = 'https://github.com/'.$param['u'].'/'.$param['p'].'/issues/'.(isset($param['i'])?$param['i']:'');
|
||||||
$html = $this->getSimpleHTMLDOM($uri)
|
$html = $this->getSimpleHTMLDOM($uri)
|
||||||
or $this->returnServerError('No results for Github Issue '.$param['i'].' in project '.$param['u'].'/'.$param['p']);
|
or $this->returnServerError('No results for Github Issue '.$param['i'].' in project '.$param['u'].'/'.$param['p']);
|
||||||
|
|
||||||
foreach($html->find('.js-comment-container') as $comment){
|
if(isset($param['i'])){
|
||||||
|
foreach($html->find('.js-comment-container') as $comment){
|
||||||
|
|
||||||
$item = array();
|
$item = array();
|
||||||
$item['author']=$comment->find('img',0)->getAttribute('alt');
|
$item['author']=$comment->find('img',0)->getAttribute('alt');
|
||||||
|
|
||||||
$comment=$comment->firstChild()->nextSibling();
|
$comment=$comment->firstChild()->nextSibling();
|
||||||
|
|
||||||
$item['uri']=$uri.'#'.$comment->getAttribute('id');
|
$item['uri']=$uri.'#'.$comment->getAttribute('id');
|
||||||
$item['title']=trim($comment->firstChild()->plaintext);
|
$item['title']=trim($comment->firstChild()->plaintext);
|
||||||
$item['timestamp']=strtotime($comment->find('relative-time',0)->getAttribute('datetime'));
|
$item['timestamp']=strtotime($comment->find('relative-time',0)->getAttribute('datetime'));
|
||||||
$item['content']=$comment->find('.comment-body',0)->innertext;
|
$item['content']=$comment->find('.comment-body',0)->innertext;
|
||||||
|
|
||||||
$this->items[]=$item;
|
$this->items[]=$item;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
foreach($html->find('.js-active-navigation-container .js-navigation-item') as $issue){
|
||||||
|
$item=array();
|
||||||
|
$info=$issue->find('.opened-by',0);
|
||||||
|
$item['author']=$info->find('a',0)->plaintext;
|
||||||
|
$item['timestamp']=strtotime($info->find('relative-time',0)->getAttribute('datetime'));
|
||||||
|
$item['title']=$issue->find('.js-navigation-open',0)->plaintext;
|
||||||
|
$comments=$issue->firstChild()->firstChild()
|
||||||
|
->nextSibling()->nextSibling()->nextSibling()->plaintext;
|
||||||
|
$item['content']='Comments: '.($comments?$comments:'0');
|
||||||
|
$item['uri']='https://github.com'.$issue->find('.js-navigation-open',0)->getAttribute('href');
|
||||||
|
$this->items[]=$item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue