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-02 14:45:12 +03:00
|
|
|
$this->parameters[] =
|
2016-06-25 10:55:00 +03:00
|
|
|
'[
|
|
|
|
{
|
|
|
|
"name" : "Base URI",
|
2016-08-21 19:07:42 +03:00
|
|
|
"identifier" : "uri",
|
|
|
|
"defaultValue":"https://gitlab.com"
|
2016-06-25 10:55:00 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" : "User name",
|
2016-08-21 19:07:42 +03:00
|
|
|
"identifier" : "u",
|
|
|
|
"required": true
|
2016-06-25 10:55:00 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" : "Project name",
|
2016-08-21 19:07:42 +03:00
|
|
|
"identifier" : "p",
|
|
|
|
"required":true
|
2016-08-02 14:45:12 +03:00
|
|
|
},
|
2016-06-25 10:55:00 +03:00
|
|
|
{
|
|
|
|
"name" : "Project branch",
|
2016-08-21 19:07:42 +03:00
|
|
|
"identifier" : "b",
|
|
|
|
"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
|
|
|
|
|
|
|
$item = new \Item();
|
2016-06-26 01:39:56 +03:00
|
|
|
$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');
|
|
|
|
$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)){
|
|
|
|
$item->title=$a->plaintext;
|
|
|
|
}
|
|
|
|
if(in_array('commit-author-link',$classes)){
|
2016-08-09 15:54:44 +03:00
|
|
|
$item->author=trim($a->plaintext);
|
2016-06-25 10:55:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pre=$commit->find('pre',0);
|
|
|
|
if($pre){
|
|
|
|
$item->content=$pre->outertext;
|
|
|
|
}else{
|
|
|
|
$item->content='';
|
|
|
|
}
|
2016-06-26 01:39:56 +03:00
|
|
|
$item->timestamp=strtotime($commit->find('time',0)->getAttribute('datetime'));
|
2016-06-25 10:55:00 +03:00
|
|
|
|
|
|
|
$this->items[]=$item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|