2016-06-25 09:55:00 +02:00
|
|
|
<?php
|
|
|
|
class GitlabCommitsBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-27 21:03:26 +02: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 09:55:00 +02:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $parameters = array( array(
|
2016-08-22 01:25:56 +02: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 21:03:26 +02:00
|
|
|
));
|
2016-06-25 09:55:00 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-28 01:25:33 +02:00
|
|
|
$uri = $this->getInput('uri').'/'.$this->getInput('u').'/'.$this->getInput('p').'/commits/';
|
2016-08-28 20:38:01 +02:00
|
|
|
if($this->getInput('b')){
|
2016-08-28 01:25:33 +02:00
|
|
|
$uri.=$this->getInput('b');
|
2016-06-25 09:55:00 +02:00
|
|
|
}else{
|
|
|
|
$uri.='master';
|
|
|
|
}
|
|
|
|
|
2016-07-08 19:06:35 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($uri)
|
2016-08-28 01:25:33 +02:00
|
|
|
or $this->returnServerError('No results for Gitlab Commits of project '.$this->getInput('uri').'/'.$this->getInput('u').'/'.$this->getInput('p'));
|
2016-06-25 09:55:00 +02:00
|
|
|
|
|
|
|
|
2016-06-26 00:46:41 +02:00
|
|
|
foreach($html->find('li.commit') as $commit){
|
2016-06-25 09:55:00 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-08-28 01:25:33 +02:00
|
|
|
$item['uri']=$this->getInput('uri');
|
2016-06-25 09:55:00 +02:00
|
|
|
|
2016-06-26 00:39:56 +02:00
|
|
|
foreach($commit->getElementsByTagName('a') as $a){
|
2016-06-25 09:55:00 +02:00
|
|
|
$classes=explode(' ',$a->getAttribute("class"));
|
|
|
|
if(in_array('commit-short-id',$classes) ||
|
|
|
|
in_array('commit_short_id',$classes)){
|
2016-06-26 00:39:56 +02:00
|
|
|
$href=$a->getAttribute('href');
|
2016-08-28 01:25:33 +02:00
|
|
|
$item['uri'].=substr($href,strpos($href,'/'.$this->getInput('u').'/'.$this->getInput('p')));
|
2016-06-25 09:55:00 +02:00
|
|
|
}
|
|
|
|
if(in_array('commit-row-message',$classes)){
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['title']=$a->plaintext;
|
2016-06-25 09:55:00 +02:00
|
|
|
}
|
|
|
|
if(in_array('commit-author-link',$classes)){
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['author']=trim($a->plaintext);
|
2016-06-25 09:55:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pre=$commit->find('pre',0);
|
|
|
|
if($pre){
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content']=$pre->outertext;
|
2016-06-25 09:55:00 +02:00
|
|
|
}else{
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content']='';
|
2016-06-25 09:55:00 +02:00
|
|
|
}
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['timestamp']=strtotime($commit->find('time',0)->getAttribute('datetime'));
|
2016-06-25 09:55:00 +02:00
|
|
|
|
|
|
|
$this->items[]=$item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|