2016-06-25 10:55:00 +03:00
|
|
|
<?php
|
|
|
|
class GitlabCommitsBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = 'Pierre Mazière';
|
|
|
|
public $name = 'Gitlab Commits';
|
|
|
|
public $uri = '';
|
|
|
|
public $description = 'Returns the commits of a project hosted on a gitlab instance';
|
2016-06-25 10:55:00 +03:00
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $parameters = array( array(
|
2016-08-22 02:25:56 +03:00
|
|
|
'uri'=>array(
|
|
|
|
'name'=>'Base URI',
|
|
|
|
'defaultValue'=>'https://gitlab.com'
|
|
|
|
),
|
|
|
|
'u'=>array(
|
|
|
|
'name'=>'User name',
|
|
|
|
'required'=>true
|
|
|
|
),
|
|
|
|
'p'=>array(
|
|
|
|
'name'=>'Project name',
|
|
|
|
'required'=>true
|
|
|
|
),
|
|
|
|
'b'=>array(
|
|
|
|
'name'=>'Project branch',
|
|
|
|
'defaultValue'=>'master'
|
|
|
|
)
|
2016-08-27 22:03:26 +03:00
|
|
|
));
|
2016-06-25 10:55:00 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2016-08-29 01:20:21 +03:00
|
|
|
$uri = $this->getInput('uri').'/'.$this->getInput('u').'/'
|
|
|
|
.$this->getInput('p').'/commits/'.$this->getInput('b');
|
2016-06-25 10:55:00 +03:00
|
|
|
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($uri)
|
2016-08-29 01:20:21 +03:00
|
|
|
or $this->returnServerError('No results for Gitlab Commits of project '.$uri);
|
2016-06-25 10:55:00 +03:00
|
|
|
|
2016-06-26 01:46:41 +03:00
|
|
|
foreach($html->find('li.commit') as $commit){
|
2016-06-25 10:55:00 +03:00
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
2016-08-28 02:25:33 +03:00
|
|
|
$item['uri']=$this->getInput('uri');
|
2016-06-25 10:55:00 +03:00
|
|
|
|
2016-06-26 01:39:56 +03:00
|
|
|
foreach($commit->getElementsByTagName('a') as $a){
|
2016-06-25 10:55:00 +03:00
|
|
|
$classes=explode(' ',$a->getAttribute("class"));
|
|
|
|
if(in_array('commit-short-id',$classes) ||
|
|
|
|
in_array('commit_short_id',$classes)){
|
2016-06-26 01:39:56 +03:00
|
|
|
$href=$a->getAttribute('href');
|
2016-08-28 02:25:33 +03:00
|
|
|
$item['uri'].=substr($href,strpos($href,'/'.$this->getInput('u').'/'.$this->getInput('p')));
|
2016-06-25 10:55:00 +03:00
|
|
|
}
|
|
|
|
if(in_array('commit-row-message',$classes)){
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['title']=$a->plaintext;
|
2016-06-25 10:55:00 +03:00
|
|
|
}
|
|
|
|
if(in_array('commit-author-link',$classes)){
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['author']=trim($a->plaintext);
|
2016-06-25 10:55:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pre=$commit->find('pre',0);
|
|
|
|
if($pre){
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['content']=$pre->outertext;
|
2016-06-25 10:55:00 +03:00
|
|
|
}else{
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['content']='';
|
2016-06-25 10:55:00 +03:00
|
|
|
}
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['timestamp']=strtotime($commit->find('time',0)->getAttribute('datetime'));
|
2016-06-25 10:55:00 +03:00
|
|
|
|
|
|
|
$this->items[]=$item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|