[GithubIssueBriddge] list all issues when 'i' parameter is not provided

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-23 20:29:29 +02:00
orang tua 7961f8081e
melakukan c9822bffa7

Melihat File

@ -1,19 +1,13 @@
<?php
/**
* GithubIssueBridge
*
* @name GithubIssue Bridge
* @description Returns the comments of a github project issue
*/
class GithubIssueBridge extends BridgeAbstract{
public function loadMetadatas() {
$this->maintainer = 'Pierre Mazière';
$this->name = 'Github Issue';
$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(
'name'=>'User name',
'required'=>true
@ -21,33 +15,52 @@ class GithubIssueBridge extends BridgeAbstract{
'p'=>array(
'name'=>'Project name',
'required'=>true
),
)
);
$this->parameters['Project Issues']=array();
$this->parameters['Issue comments']=array(
'i'=>array(
'name'=>'Issue number',
'type'=>'number',
'required'=>true
'required'=>'true'
)
);
}
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)
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['author']=$comment->find('img',0)->getAttribute('alt');
$item = array();
$item['author']=$comment->find('img',0)->getAttribute('alt');
$comment=$comment->firstChild()->nextSibling();
$comment=$comment->firstChild()->nextSibling();
$item['uri']=$uri.'#'.$comment->getAttribute('id');
$item['title']=trim($comment->firstChild()->plaintext);
$item['timestamp']=strtotime($comment->find('relative-time',0)->getAttribute('datetime'));
$item['content']=$comment->find('.comment-body',0)->innertext;
$item['uri']=$uri.'#'.$comment->getAttribute('id');
$item['title']=trim($comment->firstChild()->plaintext);
$item['timestamp']=strtotime($comment->find('relative-time',0)->getAttribute('datetime'));
$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;
$item['uri']='https://github.com'.$issue->find('.js-navigation-open',0)->getAttribute('href');
$this->items[]=$item;
}
}
}