Refactored project structure.
This commit is contained in:
parent
cfe93434ad
commit
c015d8c58b
308 changed files with 39 additions and 47 deletions
81
src/Plugin/Deployer.php
Normal file
81
src/Plugin/Deployer.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Plugin;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* Integration with Deployer: https://github.com/rebelinblue/deployer
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class Deployer extends Plugin
|
||||
{
|
||||
protected $webhookUrl;
|
||||
protected $reason;
|
||||
protected $updateOnly;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function pluginName()
|
||||
{
|
||||
return 'deployer';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->reason = 'PHP Censor Build #%BUILD% - %COMMIT_MESSAGE%';
|
||||
if (isset($options['webhook_url'])) {
|
||||
$this->webhookUrl = $options['webhook_url'];
|
||||
}
|
||||
|
||||
if (isset($options['reason'])) {
|
||||
$this->reason = $options['reason'];
|
||||
}
|
||||
|
||||
$this->updateOnly = isset($options['update_only']) ? (bool) $options['update_only'] : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies files from the root of the build directory into the target folder
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (empty($this->webhookUrl)) {
|
||||
$this->builder->logFailure('You must specify a webhook URL.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->post(
|
||||
$this->webhookUrl,
|
||||
[
|
||||
'form_params' => [
|
||||
'reason' => $this->builder->interpolate($this->reason),
|
||||
'source' => 'PHP Censor',
|
||||
'url' => $this->builder->interpolate('%BUILD_URI%'),
|
||||
'branch' => $this->builder->interpolate('%BRANCH%'),
|
||||
'commit' => $this->builder->interpolate('%COMMIT%'),
|
||||
'update_only' => $this->updateOnly,
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$status = (integer)$response->getStatusCode();
|
||||
|
||||
return (
|
||||
($status >= 200 && $status < 300)
|
||||
? true
|
||||
: false
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue