Skip to content

Commit

Permalink
feat(export) export pipeline as yaml file (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierozi authored and Frédéric Dewinne committed May 14, 2018
1 parent 9396bd6 commit f28213b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"continuousphp/sdk": "dev-feat/entities",
"continuousphp/sdk": "^0.7",
"symfony/console": "^3.3",
"hoa/console": "~3.0"
},
Expand All @@ -29,7 +29,7 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Pierozi/guzzle-services.git"
"url": "https://github.com/continuousphp/guzzle-services.git"
}
]
}
2 changes: 2 additions & 0 deletions src/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Continuous\Cli\Command\Build\BuildStopCommand;
use Continuous\Cli\Command\Company\CompanyListCommand;
use Continuous\Cli\Command\ConfigureCommand;
use Continuous\Cli\Command\Pipeline\PipelineExportCommand;
use Continuous\Cli\Command\Project\ProjectListCommand;
use Continuous\Cli\Command\Repository\RepositoryListCommand;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -34,6 +35,7 @@ public function create()
$application->add(new BuildListCommand());
$application->add(new BuildStartCommand());
$application->add(new BuildStopCommand());
$application->add(new PipelineExportCommand());

return $application;
}
Expand Down
78 changes: 78 additions & 0 deletions src/Command/Pipeline/PipelineExportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Continuous\Cli\Command\Pipeline;

use Continuous\Cli\Command\CommandAbstract;
use Continuous\Sdk\Collection;
use Continuous\Sdk\Decorator\Pipeline\PipelineExportDecorator;
use Continuous\Sdk\Entity\Pipeline;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class PipelineExportCommand extends CommandAbstract
{
protected function configure()
{
$this
->setName('pipeline:export')
->setDescription('Export pipeline as configuration file.')
->setHelp('This command export a specific pipeline as a configuration file in YAML.')
->addArgument('provider', InputArgument::REQUIRED, 'The repository provider')
->addArgument('repository', InputArgument::REQUIRED, 'The repository name')
->addArgument('ref', InputArgument::REQUIRED, 'The git reference')
;

$this
->addOption(
'output',
'o',
InputOption::VALUE_OPTIONAL,
'File where yaml output will be persisted'
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);

$outFd = 'php://stdout';

if (null !== ($outOpt = $input->getOption('output'))) {
$outFd = getcwd() . DIRECTORY_SEPARATOR . $outOpt;
}

$ref = $input->getArgument('ref');
$params = [
'provider' => static::mapProviderToSdk($input->getArgument('provider')),
'repository' => $input->getArgument('repository'),
'ref' => $input->getArgument('ref'),
];

$this->showLoader($output, 'Loading pipelines...');

/** @var Collection $collection */
$collection = $this->continuousClient->getPipelines($params);
$entity = null;

foreach ($collection->getIterator() as $entity) {
/** @var Pipeline $entity */
if ($ref === $entity->get('settingId')) {
break;
}

$entity = null;
}

$exportDecorator = new PipelineExportDecorator($entity);

$this->hideLoader($output);
file_put_contents($outFd, $exportDecorator->toYaml());
}
}

0 comments on commit f28213b

Please sign in to comment.