forked from deployphp/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbugsnag.php
52 lines (43 loc) · 1.65 KB
/
bugsnag.php
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
<?php
/* (c) Tim Robertson <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
desc('Notifying Bugsnag of deployment');
task('deploy:bugsnag', function () {
global $php_errormsg;
$defaultConfig = [
'api_key' => null,
'release_stage' => get('stages')[0],
'repository' => get('repository'),
'provider' => null,
'branch' => get('branch'),
'revision' => trim(runLocally('git log -n 1 --format="%h"')),
'app_version' => null,
];
$config = array_merge($defaultConfig, (array) get('bugsnag'));
if (!is_array($config) || !isset($config['api_key'])) {
throw new \RuntimeException("Please configure new bugsnag: set('bugsnag', ['api_key' => 'c09a3...', 'release_stage' => 'production']);");
}
$postdata = [
'apiKey' => $config['api_key'],
'releaseStage' => $config['release_stage'],
'repository' => $config['repository'],
'provider' => $config['provider'],
'branch' => $config['branch'],
'revision' => $config['revision'],
'appVersion' => $config['app_version'],
];
$options = array('http' => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => json_encode($postdata),
));
$context = stream_context_create($options);
$result = @file_get_contents('https://notify.bugsnag.com/deploy', false, $context);
if (!$result) {
throw new \RuntimeException($php_errormsg);
}
});