diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index d55e3ca6a..fae3bca9a 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -97,7 +97,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Get Cloud application. $cloudApplication = $this->getCloudApplication($appUuid); $project = $this->determineGitLabProject($cloudApplication); - $projectId = $project['id']; $this->io->writeln([ "", @@ -115,15 +114,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $projectAccessTokenName = 'acquia-codestudio'; $projectAccessToken = $this->createProjectAccessToken($project, $projectAccessTokenName); $this->updateGitLabProject($project); - $ciPath = 'gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml@acquia/node-template'; - $hostPath = $this->getGitLabHost(); - $curlCommand = $this->getCurlCommand($projectAccessToken, $hostPath, $projectId, $ciPath); switch ($projectSelected) { case "Drupal_project": $this->setGitLabCiCdVariablesForPhpProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); break; case "Node_project": - $this->invokeCurlCommand($curlCommand); + $parameters = [ + 'ci_config_path' => 'gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml@acquia/node-template', + ]; + $client = $this->getGitLabClient(); + $client->projects()->update($project['id'], $parameters); $this->setGitLabCiCdVariablesForNodeProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); break; } @@ -181,11 +181,6 @@ private function getListOfProjectType(): ?array { return $array; } - public function getCurlCommand(string $projectAccessToken, string $hostPath, int $projectId, string $ciPath): string { - $curlCommandString = 'curl -s -N -k -L --request PUT --header "PRIVATE-TOKEN: ' . $projectAccessToken . '" --url ' . $hostPath . '/api/v4/projects/' . $projectId . ' --data "ci_config_path=' . $ciPath . '"'; - return $curlCommandString; - } - private function createProjectAccessToken(array $project, string $projectAccessTokenName): string { $this->io->writeln("Creating project access token..."); diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index a6b727dce..307a65f27 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -1572,14 +1572,6 @@ protected function createMySqlDumpOnLocal(string $dbHost, string $dbUser, string return $localFilepath; } - protected function invokeCurlCommand(string $command, Closure $outputCallback = NULL): void { - $this->localMachineHelper->checkRequiredBinariesExist(['curl']); - $process = $this->localMachineHelper->executeFromCmd($command, $outputCallback, NULL, ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL)); - if (!$process->isSuccessful()) { - throw new AcquiaCliException('Unable to execute curl command. {error_message}', ['error_message' => $process->getErrorOutput()]); - } - } - protected function promptOpenBrowserToCreateToken( InputInterface $input ): void { diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index 0e18fd0ce..6a9c09b8c 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -384,15 +384,6 @@ protected function mockCreateMySqlDumpOnLocal(ObjectProphecy $localMachineHelper ->shouldBeCalled(); } - protected function mockCurlCommand(ObjectProphecy $localMachineHelper): void { - $localMachineHelper->checkRequiredBinariesExist(["curl"])->shouldBeCalled(); - $process = $this->mockProcess(); - $process->getOutput()->willReturn(''); - $command = $this->getCurlString(); - $localMachineHelper->executeFromCmd($command, Argument::type('callable'), NULL, TRUE)->willReturn($process->reveal()) - ->shouldBeCalled(); - } - protected function mockExecutePvExists( ObjectProphecy $localMachineHelper, bool $pvExists = TRUE diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 28fa8e408..e431dcf12 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -30,7 +30,6 @@ class CodeStudioWizardCommandTest extends WizardTestBase { private string $gitLabHost = 'gitlabhost'; private string $gitLabToken = 'gitlabtoken'; - private string $ciPath = 'ciPath'; private int $gitLabProjectId = 33; private int $gitLabTokenId = 118; @@ -315,6 +314,13 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a Argument::type('string'), )->shouldBeCalled(); $this->mockGitLabVariables($this->gitLabProjectId, $projects); + + if ($inputs[0] === 'y' && ($inputs[1] === '1' || (array_key_exists(3, $inputs) && $inputs[3] === '1'))) { + $parameters = [ + 'ci_config_path' => 'gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml@acquia/node-template', + ]; + $projects->update($this->gitLabProjectId, $parameters)->shouldBeCalled(); + } $schedules = $this->prophet->prophesize(Schedules::class); $schedules->showAll($this->gitLabProjectId)->willReturn([]); $pipeline = ['id' => 1]; @@ -349,10 +355,6 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a $this->mockGitlabGetHost($localMachineHelper, $this->gitLabHost); $this->mockGitlabGetToken($localMachineHelper, $this->gitLabToken, $this->gitLabHost); - if ($inputs[0] == 'y' && $inputs[1] == '1' ) { - $this->mockCurlCommand($localMachineHelper); - } - /** @var Filesystem|ObjectProphecy $fileSystem */ $fileSystem = $this->prophet->prophesize(Filesystem::class); // Set properties and execute. @@ -364,9 +366,6 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a } // Assertions. - $curlCommand = $this->command->getCurlCommand($this->gitLabToken, $this->gitLabHost, $this->gitLabProjectId, $this->ciPath); - $curlString = $this->getCurlString(); - self::assertStringContainsString($curlString, $curlCommand); $this->assertEquals(0, $this->getStatusCode()); } diff --git a/tests/phpunit/src/Commands/WizardTestBase.php b/tests/phpunit/src/Commands/WizardTestBase.php index 7cdaf9582..b22a98d80 100644 --- a/tests/phpunit/src/Commands/WizardTestBase.php +++ b/tests/phpunit/src/Commands/WizardTestBase.php @@ -162,12 +162,4 @@ protected function getOutputStrings(): array { ]; } - /** - * @return string - * A strings to inspect the output for. - */ - protected function getCurlString(): string { - return 'curl -s -N -k -L --request PUT --header "PRIVATE-TOKEN: gitlabtoken" --url gitlabhost/api/v4/projects/33 --data "ci_config_path=ciPath"'; - } - }