Skip to content

Commit

Permalink
Fixes for new BitbucketServer build type. Issue #260, #286.
Browse files Browse the repository at this point in the history
  • Loading branch information
corpsee committed Mar 12, 2019
1 parent 2d4a8d0 commit 074d609
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
28 changes: 14 additions & 14 deletions src/Controller/ProjectController.php
Expand Up @@ -103,10 +103,10 @@ public function view($projectId)
}

/** @var PHPCensor\Model\User $user */
$user = $this->getUser();
$perPage = $user->getFinalPerPage();
$builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage);
$pages = ($builds[1] === 0)
$user = $this->getUser();
$perPage = $user->getFinalPerPage();
$builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage);
$pages = ($builds[1] === 0)
? 1
: (integer)ceil($builds[1] / $perPage);

Expand Down Expand Up @@ -486,17 +486,17 @@ protected function projectForm($values, $type = 'add')
$form->addField(new Form\Element\Hidden('ssh_public_key'));

$options = [
'choose' => Lang::get('select_repository_type'),
Project::TYPE_GITHUB => 'GitHub',
Project::TYPE_BITBUCKET => 'Bitbucket (Git)',
'choose' => Lang::get('select_repository_type'),
Project::TYPE_GITHUB => 'GitHub',
Project::TYPE_BITBUCKET => 'Bitbucket (Git)',
Project::TYPE_BITBUCKET_SERVER => 'Bitbucket (Server)',
Project::TYPE_BITBUCKET_HG => 'Bitbucket (Hg)',
Project::TYPE_GITLAB => 'GitLab',
Project::TYPE_GOGS => 'Gogs',
Project::TYPE_GIT => 'Git',
Project::TYPE_LOCAL => Lang::get('local'),
Project::TYPE_HG => 'Hg (Mercurial)',
Project::TYPE_SVN => 'Svn (Subversion)',
Project::TYPE_BITBUCKET_HG => 'Bitbucket (Hg)',
Project::TYPE_GITLAB => 'GitLab',
Project::TYPE_GOGS => 'Gogs',
Project::TYPE_GIT => 'Git',
Project::TYPE_LOCAL => Lang::get('local'),
Project::TYPE_HG => 'Hg (Mercurial)',
Project::TYPE_SVN => 'Svn (Subversion)',
];

$sourcesPattern = sprintf('^(%s)', implode('|', Project::$allowedTypes));
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/CommandExecutor.php
Expand Up @@ -147,7 +147,7 @@ function ($a) {

$shouldOutput = ($this->logExecOutput && ($this->verbose || 0 !== $status));

if (($shouldOutput) && !empty($this->lastOutput)) {
if ($shouldOutput && !empty($this->lastOutput)) {
$this->logger->log($this->lastOutput);
}

Expand Down
18 changes: 9 additions & 9 deletions src/Model/Base/Project.php
Expand Up @@ -7,16 +7,16 @@

class Project extends Model
{
const TYPE_LOCAL = 'local';
const TYPE_GIT = 'git';
const TYPE_GITHUB = 'github';
const TYPE_BITBUCKET = 'bitbucket';
const TYPE_GITLAB = 'gitlab';
const TYPE_GOGS = 'gogs';
const TYPE_HG = 'hg';
const TYPE_BITBUCKET_HG = 'bitbucket-hg';
const TYPE_LOCAL = 'local';
const TYPE_GIT = 'git';
const TYPE_GITHUB = 'github';
const TYPE_BITBUCKET = 'bitbucket';
const TYPE_GITLAB = 'gitlab';
const TYPE_GOGS = 'gogs';
const TYPE_HG = 'hg';
const TYPE_BITBUCKET_HG = 'bitbucket-hg';
const TYPE_BITBUCKET_SERVER = 'bitbucket-server';
const TYPE_SVN = 'svn';
const TYPE_SVN = 'svn';

/**
* @var array
Expand Down
5 changes: 3 additions & 2 deletions src/Model/Build/BitbucketBuild.php
Expand Up @@ -8,6 +8,7 @@
use PHPCensor\Config;
use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError;
use PHPCensor\Helper\Diff;

/**
* BitBucket Build Model
Expand Down Expand Up @@ -313,12 +314,12 @@ protected function getDiffLineNumber(Builder $builder, $file, $line)
$path = $builder->buildPath;

if (!empty($prNumber)) {
$builder->executeCommand('cd %s && git diff origin/%s "%s"', $path, $this->getBranch(), $file);
$builder->executeCommand('cd "%s" && git diff "origin/%s" "%s"', $path, $this->getBranch(), $file);
} else {
$commitId = $this->getCommitId();
$compare = empty($commitId) ? 'HEAD' : $commitId;

$builder->executeCommand('cd %s && git diff %s^^ "%s"', $path, $compare, $file);
$builder->executeCommand('cd "%s" && git diff "%s^^" "%s"', $path, $compare, $file);
}

$builder->logExecOutput(true);
Expand Down
15 changes: 5 additions & 10 deletions src/Model/Build/BitbucketServerBuild.php
Expand Up @@ -5,12 +5,6 @@
use PHPCensor\Builder;
use PHPCensor\Model\Build;

/**
* BitBucket Build Model
* Derived from BitBucketBuild
* @author Dan Cryer <dan@block8.co.uk>
*
*/
class BitbucketServerBuild extends GitBuild
{
/**
Expand Down Expand Up @@ -128,8 +122,8 @@ protected function postCloneSetup(Builder $builder, $cloneTo, array $extra = nul
$success = $builder->executeCommand($cmd, $cloneTo);

if ($success) {
$applycmd = 'git apply "%s"';
$success = $builder->executeCommand($applycmd, $diffFile);
$applyCmd = 'git apply "%s"';
$success = $builder->executeCommand($applyCmd, $diffFile);
}

//unlink($diffFile);
Expand Down Expand Up @@ -158,11 +152,12 @@ protected function getPullRequestDiff(Builder $builder, $cloneTo, $targetBranch)
$cmd = 'cd "%s" && git diff %s';

$success = $builder->executeCommand($cmd, $cloneTo, $targetBranch);

if ($success) {
return $builder->getLastOutput();
}
throw new Exception('Unable to create diff patch.');

throw new \Exception('Unable to create diff patch.');
}

/**
Expand Down

0 comments on commit 074d609

Please sign in to comment.