diff --git a/ahoy.yml b/ahoy.yml index 440ced7e4b552f0f70e2ade0d198290f6ec3ab29..5b094d940239e9e6fdda5f4d0ed8b9cfbc40b253 100644 --- a/ahoy.yml +++ b/ahoy.yml @@ -17,3 +17,6 @@ commands: env -i $(cat .env | xargs) >.env composer lakedrops:dorgflow --no-interaction usage: Turn off dorgflow + issue: + cmd: composer lakedrops:issuefork "$@" --no-interaction + usage: Load an issue fork for a specific project from drupal.org diff --git a/src/CommandProvider.php b/src/CommandProvider.php index 8518e8bf4c38138766ecb57036465e4955ae2ba1..f8a810af8d23d92cd12a61578299753f36d529f5 100644 --- a/src/CommandProvider.php +++ b/src/CommandProvider.php @@ -12,6 +12,7 @@ class CommandProvider implements CommandProviderCapability { public function getCommands(): array { return [ new PrepareCommand(), + new IssueForkCommand(), ]; } } diff --git a/src/Handler.php b/src/Handler.php index decca1b6d954dc3bcd8611a18b50aae83e3f7fc1..200e3adf487844b2f6d45b3694f920ab503e211a 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -116,8 +116,7 @@ class Handler extends BaseHandler { // Already setup correctly. return; } - } - catch (Exception $ex) { + } catch (Exception $ex) { // Ignore the exception and conitue setup. } @@ -126,7 +125,6 @@ class Handler extends BaseHandler { $fs->mkdir($path); $repository->init(); $repository->addRemote('origin', $uri); - $repository->getCaller()->execute('config --add remote.origin.fetch "+refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*"'); $repository->fetch(); $repository->checkout($version); @@ -134,4 +132,50 @@ class Handler extends BaseHandler { $this->io->write(' - completed', TRUE); } + /** + * Load an issue fork for a specific project from drupal.org. + */ + public function loadIssueFork(string $project, string $issue): void { + // We only do the fancy stuff for developers. + if (!$this->isDevMode() || $this->isCiContext()) { + return; + } + + $this->init(); + + $dorgflow = $this->env->receiveGlobal('DORGFLOW', 'Dorgflow', '0'); + if (empty($dorgflow)) { + $this->io->error('Dorgflow is not enabled.'); + return; + } + + $installationManager = $this->composer->getInstallationManager(); + $package = $this->getPackage('drupal/' . $project); + if ($package === NULL) { + $this->io->error('Project not installed.'); + return; + } + $path = $installationManager->getInstallPath($package); + if (!file_exists($path)) { + $this->io->error('Installation path not found: ' . $path); + return; + } + $uri = 'git@git.drupal.org:issue/' . $project . '-' . $issue . '.git'; + $remote = $project . '-issue-' . $issue; + $repository = Repository::open($path); + try { + $origin = $repository->getRemote($remote, FALSE); + if ($origin && $origin->getFetchURL() === $uri) { + // Already setup correctly. + $this->io->info('Already available.'); + return; + } + } catch (Exception $ex) { + // Ignore the exception and conitue setup. + } + $repository->addRemote($remote, $uri); + $repository->fetch($remote); + $this->io->info('Successfully added issue fork.'); + } + } diff --git a/src/IssueForkCommand.php b/src/IssueForkCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..8fc3d54af476b577a0f4e8b5aaebe3f715530f7a --- /dev/null +++ b/src/IssueForkCommand.php @@ -0,0 +1,42 @@ +<?php + +namespace LakeDrops\DorgFlow; + +use LakeDrops\Component\Composer\BaseCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class IssueForkCommand extends BaseCommand { + + /** + * {@inheritdoc} + */ + protected function configure(): void { + parent::configure(); + $this + ->setName('lakedrops:issuefork') + ->addArgument('Project', InputArgument::REQUIRED, 'Name of the project, e.g. core') + ->addArgument('Issue', InputArgument::REQUIRED, 'Number fo the issue') + ->setDescription('Load an issue fork for a specific project from drupal.org.'); + } + + /** + * {@inheritdoc} + */ + public function getHandlerClass(): string { + return Handler::class; + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output): int { + parent::execute($input, $output); + /** @var Handler $handler */ + $handler = $this->handler; + $handler->loadIssueFork($input->getArgument('Project'), $input->getArgument('Issue')); + return 0; + } + +}