-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathDeployer.php
More file actions
85 lines (72 loc) · 2.21 KB
/
Copy pathDeployer.php
File metadata and controls
85 lines (72 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?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
*
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class Deployer extends Plugin
{
protected $webhookUrl;
protected $reason = 'PHP Censor Build #%BUILD_ID% - %COMMIT_MESSAGE%';
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);
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, true),
'source' => 'PHP Censor',
'url' => $this->builder->interpolate('%BUILD_LINK%', true),
'branch' => $this->builder->interpolate('%BRANCH%', true),
'commit' => $this->builder->interpolate('%COMMIT_ID%', true),
'update_only' => $this->updateOnly,
]
]
);
$status = (int)$response->getStatusCode();
return (
($status >= 200 && $status < 300)
? true
: false
);
}
}