Browse Source

Merge branch 'GithubIssuesBridge' of https://framagit.org/peetah/rss-bridge

logmanoriginal 7 years ago
parent
commit
99a416ebad
1 changed files with 33 additions and 20 deletions
  1. 33 20
      bridges/GithubIssueBridge.php

+ 33 - 20
bridges/GithubIssueBridge.php

@@ -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?$comments:'0');
+        $item['uri']='https://github.com'.$issue->find('.js-navigation-open',0)->getAttribute('href');
+        $this->items[]=$item;
+      }
     }
   }