Skip to content

Commit ec8ecbc

Browse files
committed
Rebuild from vcs for evcs sites.
1 parent f61cb52 commit ec8ecbc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Commands/Env/CodeRebuildCommand.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public function rebuild(
4040
$site = $this->getSiteById($site_env);
4141
$env = $this->getEnv($site_env);
4242

43+
if ($site->isEvcs()) {
44+
if (($env->getName() === 'test' || $env->getName() === 'live') && !$site->isNodejs()) {
45+
// Rebuilding for test/live is only supported for Node.js sites.
46+
throw new TerminusException('Rebuilding for test/live is only supported for Node.js sites.');
47+
}
48+
return $this->rebuildFromVcs($site->get('id'), $env->getName());
49+
}
50+
4351
if ($env->getName() === 'test' || $env->getName() === 'live') {
4452
throw new TerminusException('Test and live are not valid environments for this command.');
4553
}
@@ -56,4 +64,23 @@ public function rebuild(
5664
$this->processWorkflow($workflow);
5765
$this->log()->notice($workflow->getMessage());
5866
}
67+
68+
/**
69+
* Rebuild from latest vcs event.
70+
*/
71+
protected function rebuildFromVcs(string $site_id, string $env)
72+
{
73+
$path = sprintf("/vcs/v1/site-details/%s/environments/%s/rebuild", $site_id, $env);
74+
$response = $this->request()->request($path, [
75+
'method' => 'POST',
76+
'json' => [],
77+
]);
78+
if ($response->getStatusCode() !== 200) {
79+
throw new TerminusException(
80+
'Failed to rebuild from VCS for site {site} environment {env}. Response: {response}. Status Code: {status_code}',
81+
['site' => $site_id, 'env' => $env, 'response' => $response->getBody(), 'status_code' => $response->getStatusCode()]
82+
);
83+
}
84+
$this->log()->info("Rebuild is now happening for site {site} environment {env}.", ['site' => $site_id, 'env' => $env]);
85+
}
5986
}

0 commit comments

Comments
 (0)