Skip to content
Snippets Groups Projects
Commit 4f488a9c authored by jurgenhaas's avatar jurgenhaas
Browse files

#7 Add command to download issue fork

parent ac313867
No related branches found
No related tags found
No related merge requests found
...@@ -17,3 +17,6 @@ commands: ...@@ -17,3 +17,6 @@ commands:
env -i $(cat .env | xargs) >.env env -i $(cat .env | xargs) >.env
composer lakedrops:dorgflow --no-interaction composer lakedrops:dorgflow --no-interaction
usage: Turn off dorgflow usage: Turn off dorgflow
issue:
cmd: composer lakedrops:issuefork "$@" --no-interaction
usage: Load an issue fork for a specific project from drupal.org
...@@ -12,6 +12,7 @@ class CommandProvider implements CommandProviderCapability { ...@@ -12,6 +12,7 @@ class CommandProvider implements CommandProviderCapability {
public function getCommands(): array { public function getCommands(): array {
return [ return [
new PrepareCommand(), new PrepareCommand(),
new IssueForkCommand(),
]; ];
} }
} }
...@@ -116,8 +116,7 @@ class Handler extends BaseHandler { ...@@ -116,8 +116,7 @@ class Handler extends BaseHandler {
// Already setup correctly. // Already setup correctly.
return; return;
} }
} } catch (Exception $ex) {
catch (Exception $ex) {
// Ignore the exception and conitue setup. // Ignore the exception and conitue setup.
} }
...@@ -126,7 +125,6 @@ class Handler extends BaseHandler { ...@@ -126,7 +125,6 @@ class Handler extends BaseHandler {
$fs->mkdir($path); $fs->mkdir($path);
$repository->init(); $repository->init();
$repository->addRemote('origin', $uri); $repository->addRemote('origin', $uri);
$repository->getCaller()->execute('config --add remote.origin.fetch "+refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*"');
$repository->fetch(); $repository->fetch();
$repository->checkout($version); $repository->checkout($version);
...@@ -134,4 +132,50 @@ class Handler extends BaseHandler { ...@@ -134,4 +132,50 @@ class Handler extends BaseHandler {
$this->io->write(' - completed', TRUE); $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.');
}
} }
<?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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment