Skip to content

Commit

Permalink
Adds code switch and deploy methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent f35b5b0 commit 52d0de7
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AcquiaCli\Commands;

use AcquiaCloudApi\Response\BranchResponse;
use AcquiaCloudApi\Response\EnvironmentResponse;
use Symfony\Component\Console\Helper\Table;
use AcquiaCloudApi\Endpoints\Code;

Expand All @@ -20,6 +21,7 @@ class CodeCommand extends AcquiaCommand
* @param string $match A string to filter out specific code branches with.
*
* @command code:list
* @aliases c:l
*/
public function code($uuid, $match = null)
{
Expand Down Expand Up @@ -48,4 +50,74 @@ public function code($uuid, $match = null)
$table->render();
}
/**
* Deploys code from one environment to another.
*
* @param string $uuid
* @param EnvironmentResponse $environmentFrom
* @param EnvironmentResponse $environmentTo
*
* @command code:deploy
* @aliases c:d
*/
public function codeDeploy(
$uuid,
EnvironmentResponse $environmentFrom,
EnvironmentResponse $environmentTo
) {
if (!$this->confirm(
sprintf(
'Are you sure you want to deploy code from %s to %s?',
$environmentFrom->label,
$environmentTo->label
)
)) {
return;
}
$this->backupAllEnvironmentDbs($uuid, $environmentTo);
$this->say(
sprintf(
'Deploying code from the %s environment to the %s environment',
$environmentFrom->label,
$environmentTo->label
)
);
$code = new Code($this->cloudapi);
$response = $code->deploy($environmentFrom->uuid, $environmentTo->uuid);
$this->waitForNotification($response);
}
/**
* Switches code branch on an environment.
*
* @param string $uuid
* @param EnvironmentResponse $environment
* @param string $branch
*
* @command code:switch
* @aliases c:s
*/
public function codeSwitch($uuid, EnvironmentResponse $environment, $branch)
{
if (!$this->confirm(
sprintf(
'Are you sure you want to switch code on the %s environment to branch: %s?',
$environment->name,
$branch
)
)) {
return;
}
$this->backupAllEnvironmentDbs($uuid, $environment);
$this->say(sprintf('Switching %s enviroment to %s branch', $environment->label, $branch));
$code = new Code($this->cloudapi);
$response = $code->switch($environment->uuid, $branch);
$this->waitForNotification($response);
}
}

0 comments on commit 52d0de7

Please sign in to comment.