Add support for Bitbucket's Mercurial based repos
This commit is contained in:
parent
ea8c5393bc
commit
7084b49da7
9 changed files with 126 additions and 22 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
67
src/PHPCensor/Model/Build/BitbucketHgBuild.php
Normal file
67
src/PHPCensor/Model/Build/BitbucketHgBuild.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -754,6 +754,7 @@ class Project extends Model
|
|||
break;
|
||||
|
||||
case 'bitbucket':
|
||||
case 'bitbuckethg':
|
||||
$icon = 'bitbucket';
|
||||
break;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue