GithubIssueBridge.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * GithubIssueBridge
  4. *
  5. * @name GithubIssue Bridge
  6. * @description Returns the comments of a github project issue
  7. */
  8. class GithubIssueBridge extends BridgeAbstract{
  9. public function loadMetadatas() {
  10. $this->maintainer = 'Pierre Mazière';
  11. $this->name = 'Github Issue';
  12. $this->uri = '';
  13. $this->description = 'Returns the comments of a github project issue';
  14. $this->update = '2016-06-25';
  15. $this->parameters[]=
  16. '[
  17. {
  18. "name" : "User name",
  19. "identifier" : "u"
  20. },
  21. {
  22. "name" : "Project name",
  23. "identifier" : "p"
  24. },
  25. {
  26. "name" : "Issue number",
  27. "identifier" : "i"
  28. }
  29. ]';
  30. }
  31. public function collectData(array $param){
  32. $uri = 'https://github.com/'.$param['u'].'/'.$param['p'].'/issues/'.$param['i'];
  33. $html = file_get_html($uri)
  34. or $this->returnError('No results for Github Issue '.$param['i'].' in project '.$param['u'].'/'.$param['p'], 404);
  35. foreach($html->find('.js-comment-container') as $comment){
  36. $item = new \Item();
  37. $item->name=$comment->find('img',0)->getAttribute('alt');
  38. $comment=$comment->firstChild()->nextSibling();
  39. $item->uri=$uri.'#'.$comment->getAttribute('id');
  40. $item->title=trim($comment->firstChild()->plaintext);
  41. $item->timestamp=strtotime($comment->find('relative-time',0)->getAttribute('datetime'));
  42. $item->content=$comment->find('.comment-body',0)->innertext;
  43. $this->items[]=$item;
  44. }
  45. }
  46. public function getName(){
  47. return 'Github Issue';
  48. }
  49. public function getURI(){
  50. return '';
  51. }
  52. public function getCacheDuration(){
  53. return 600; // ten minutes
  54. }
  55. }