From c9822bffa75bcedd4cc7eeeff4419a5c836d62d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Tue, 23 Aug 2016 20:29:29 +0200 Subject: [PATCH 1/2] [GithubIssueBriddge] list all issues when 'i' parameter is not provided MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/GithubIssueBridge.php | 53 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index 2bdea3e4..42e23241 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -1,19 +1,13 @@ 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; + } } } From c051730f7ce13f7890172224eb2ab32d7c54f184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Tue, 23 Aug 2016 21:20:21 +0200 Subject: [PATCH 2/2] [GithubIssueBridge] fix comments number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/GithubIssueBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index 42e23241..9bfddb84 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -57,7 +57,7 @@ class GithubIssueBridge extends BridgeAbstract{ $item['title']=$issue->find('.js-navigation-open',0)->plaintext; $comments=$issue->firstChild()->firstChild() ->nextSibling()->nextSibling()->nextSibling()->plaintext; - $item['content']='Comments: '.$comments; + $item['content']='Comments: '.($comments?$comments:'0'); $item['uri']='https://github.com'.$issue->find('.js-navigation-open',0)->getAttribute('href'); $this->items[]=$item; }