From 4b4cfd1eb902104b889e88ce7e312625f2b34acb Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Fri, 20 Oct 2023 15:06:54 -0700 Subject: [PATCH] cleanup --- src/Command/Push/PushArtifactCommand.php | 36 +++++++++++++++--------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 021689c8d..d92a1f65c 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -47,9 +47,10 @@ protected function configure(): void { $this->setDescription('Build and push a code artifact to a Cloud Platform environment') ->addOption('dir', NULL, InputArgument::OPTIONAL, 'The directory containing the Drupal project to be pushed') ->addOption('no-sanitize', NULL, InputOption::VALUE_NONE, 'Do not sanitize the build artifact') - ->addOption('dry-run', NULL, InputOption::VALUE_NONE, 'Do not push changes to Acquia Cloud') - ->addOption('no-clone', NULL, InputOption::VALUE_NONE) - ->addOption('no-commit', NULL, InputOption::VALUE_NONE) + ->addOption('dry-run', NULL, InputOption::VALUE_NONE, 'Deprecated: Use no-push instead') + ->addOption('no-push', NULL, InputOption::VALUE_NONE, 'Do not push changes to Acquia Cloud') + ->addOption('no-clone', NULL, InputOption::VALUE_NONE, 'Do not clone repository. Implies no-commit and no-push') + ->addOption('no-commit', NULL, InputOption::VALUE_NONE, 'Do not commit changes. Implies no-push') ->addOption('destination-git-urls', 'u', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'The URL(s) of your git repository to which the artifact branch will be pushed') ->addOption('destination-git-branch', 'b', InputOption::VALUE_REQUIRED, 'The destination branch to push the artifact to') ->addOption('destination-git-tag', 't', InputOption::VALUE_REQUIRED, 'The destination tag to push the artifact to. Using this option requires also using the --source-git-tag option') @@ -69,6 +70,13 @@ protected function commandRequiresAuthentication(): bool { protected function execute(InputInterface $input, OutputInterface $output): int { $this->setDirAndRequireProjectCwd($input); + if ($input->getOption('no-clone')) { + $input->setOption('no-commit', TRUE); + $input->setOption('no-push', TRUE); + } + if ($input->getOption('no-commit')) { + $input->setOption('no-push', TRUE); + } $artifactDir = Path::join(sys_get_temp_dir(), 'acli-push-artifact'); $this->composerJsonPath = Path::join($this->dir, 'composer.json'); $this->docrootPath = Path::join($this->dir, 'docroot'); @@ -80,8 +88,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new AcquiaCliException('Pushing code was aborted because your local Git repository has uncommitted changes. Either commit, reset, or stash your changes via git.'); } $this->checklist = new Checklist($output); + $outputCallback = $this->getOutputCallback($output, $this->checklist); - if (!$input->getOption('no-clone') || !$input->getOption('dry-run')) { + $destinationGitUrls = []; + $destinationGitRef = ''; + if (!$input->getOption('no-clone')) { $applicationUuid = $this->determineCloudApplication(); $destinationGitUrls = $this->determineDestinationGitUrls($applicationUuid); $destinationGitRef = $this->determineDestinationGitRef(); @@ -96,11 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int "- Commit changes and push the $destinationGitRef $refType to the following git remote(s):", " $destinationGitUrlsString", ]); - } - $outputCallback = $this->getOutputCallback($output, $this->checklist); - - if (!$input->getOption('no-clone')) { $this->checklist->addItem('Preparing artifact directory'); $this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch); $this->checklist->completePreviousItem(); @@ -122,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->checklist->completePreviousItem(); } - if (!$input->getOption('dry-run')) { + if (!$input->getOption('dry-run') && !$input->getOption('no-push')) { if ($tagName = $input->getOption('destination-git-tag')) { $this->checklist->addItem("Creating $tagName tag."); $this->createTag($tagName, $outputCallback, $artifactDir); @@ -137,13 +144,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->checklist->completePreviousItem(); } else { - $this->logger->warning("The --dry-run option prevented changes from being pushed to Acquia Cloud. The artifact has been built at $artifactDir"); + $this->logger->warning("The --dry-run (deprecated) or --no-push option prevented changes from being pushed to Acquia Cloud. The artifact has been built at $artifactDir"); } return Command::SUCCESS; } - private function determineDestinationGitUrls(?string $applicationUuid): mixed { + /** + * @return string[] + */ + private function determineDestinationGitUrls(?string $applicationUuid): array { if ($this->input->getOption('destination-git-urls')) { return $this->input->getOption('destination-git-urls'); } @@ -393,7 +403,7 @@ private function validateSourceCode(): void { } } - private function determineSourceGitRef(): mixed { + private function determineSourceGitRef(): string { if ($this->input->getOption('source-git-tag')) { return $this->input->getOption('source-git-tag'); } @@ -408,7 +418,7 @@ private function determineSourceGitRef(): mixed { return $this->destinationGitRef; } - private function determineDestinationGitRef(): mixed { + private function determineDestinationGitRef(): string { if ($this->input->getOption('destination-git-tag')) { $this->destinationGitRef = $this->input->getOption('destination-git-tag'); return $this->destinationGitRef;