Skip to content

Commit

Permalink
CLI-1377 Delay API lookup of application by ID (#1781)
Browse files Browse the repository at this point in the history
* CLI-1377 Delay API lookup of application by ID

* move api call

* fix phpcs and remove ignored mocks

* remove mocks from testPushArtifactWithArgs

* remove mocks from testCloudAppFromLocalConfig

* put back getApplicationIdes mock

---------

Co-authored-by: Dane Powell <[email protected]>
  • Loading branch information
mglaman and danepowell authored Sep 9, 2024
1 parent 9960580 commit f4fa8e7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,12 +878,13 @@ protected function determineCloudApplication(bool $promptLinkApp = false): ?stri
throw new AcquiaCliException("Could not determine Cloud Application. Run this command interactively or use `acli link` to link a Cloud Application before running non-interactively.");
}

$application = $this->getCloudApplication($applicationUuid);
// No point in trying to link a directory that's not a repo.
if (!empty($this->projectDir) && !$this->getCloudUuidFromDatastore()) {
if ($promptLinkApp) {
$application = $this->getCloudApplication($applicationUuid);
$this->saveCloudUuidToDatastore($application);
} elseif (!AcquiaDrupalEnvironmentDetector::isAhIdeEnv() && !$this->getCloudApplicationUuidFromBltYaml()) {
$application = $this->getCloudApplication($applicationUuid);
$this->promptLinkApplication($application);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Command/Push/PushArtifactCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$destinationGitUrls = [];
$destinationGitRef = '';
if (!$input->getOption('no-clone')) {
$applicationUuid = $this->determineCloudApplication();
$destinationGitUrls = $this->determineDestinationGitUrls($applicationUuid);
$destinationGitUrls = $this->determineDestinationGitUrls();
$destinationGitRef = $this->determineDestinationGitRef();
$sourceGitBranch = $this->determineSourceGitRef();
$destinationGitUrlsString = implode(',', $destinationGitUrls);
Expand Down Expand Up @@ -153,18 +152,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* @return string[]
*/
private function determineDestinationGitUrls(?string $applicationUuid): array
private function determineDestinationGitUrls(): array
{
if ($this->input->getOption('destination-git-urls')) {
return $this->input->getOption('destination-git-urls');
}
if ($envVar = getenv('ACLI_PUSH_ARTIFACT_DESTINATION_GIT_URLS')) {
return explode(',', $envVar);
}

if ($this->datastoreAcli->get('push.artifact.destination-git-urls')) {
return $this->datastoreAcli->get('push.artifact.destination-git-urls');
}

$applicationUuid = $this->determineCloudApplication();
return [$this->getAnyVcsUrl($applicationUuid)];
}

Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/src/Commands/CommandBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function testUnauthenticatedFailure(): void
public function testCloudAppFromLocalConfig(): void
{
$this->command = $this->injectCommand(IdeListCommand::class);
$this->mockRequest('getApplicationByUuid', 'a47ac10b-58cc-4372-a567-0e02b2c3d470');
$this->mockRequest('getApplicationIdes', 'a47ac10b-58cc-4372-a567-0e02b2c3d470');
$this->createMockAcliConfigFile('a47ac10b-58cc-4372-a567-0e02b2c3d470');
$this->executeCommand();
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ public function testPushTagArtifact(): void

public function testPushArtifactWithAcquiaCliFile(): void
{
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[0]->uuid);
$this->mockRequest('getApplicationEnvironments', $applications[0]->uuid);
$this->datastoreAcli->set('push.artifact.destination-git-urls', [
'https://github.com/example1/cli.git',
'https://github.com/example2/cli.git',
Expand All @@ -143,9 +140,6 @@ public function testPushArtifactWithAcquiaCliFile(): void

public function testPushArtifactWithArgs(): void
{
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[0]->uuid);
$this->mockRequest('getApplicationEnvironments', $applications[0]->uuid);
$destinationGitUrls = [
'https://github.com/example1/cli.git',
'https://github.com/example2/cli.git',
Expand Down

0 comments on commit f4fa8e7

Please sign in to comment.