Skip to content

Commit 5531898

Browse files
committed
Fixes to get rebuild working.
1 parent ec8ecbc commit 5531898

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Commands/Env/CodeRebuildCommand.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
use Pantheon\Terminus\Exceptions\TerminusException;
88
use Pantheon\Terminus\Site\SiteAwareInterface;
99
use Pantheon\Terminus\Site\SiteAwareTrait;
10+
use Pantheon\Terminus\Request\RequestAwareInterface;
11+
use Pantheon\Terminus\Request\RequestAwareTrait;
1012

1113
/**
1214
* Class CodeRebuildCommand.
1315
*
1416
* @package Pantheon\Terminus\Commands\Env
1517
*/
16-
class CodeRebuildCommand extends TerminusCommand implements SiteAwareInterface
18+
class CodeRebuildCommand extends TerminusCommand implements SiteAwareInterface, RequestAwareInterface
1719
{
1820
use SiteAwareTrait;
1921
use WorkflowProcessingTrait;
22+
use RequestAwareTrait;
2023

2124
/**
2225
* Moves code to the specified environment's runtime from the associated git branch, retriggering Composer builds for sites using Integrated Composer. (Not applicable for Test and Live environments which run on git tags made from the Dev environment's git history.)
@@ -70,17 +73,42 @@ public function rebuild(
7073
*/
7174
protected function rebuildFromVcs(string $site_id, string $env)
7275
{
73-
$path = sprintf("/vcs/v1/site-details/%s/environments/%s/rebuild", $site_id, $env);
76+
$path = sprintf("%s/vcs/v1/site-details/%s/environments/%s/rebuild", $this->getBaseURI(), $site_id, $env);
7477
$response = $this->request()->request($path, [
7578
'method' => 'POST',
7679
'json' => [],
80+
'headers' => [
81+
'Authorization' => sprintf(
82+
'Bearer %s',
83+
$this->session()->get('session')
84+
),
85+
],
7786
]);
7887
if ($response->getStatusCode() !== 200) {
7988
throw new TerminusException(
8089
'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()]
90+
['site' => $site_id, 'env' => $env, 'response' => $response->getData(), 'status_code' => $response->getStatusCode()]
8291
);
8392
}
8493
$this->log()->info("Rebuild is now happening for site {site} environment {env}.", ['site' => $site_id, 'env' => $env]);
8594
}
95+
96+
/**
97+
* Get API Base Uri.
98+
*/
99+
/**
100+
* Parses the base URI for requests.
101+
*
102+
* @return string
103+
*/
104+
private function getBaseURI()
105+
{
106+
$config = $this->getConfig();
107+
return sprintf(
108+
'%s://%s:%s',
109+
$config->get('protocol'),
110+
$config->get('host'),
111+
$config->get('port')
112+
);
113+
}
86114
}

0 commit comments

Comments
 (0)