Add support for Bitbucket's Mercurial based repos

This commit is contained in:
bochkovprivate 2017-03-19 11:17:10 +07:00 committed by Dmitry Khomutov
commit 7084b49da7
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
9 changed files with 126 additions and 22 deletions

View file

@ -3,31 +3,31 @@
namespace PHPCensor\Model\Build;
/**
* Bitbucket Build Model
* BitBucket Build Model
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class BitbucketBuild extends RemoteGitBuild
{
/**
* Get link to commit from another source (i.e. Github)
*/
* Get link to commit from another source (i.e. BitBucket)
*/
public function getCommitLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/commits/' . $this->getCommitId();
}
/**
* Get link to branch from another source (i.e. Github)
*/
* Get link to branch from another source (i.e. BitBucket)
*/
public function getBranchLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/src/?at=' . $this->getBranch();
}
/**
* Get the URL to be used to clone this remote repository.
*/
* Get the URL to be used to clone this remote repository.
*/
protected function getCloneUrl()
{
$key = trim($this->getProject()->getSshPrivateKey());
@ -38,4 +38,30 @@ class BitbucketBuild extends RemoteGitBuild
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '.git';
}
}
/**
* Get a template to use for generating links to files.
*
* @return string
*/
public function getFileLinkTemplate()
{
$reference = $this->getProject()->getReference();
$branch = $this->getBranch();
if ($this->getExtra('build_type') == 'pull_request') {
$matches = [];
preg_match('/[\/:]([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)/', $this->getExtra('remote_url'), $matches);
$reference = $matches[1];
$branch = $this->getExtra('remote_branch');
}
$link = 'https://bitbucket.org/' . $reference . '/';
$link .= 'src/' . $branch . '/';
$link .= '{FILE}';
$link .= '#{BASEFILE}-{LINE}';
return $link;
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace PHPCensor\Model\Build;
/**
* BitBucket Build Model
*
* @author Artem Bochkov <artem.v.bochkov@gmail.com>
*/
class BitbucketHgBuild extends MercurialBuild
{
/**
* Get link to commit from another source (i.e. BitBucket)
*/
public function getCommitLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/commits/' . $this->getCommitId();
}
/**
* Get link to branch from another source (i.e. BitBucket)
*/
public function getBranchLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/src/?at=' . $this->getBranch();
}
/**
* Get the URL to be used to clone this remote repository.
*/
protected function getCloneUrl()
{
$key = trim($this->getProject()->getSshPrivateKey());
if (!empty($key)) {
return 'ssh://hg@bitbucket.org/' . $this->getProject()->getReference();
} else {
return 'https://bitbucket.org/' . $this->getProject()->getReference();
}
}
/**
* Get a template to use for generating links to files.
*
* @return string
*/
public function getFileLinkTemplate()
{
$reference = $this->getProject()->getReference();
$branch = $this->getBranch();
if ($this->getExtra('build_type') == 'pull_request') {
$matches = [];
preg_match('/[\/:]([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)/', $this->getExtra('remote_url'), $matches);
$reference = $matches[1];
$branch = $this->getExtra('remote_branch');
}
$link = 'https://bitbucket.org/' . $reference . '/';
$link .= 'src/' . $branch . '/';
$link .= '{FILE}';
$link .= '#{BASEFILE}-{LINE}';
return $link;
}
}

View file

@ -25,9 +25,9 @@ class MercurialBuild extends Build
*/
public function createWorkingCopy(Builder $builder, $buildPath)
{
$key = trim($this->getProject()->getSshPublicKey());
$key = trim($this->getProject()->getSshPrivateKey());
if (!empty($key) && strpos($this->getProject()->getReference(), 'ssh') > -1) {
if (!empty($key)) {
$success = $this->cloneBySsh($builder, $buildPath);
} else {
$success = $this->cloneByHttp($builder, $buildPath);