Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #71 from funkjedi/bugsnag-recipe
Browse files Browse the repository at this point in the history
Adding a Bugsnag recipe
  • Loading branch information
antonmedv authored Nov 19, 2016
2 parents d3b1fe7 + 281c428 commit c2883d9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require 'vendor/deployer/recipes/cachetool.php';

| Recipe | Docs | Usage
| ------ | ---- | -----
| bugsnag | [read](docs/bugsnag.md) | `require 'vendor/deployer/recipes/bugsnag.php';`
| cachetool | [read](docs/cachetool.md) | `require 'vendor/deployer/recipes/cachetool.php';`
| cloudflare | [read](docs/cloudflare.md) | `require 'vendor/deployer/recipes/cloudflare.php';`
| hipchat | [read](docs/hipchat.md) | `require 'vendor/deployer/recipes/hipchat.php';`
Expand Down
52 changes: 52 additions & 0 deletions bugsnag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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' => env('stages')[0],
'repository' => env('repository'),
'provider' => null,
'branch' => env('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);
}
});
45 changes: 45 additions & 0 deletions docs/bugsnag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Bugsnag recipe

### Installing

```php
// deploy.php

require 'vendor/deployphp/recipes/bugsnag.php';
```

### Configuration options

- **bugsnag** *(required)*: accepts an *array* with the api_key. Key is given by the [Bugsnag website](https://bugsnag.com/).

You can provide also other configuration options:

- *api_key* - The API Key associated with the project. Informs Bugsnag which project has been deployed. This is the only required field.
- *release_stage* - The release stage (eg, production, staging) currently being deployed. (Optional, defaults to **{{stage}}**.)
- *repository* - The URL of the repository containing the source code being deployed. (Optional, defaults to **{{repository}}**.)
- *provider* - The name of your source control provider. Required when repository is supplied and only for on-premise services.
- *branch* - The source control branch from which you are deploying the code. (Optional, defaults to **{{branch}}**.)
- *revision* - The source control revision id for the code you are deploying. (Optional defaults to `git log -n 1 --format="%h"`.)
- *app_version* - The app version of the code you are currently deploying. Only set this if you tag your releases with semantic version numbers and deploy infrequently. (Optional.)

```php
// deploy.php

set('bugsnag', [
'api_key' => "daf9a694....",
]);
```

### Tasks

- `deploy:bugsnag` send message to Bugsnag

### Suggested Usage

Since you should only notify Bugsnag of a successfull deployment, the `deploy:bugsnag` task should be executed right at the end.

```php
// deploy.php

after('deploy', 'deploy:bugsnag');
```

0 comments on commit c2883d9

Please sign in to comment.