Added tags for Github builds.
This commit is contained in:
parent
f26f000bb4
commit
647a5cedcd
|
@ -57,9 +57,9 @@ class CreateBuildCommand extends Command
|
|||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$projectId = $input->getArgument('projectId');
|
||||
$commitId = $input->getOption('commit');
|
||||
$branch = $input->getOption('branch');
|
||||
$projectId = $input->getArgument('projectId');
|
||||
$commitId = $input->getOption('commit');
|
||||
$branch = $input->getOption('branch');
|
||||
$environment = $input->hasOption('environment') ? $input->getOption('environment') : null;
|
||||
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
|
|
|
@ -148,7 +148,16 @@ class ProjectController extends PHPCensor\Controller
|
|||
}
|
||||
|
||||
$email = $_SESSION['php-censor-user']->getEmail();
|
||||
$build = $this->buildService->createBuild($project, $environment, null, urldecode($branch), $email, null, $extra);
|
||||
$build = $this->buildService->createBuild(
|
||||
$project,
|
||||
$environment,
|
||||
null,
|
||||
urldecode($branch),
|
||||
null,
|
||||
$email,
|
||||
null,
|
||||
$extra
|
||||
);
|
||||
|
||||
if ($this->buildService->queueError) {
|
||||
$_SESSION['global_error'] = Lang::get('add_to_queue_failed');
|
||||
|
|
|
@ -121,6 +121,7 @@ class WebhookController extends Controller
|
|||
$project,
|
||||
$commit['new']['target']['hash'],
|
||||
$commit['new']['name'],
|
||||
null,
|
||||
$email,
|
||||
$commit['new']['target']['message']
|
||||
);
|
||||
|
@ -152,6 +153,7 @@ class WebhookController extends Controller
|
|||
$project,
|
||||
$commit['raw_node'],
|
||||
$commit['branch'],
|
||||
null,
|
||||
$email,
|
||||
$commit['message']
|
||||
);
|
||||
|
@ -179,7 +181,7 @@ class WebhookController extends Controller
|
|||
$commitMessage = $this->getParam('message');
|
||||
$committer = $this->getParam('committer');
|
||||
|
||||
return $this->createBuild($project, $commit, $branch, $committer, $commitMessage);
|
||||
return $this->createBuild($project, $commit, $branch, null, $committer, $commitMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,7 +247,9 @@ class WebhookController extends Controller
|
|||
$results[$commit['id']] = ['status' => 'ignored'];
|
||||
} else {
|
||||
try {
|
||||
$tag = null;
|
||||
if ($isTag) {
|
||||
$tag = str_replace('refs/tags/', '', $payload['ref']);
|
||||
$branch = str_replace('refs/heads/', '', $payload['base_ref']);
|
||||
$committer = $payload['pusher']['email'];
|
||||
} else {
|
||||
|
@ -257,6 +261,7 @@ class WebhookController extends Controller
|
|||
$project,
|
||||
$commit['id'],
|
||||
$branch,
|
||||
$tag,
|
||||
$committer,
|
||||
$commit['message']
|
||||
);
|
||||
|
@ -339,7 +344,7 @@ class WebhookController extends Controller
|
|||
'remote_url' => $payload['pull_request']['head']['repo'][$remoteUrlKey],
|
||||
];
|
||||
|
||||
$results[$id] = $this->createBuild($project, $id, $branch, $committer, $message, $extra);
|
||||
$results[$id] = $this->createBuild($project, $id, $branch, null, $committer, $message, $extra);
|
||||
$status = 'ok';
|
||||
} catch (Exception $ex) {
|
||||
$results[$id] = ['status' => 'failed', 'error' => $ex->getMessage()];
|
||||
|
@ -367,7 +372,7 @@ class WebhookController extends Controller
|
|||
$commit = $attributes['last_commit'];
|
||||
$committer = $commit['author']['email'];
|
||||
|
||||
return $this->createBuild($project, $commit['id'], $branch, $committer, $commit['message']);
|
||||
return $this->createBuild($project, $commit['id'], $branch, null, $committer, $commit['message']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,6 +390,7 @@ class WebhookController extends Controller
|
|||
$project,
|
||||
$commit['id'],
|
||||
$branch,
|
||||
null,
|
||||
$committer,
|
||||
$commit['message']
|
||||
);
|
||||
|
@ -417,7 +423,7 @@ class WebhookController extends Controller
|
|||
$commitMessage = $this->getParam('message');
|
||||
$committer = $this->getParam('committer');
|
||||
|
||||
return $this->createBuild($project, $commit, $branch, $committer, $commitMessage);
|
||||
return $this->createBuild($project, $commit, $branch, null, $committer, $commitMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,6 +477,7 @@ class WebhookController extends Controller
|
|||
$project,
|
||||
$commit['id'],
|
||||
$branch,
|
||||
null,
|
||||
$committer,
|
||||
$commit['message']
|
||||
);
|
||||
|
@ -490,11 +497,12 @@ class WebhookController extends Controller
|
|||
* Wrapper for creating a new build.
|
||||
*
|
||||
* @param Project $project
|
||||
* @param string $commitId
|
||||
* @param string $branch
|
||||
* @param string $committer
|
||||
* @param string $commitMessage
|
||||
* @param array $extra
|
||||
* @param string $commitId
|
||||
* @param string $branch
|
||||
* @param string $tag
|
||||
* @param string $committer
|
||||
* @param string $commitMessage
|
||||
* @param array $extra
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
@ -504,6 +512,7 @@ class WebhookController extends Controller
|
|||
Project $project,
|
||||
$commitId,
|
||||
$branch,
|
||||
$tag,
|
||||
$committer,
|
||||
$commitMessage,
|
||||
array $extra = null
|
||||
|
@ -533,11 +542,21 @@ class WebhookController extends Controller
|
|||
foreach ($environment_names as $environment_name) {
|
||||
if (!in_array($environment_name, $ignore_environments)) {
|
||||
// If not, create a new build job for it:
|
||||
$build = $this->buildService->createBuild($project, $environment_name, $commitId, $project->getBranch(), $committer, $commitMessage, $extra);
|
||||
$created_builds[] = array(
|
||||
'id' => $build->getID(),
|
||||
'environment' => $environment_name,
|
||||
$build = $this->buildService->createBuild(
|
||||
$project,
|
||||
$environment_name,
|
||||
$commitId,
|
||||
$project->getBranch(),
|
||||
$tag,
|
||||
$committer,
|
||||
$commitMessage,
|
||||
$extra
|
||||
);
|
||||
|
||||
$created_builds[] = [
|
||||
'id' => $build->getID(),
|
||||
'environment' => $environment_name,
|
||||
];
|
||||
} else {
|
||||
$duplicates[] = array_search($environment_name, $ignore_environments);
|
||||
}
|
||||
|
@ -556,8 +575,18 @@ class WebhookController extends Controller
|
|||
}
|
||||
} else {
|
||||
$environment_name = null;
|
||||
if (!in_array($environment_name, $ignore_environments)) {
|
||||
$build = $this->buildService->createBuild($project, null, $commitId, $branch, $committer, $commitMessage, $extra);
|
||||
if (!in_array($environment_name, $ignore_environments) ||$tag) {
|
||||
$build = $this->buildService->createBuild(
|
||||
$project,
|
||||
null,
|
||||
$commitId,
|
||||
$branch,
|
||||
$tag,
|
||||
$committer,
|
||||
$commitMessage,
|
||||
$extra
|
||||
);
|
||||
|
||||
return ['status' => 'ok', 'buildID' => $build->getID()];
|
||||
} else {
|
||||
return [
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class AddedTagColumnToBuildTable extends AbstractMigration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$table = $this->table('build');
|
||||
|
||||
if (!$table->hasColumn('tag')) {
|
||||
$table->addColumn('tag', 'string', ['limit' => 250, 'null' => true])->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$table = $this->table('build');
|
||||
|
||||
if ($table->hasColumn('tag')) {
|
||||
$table->removeColumn('tag')->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ class Build extends Model
|
|||
'status' => null,
|
||||
'log' => null,
|
||||
'branch' => null,
|
||||
'tag' => null,
|
||||
'created' => null,
|
||||
'started' => null,
|
||||
'finished' => null,
|
||||
|
@ -71,6 +72,7 @@ class Build extends Model
|
|||
'status' => 'getStatus',
|
||||
'log' => 'getLog',
|
||||
'branch' => 'getBranch',
|
||||
'tag' => 'getTag',
|
||||
'created' => 'getCreated',
|
||||
'started' => 'getStarted',
|
||||
'finished' => 'getFinished',
|
||||
|
@ -94,6 +96,7 @@ class Build extends Model
|
|||
'status' => 'setStatus',
|
||||
'log' => 'setLog',
|
||||
'branch' => 'setBranch',
|
||||
'setTag' => 'setTag',
|
||||
'created' => 'setCreated',
|
||||
'started' => 'setStarted',
|
||||
'finished' => 'setFinished',
|
||||
|
@ -142,6 +145,11 @@ class Build extends Model
|
|||
'length' => 250,
|
||||
'default' => 'master',
|
||||
],
|
||||
'tag' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 250,
|
||||
'default' => null,
|
||||
],
|
||||
'created' => [
|
||||
'type' => 'datetime',
|
||||
'nullable' => true,
|
||||
|
@ -986,6 +994,36 @@ class Build extends Model
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of Tag / tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
$rtn = $this->data['tag'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of Tag / tag.
|
||||
*
|
||||
* @param $value string
|
||||
*/
|
||||
public function setTag($value)
|
||||
{
|
||||
$this->validateString('Tag', $value);
|
||||
|
||||
if ($this->data['tag'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['tag'] = $value;
|
||||
|
||||
$this->setModified('tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of Environment / environment.
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ class BuildService
|
|||
* @param string $environment
|
||||
* @param string|null $commitId
|
||||
* @param string|null $branch
|
||||
* @param string|null $tag
|
||||
* @param string|null $committerEmail
|
||||
* @param string|null $commitMessage
|
||||
* @param string|null $extra
|
||||
|
@ -49,6 +50,7 @@ class BuildService
|
|||
$environment,
|
||||
$commitId = null,
|
||||
$branch = null,
|
||||
$tag = null,
|
||||
$committerEmail = null,
|
||||
$commitMessage = null,
|
||||
$extra = null
|
||||
|
@ -75,6 +77,10 @@ class BuildService
|
|||
$build->setBranch($project->getBranch());
|
||||
}
|
||||
|
||||
if (!is_null($tag)) {
|
||||
$build->setTag($tag);
|
||||
}
|
||||
|
||||
if (!is_null($committerEmail)) {
|
||||
$build->setCommitterEmail($committerEmail);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
<a target="_blank" href="<?php print $build->getBranchLink(); ?>">
|
||||
<span class="label label-default"><?php print $build->getBranch(); ?></span>
|
||||
</a>
|
||||
<?php if ($tag = $build->getTag()): ?> /
|
||||
<span class='label label-info'><?= $tag; ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
|
|
@ -59,7 +59,10 @@ $branches = $build->getExtra('branches');
|
|||
</td>
|
||||
<td>
|
||||
<a href="<?php print $build->getBranchLink(); ?>" target="_blank"><?php print $build->getBranch(); ?></a>
|
||||
<?php print $branches ? ' + '.implode(', ', $branches) : ''; ?>
|
||||
<?= $branches ? ' + '.implode(', ', $branches) : ''; ?>
|
||||
<?php if ($tag = $build->getTag()): ?> /
|
||||
<span class='label label-info'><?= $tag; ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
|
|
|
@ -87,7 +87,15 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
|||
$project->setType('hg');
|
||||
$project->setId(101);
|
||||
|
||||
$returnValue = $this->testedService->createBuild($project, null, '123', 'testbranch', 'test@example.com', 'test');
|
||||
$returnValue = $this->testedService->createBuild(
|
||||
$project,
|
||||
null,
|
||||
'123',
|
||||
'testbranch',
|
||||
null,
|
||||
'test@example.com',
|
||||
'test'
|
||||
);
|
||||
|
||||
$this->assertEquals('testbranch', $returnValue->getBranch());
|
||||
$this->assertEquals('123', $returnValue->getCommitId());
|
||||
|
@ -109,7 +117,16 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
|||
$project->setType('bitbucket');
|
||||
$project->setId(101);
|
||||
|
||||
$returnValue = $this->testedService->createBuild($project, null, null, null, null, null, ['item1' => 1001]);
|
||||
$returnValue = $this->testedService->createBuild(
|
||||
$project,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
['item1' => 1001]
|
||||
);
|
||||
|
||||
$this->assertEquals(1001, $returnValue->getExtra('item1'));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue