Skip to content

Commit

Permalink
Added a way to signify deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Aug 3, 2016
1 parent abe651f commit f458927
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Client.php
Expand Up @@ -229,6 +229,34 @@ public function notify(Report $report, callable $callback = null)
}
}

/**
* Notify Bugsnag of a deployment.
*
* @param string|null $repository the repository from which you are deploying the code
* @param string|null $branch the source control branch from which you are deploying
* @param string|null $revision the source control revision you are currently deploying
*
* @return void
*/
public function deploy($repository = null, $branch = null, $revision = null)
{
$data = [];

if ($repository) {
$data['repository'] = $repository;
}

if ($branch) {
$data['branch'] = $branch;
}

if ($revision) {
$data['revision'] = $revision;
}

$this->http->deploy($data);
}

/**
* Flush any buffered reports.
*
Expand Down
22 changes: 22 additions & 0 deletions src/HttpClient.php
Expand Up @@ -55,6 +55,28 @@ public function queue(Report $report)
$this->queue[] = $report;
}

/**
* Notify Bugsnag of a deployment.
*
* @param array $data the deployment information
*
* @return void
*/
public function deploy(array $data)
{
$app = $this->config->getAppData();

$data['releaseStage'] = $app['releaseStage'];

if (isset($app['version'])) {
$data['appVersion'] = $app['version'];
}

$data['apiKey'] = $this->config->getApiKey();

$this->guzzle->request('POST', 'deploy', ['json' => $data]);
}

/**
* Deliver everything on the queue to Bugsnag.
*
Expand Down
70 changes: 70 additions & 0 deletions tests/ClientTest.php
Expand Up @@ -203,4 +203,74 @@ public function testCanManuallyFlush()
$this->client->flush();
$this->client->flush();
}

public function testDeployWorksOutOfTheBox()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['releaseStage' => 'production', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->client->deploy();
}

public function testDeployWorksWithgReleaseStage()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['releaseStage' => 'staging', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->config->setReleaseStage('staging');

$this->client->deploy();
}

public function testDeployWorksWithAppVersion()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['releaseStage' => 'production', 'appVersion' => '1.1.0', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->config->setAppVersion('1.1.0');

$this->client->deploy();
}

public function testDeployWorksWithRepository()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['repository' => 'foo', 'releaseStage' => 'production', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->client->deploy('foo');
}

public function testDeployWorksWithBranch()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['branch' => 'master', 'releaseStage' => 'production', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->client->deploy(null, 'master');
}

public function testDeployWorksWithRevision()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['revision' => 'bar', 'releaseStage' => 'production', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->client->deploy(null, null, 'bar');
}

public function testDeployWorksWithEverything()
{
$this->guzzle->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('deploy'), $this->equalTo(['json' => ['repository' => 'baz', 'branch' => 'develop', 'revision' => 'foo', 'releaseStage' => 'development', 'appVersion' => '1.3.1', 'apiKey' => 'example-api-key']]));

$this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);

$this->config->setReleaseStage('development');
$this->config->setAppVersion('1.3.1');

$this->client->deploy('baz', 'develop', 'foo');
}
}

0 comments on commit f458927

Please sign in to comment.