2016-06-25 10:55:00 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* GitlabCommitsBridge
|
|
|
|
*
|
|
|
|
* @name GitlabCommits Bridge
|
|
|
|
* @description Returns the commits of a project hosted on a gitlab instance
|
|
|
|
*/
|
|
|
|
class GitlabCommitsBridge extends BridgeAbstract{
|
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = 'Pierre Mazière';
|
|
|
|
$this->name = 'Gitlab Commits';
|
|
|
|
$this->uri = '';
|
|
|
|
$this->description = 'Returns the commits of a project hosted on a gitlab instance';
|
|
|
|
|
2016-08-22 02:25:56 +03:00
|
|
|
$this->parameters[] = array(
|
|
|
|
'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-06-25 10:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(array $param){
|
|
|
|
$uri = $param['uri'].'/'.$param['u'].'/'.$param['p'].'/commits/';
|
|
|
|
if(isset($param['b'])){
|
|
|
|
$uri.=$param['b'];
|
|
|
|
}else{
|
|
|
|
$uri.='master';
|
|
|
|
}
|
|
|
|
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($uri)
|
2016-08-17 15:45:08 +03:00
|
|
|
or $this->returnServerError('No results for Gitlab Commits of project '.$param['uri'].'/'.$param['u'].'/'.$param['p']);
|
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();
|
|
|
|
$item['uri']=$param['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-22 19:55:59 +03:00
|
|
|
$item['uri'].=substr($href,strpos($href,'/'.$param['u'].'/'.$param['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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|