From c929010f6e4e8146bd5717f5ebb5725d6e96988b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sat, 25 Jun 2016 09:55:00 +0200 Subject: [PATCH 1/4] new bridge GitlabCommits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit some gitlab instances do not enable RSS feed for project commits Signed-off-by: Pierre Mazière --- bridges/GitlabCommitsBridge.php | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 bridges/GitlabCommitsBridge.php diff --git a/bridges/GitlabCommitsBridge.php b/bridges/GitlabCommitsBridge.php new file mode 100644 index 00000000..0a182300 --- /dev/null +++ b/bridges/GitlabCommitsBridge.php @@ -0,0 +1,97 @@ +maintainer = 'Pierre Mazière'; + $this->name = 'Gitlab Commits'; + $this->uri = ''; + $this->description = 'Returns the commits of a project hosted on a gitlab instance'; + $this->update = '2016-06-19'; + + $this->parameters= + '[ + { + "name" : "Base URI", + "identifier" : "uri" + }, + { + "name" : "User name", + "identifier" : "u" + }, + { + "name" : "Project name", + "identifier" : "p" + } + { + "name" : "Project branch", + "identifier" : "b" + } + + ]'; + } + + public function collectData(array $param){ + $uri = $param['uri'].'/'.$param['u'].'/'.$param['p'].'/commits/'; + if(isset($param['b'])){ + $uri.=$param['b']; + }else{ + $uri.='master'; + } + + $html = file_get_html($uri) + or $this->returnError('No results for LWNprev', 404); + + + foreach($html->find('li') as $commit){ + if(!in_array('commit',explode(' ',$commit->getAttribute("class")))){ + continue; + } + + $item = new \Item(); + $item->uri=$param["uri"]; + + foreach($commit->getElementsByTagName("a") as $a){ + $classes=explode(' ',$a->getAttribute("class")); + if(in_array('commit-short-id',$classes) || + in_array('commit_short_id',$classes)){ + $href=$a->getAttribute("href"); + $item->uri.=substr($href,strpos($href,"/".$param['u'].'/'.$param['p'])); + } + if(in_array('commit-row-message',$classes)){ + $item->title=$a->plaintext; + } + if(in_array('commit-author-link',$classes)){ + $item->name=trim($a->plaintext); + } + } + + $pre=$commit->find('pre',0); + if($pre){ + $item->content=$pre->outertext; + }else{ + $item->content=''; + } + $item->timestamp=strtotime($commit->find('time',0)->getAttribute("datetime")); + + $this->items[]=$item; + } + } + + public function getName(){ + return 'Gitlab Commits'; + } + + public function getURI(){ + return ''; + } + + public function getCacheDuration(){ + return 3600; // one hour + } +} From 615df56b196f873a93462568bbb8562e875e3c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 26 Jun 2016 00:39:56 +0200 Subject: [PATCH 2/4] fix inconsistent use of simple and double quotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/GitlabCommitsBridge.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bridges/GitlabCommitsBridge.php b/bridges/GitlabCommitsBridge.php index 0a182300..a3c9299b 100644 --- a/bridges/GitlabCommitsBridge.php +++ b/bridges/GitlabCommitsBridge.php @@ -54,14 +54,14 @@ class GitlabCommitsBridge extends BridgeAbstract{ } $item = new \Item(); - $item->uri=$param["uri"]; + $item->uri=$param['uri']; - foreach($commit->getElementsByTagName("a") as $a){ + foreach($commit->getElementsByTagName('a') as $a){ $classes=explode(' ',$a->getAttribute("class")); if(in_array('commit-short-id',$classes) || in_array('commit_short_id',$classes)){ - $href=$a->getAttribute("href"); - $item->uri.=substr($href,strpos($href,"/".$param['u'].'/'.$param['p'])); + $href=$a->getAttribute('href'); + $item->uri.=substr($href,strpos($href,'/'.$param['u'].'/'.$param['p'])); } if(in_array('commit-row-message',$classes)){ $item->title=$a->plaintext; @@ -77,7 +77,7 @@ class GitlabCommitsBridge extends BridgeAbstract{ }else{ $item->content=''; } - $item->timestamp=strtotime($commit->find('time',0)->getAttribute("datetime")); + $item->timestamp=strtotime($commit->find('time',0)->getAttribute('datetime')); $this->items[]=$item; } From ca44ab943ac16477593c16f7d6d53f41b7279886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 26 Jun 2016 00:46:41 +0200 Subject: [PATCH 3/4] simplify commits detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/GitlabCommitsBridge.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bridges/GitlabCommitsBridge.php b/bridges/GitlabCommitsBridge.php index a3c9299b..972731d3 100644 --- a/bridges/GitlabCommitsBridge.php +++ b/bridges/GitlabCommitsBridge.php @@ -48,10 +48,7 @@ class GitlabCommitsBridge extends BridgeAbstract{ or $this->returnError('No results for LWNprev', 404); - foreach($html->find('li') as $commit){ - if(!in_array('commit',explode(' ',$commit->getAttribute("class")))){ - continue; - } + foreach($html->find('li.commit') as $commit){ $item = new \Item(); $item->uri=$param['uri']; From 26a9ffa5eb52ddfa6574b892c4d9868ace2bcce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 26 Jun 2016 00:47:33 +0200 Subject: [PATCH 4/4] fix copy/paste MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/GitlabCommitsBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/GitlabCommitsBridge.php b/bridges/GitlabCommitsBridge.php index 972731d3..3361ef47 100644 --- a/bridges/GitlabCommitsBridge.php +++ b/bridges/GitlabCommitsBridge.php @@ -45,7 +45,7 @@ class GitlabCommitsBridge extends BridgeAbstract{ } $html = file_get_html($uri) - or $this->returnError('No results for LWNprev', 404); + or $this->returnError('No results for Gitlab Commits of project '.$param['uri'].'/'.$param['u'].'/'.$param['p'], 404); foreach($html->find('li.commit') as $commit){