-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeployer.php
More file actions
88 lines (74 loc) · 2.32 KB
/
Copy pathDeployer.php
File metadata and controls
88 lines (74 loc) · 2.32 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
86
87
88
<?php
declare(strict_types=1);
namespace PHPCensor\Plugins\Deploy;
use GuzzleHttp\Client as HttpClient;
use PHPCensor\Common\Build\BuildInterface;
use PHPCensor\Common\Plugin\Plugin;
/**
* Integration with Deployer: https://github.com/rebelinblue/deployer
*
* @package PHP Censor
* @subpackage Plugins
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
* @author Dan Cryer <dan@block8.co.uk>
*/
class Deployer extends Plugin
{
private string $webhookUrl = '';
private string $reason = '';
private bool $updateOnly = true;
/**
* {@inheritDoc}
*/
public static function getName(): string
{
return 'deployer';
}
/**
* {@inheritDoc}
*/
public function execute(): bool
{
if (empty($this->webhookUrl)) {
$this->buildLogger->logFailure('You must specify a webhook URL.');
return false;
}
$client = new HttpClient();
$response = $client->post(
$this->webhookUrl,
[
'form_params' => [
'reason' => $this->variableInterpolator->interpolate($this->reason),
'source' => 'PHP Censor',
'url' => $this->variableInterpolator->interpolate('%BUILD_LINK%'),
'branch' => $this->variableInterpolator->interpolate('%BRANCH%'),
'commit' => $this->variableInterpolator->interpolate('%COMMIT_ID%'),
'update_only' => $this->updateOnly,
],
]
);
$status = $response->getStatusCode();
return ($status >= 200 && $status < 300);
}
/**
* {@inheritDoc}
*/
public static function canExecute(string $stage, BuildInterface $build): bool
{
if (BuildInterface::STAGE_DEPLOY === $stage) {
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
protected function initPluginSettings(): void
{
$this->reason = 'PHP Censor Build #%BUILD_ID% - %COMMIT_MESSAGE%';
$this->webhookUrl = (string)$this->options->get('webhook_url', $this->webhookUrl);
$this->reason = (string)$this->options->get('reason', $this->reason);
$this->updateOnly = (bool)$this->options->get('update_only', $this->updateOnly);
}
}