Skip to content

Deploy notify command #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/RollbarDeployNotify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Jenssegers\Rollbar;

use Illuminate\Console\Command;

class RollbarDeployNotify extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'rollbar:deploynotify';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Notify rollbar of a deployment';
private $accesssToken;

public function __construct($config)
{
parent::__construct();
$this->accesssToken = $config['access_token'];
}

public function fire()
{
$this->comment("hello");

$environment = env('APP_ENV');
$localUserName = exec('whoami');
$revision = exec('git log -n 1 --pretty=format:"%H"');

$fields_string = "";
$url = "https://api.rollbar.com/api/1/deploy/";
$fields = [
'environment' => urlencode($environment),
'local_username' => urlencode($localUserName),
'revision' => urlencode($revision),
'access_token' => urlencode($this->accesssToken),
];

foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);

curl_close($ch);
}
}
18 changes: 17 additions & 1 deletion src/RollbarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public function register()

return new RollbarLogHandler($client, $app, $level);
});

$this->app->singleton('command.rollbar.deploynotify', function($app)
{
$config = $app['config']->get('services.rollbar');

return new RollbarDeployNotify($config);
});

$this->commands('command.rollbar.deploynotify');


// If the Rollbar client was resolved, then there is a possibility that there
// are unsent error messages in the internal queue, so let's flush them.
Expand All @@ -83,5 +93,11 @@ public function register()
}
});
}


public function provides()
{
return [
'command.rollbar.deploynotify',
];
}
}