Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Oct 20, 2023
1 parent d6568f0 commit 4b4cfd1
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/Command/Push/PushArtifactCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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);

Check warning on line 75 in src/Command/Push/PushArtifactCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/Push/PushArtifactCommand.php#L74-L75

Added lines #L74 - L75 were not covered by tests
}
if ($input->getOption('no-commit')) {
$input->setOption('no-push', TRUE);

Check warning on line 78 in src/Command/Push/PushArtifactCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/Push/PushArtifactCommand.php#L78

Added line #L78 was not covered by tests
}
$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');
Expand All @@ -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();
Expand All @@ -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');

Check warning on line 111 in src/Command/Push/PushArtifactCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $destinationGitUrlsString = implode(',', $destinationGitUrls); $refType = $this->input->getOption('destination-git-tag') ? 'tag' : 'branch'; $this->io->note(["Acquia CLI will:", "- git clone {$sourceGitBranch} from {$destinationGitUrls[0]}", "- Compile the contents of {$this->dir} into an artifact in a temporary directory", "- Copy the artifact files into the checked out copy of {$sourceGitBranch}", "- Commit changes and push the {$destinationGitRef} {$refType} to the following git remote(s):", " {$destinationGitUrlsString}"]); - $this->checklist->addItem('Preparing artifact directory'); + $this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch); $this->checklist->completePreviousItem(); }
$this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch);
$this->checklist->completePreviousItem();

Check warning on line 113 in src/Command/Push/PushArtifactCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $this->io->note(["Acquia CLI will:", "- git clone {$sourceGitBranch} from {$destinationGitUrls[0]}", "- Compile the contents of {$this->dir} into an artifact in a temporary directory", "- Copy the artifact files into the checked out copy of {$sourceGitBranch}", "- Commit changes and push the {$destinationGitRef} {$refType} to the following git remote(s):", " {$destinationGitUrlsString}"]); $this->checklist->addItem('Preparing artifact directory'); $this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch); - $this->checklist->completePreviousItem(); + } $this->checklist->addItem('Generating build artifact'); $this->buildArtifact($outputCallback, $artifactDir);
Expand All @@ -122,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->checklist->completePreviousItem();

Check warning on line 129 in src/Command/Push/PushArtifactCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ if (!$input->getOption('no-commit')) { $this->checklist->addItem("Committing changes (commit hash: {$commitHash})"); $this->commit($outputCallback, $artifactDir, $commitHash); - $this->checklist->completePreviousItem(); + } if (!$input->getOption('dry-run') && !$input->getOption('no-push')) { if ($tagName = $input->getOption('destination-git-tag')) {
}

if (!$input->getOption('dry-run')) {
if (!$input->getOption('dry-run') && !$input->getOption('no-push')) {

Check warning on line 132 in src/Command/Push/PushArtifactCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $this->commit($outputCallback, $artifactDir, $commitHash); $this->checklist->completePreviousItem(); } - if (!$input->getOption('dry-run') && !$input->getOption('no-push')) { + if (!$input->getOption('dry-run') || !$input->getOption('no-push')) { if ($tagName = $input->getOption('destination-git-tag')) { $this->checklist->addItem("Creating <options=bold>{$tagName}</> tag."); $this->createTag($tagName, $outputCallback, $artifactDir);
if ($tagName = $input->getOption('destination-git-tag')) {
$this->checklist->addItem("Creating <options=bold>$tagName</> tag.");
$this->createTag($tagName, $outputCallback, $artifactDir);
Expand All @@ -137,13 +144,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->checklist->completePreviousItem();
}
else {
$this->logger->warning("The <options=bold>--dry-run</> option prevented changes from being pushed to Acquia Cloud. The artifact has been built at <options=bold>$artifactDir</>");
$this->logger->warning("The <options=bold>--dry-run</> (deprecated) or <options=bold>--no-push</> option prevented changes from being pushed to Acquia Cloud. The artifact has been built at <options=bold>$artifactDir</>");

Check warning on line 147 in src/Command/Push/PushArtifactCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/Push/PushArtifactCommand.php#L147

Added line #L147 was not covered by tests
}

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');
}
Expand Down Expand Up @@ -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');
}
Expand All @@ -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;
Expand Down

0 comments on commit 4b4cfd1

Please sign in to comment.