Skip to content

Commit f28213b

Browse files
PieroziFrédéric Dewinne
authored andcommitted
feat(export) export pipeline as yaml file (#14)
1 parent 9396bd6 commit f28213b

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"continuousphp/sdk": "dev-feat/entities",
13+
"continuousphp/sdk": "^0.7",
1414
"symfony/console": "^3.3",
1515
"hoa/console": "~3.0"
1616
},
@@ -29,7 +29,7 @@
2929
"repositories": [
3030
{
3131
"type": "vcs",
32-
"url": "https://github.com/Pierozi/guzzle-services.git"
32+
"url": "https://github.com/continuousphp/guzzle-services.git"
3333
}
3434
]
3535
}

src/ApplicationFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Continuous\Cli\Command\Build\BuildStopCommand;
88
use Continuous\Cli\Command\Company\CompanyListCommand;
99
use Continuous\Cli\Command\ConfigureCommand;
10+
use Continuous\Cli\Command\Pipeline\PipelineExportCommand;
1011
use Continuous\Cli\Command\Project\ProjectListCommand;
1112
use Continuous\Cli\Command\Repository\RepositoryListCommand;
1213
use Symfony\Component\Console\Application;
@@ -34,6 +35,7 @@ public function create()
3435
$application->add(new BuildListCommand());
3536
$application->add(new BuildStartCommand());
3637
$application->add(new BuildStopCommand());
38+
$application->add(new PipelineExportCommand());
3739

3840
return $application;
3941
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Continuous\Cli\Command\Pipeline;
4+
5+
use Continuous\Cli\Command\CommandAbstract;
6+
use Continuous\Sdk\Collection;
7+
use Continuous\Sdk\Decorator\Pipeline\PipelineExportDecorator;
8+
use Continuous\Sdk\Entity\Pipeline;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
class PipelineExportCommand extends CommandAbstract
15+
{
16+
protected function configure()
17+
{
18+
$this
19+
->setName('pipeline:export')
20+
->setDescription('Export pipeline as configuration file.')
21+
->setHelp('This command export a specific pipeline as a configuration file in YAML.')
22+
->addArgument('provider', InputArgument::REQUIRED, 'The repository provider')
23+
->addArgument('repository', InputArgument::REQUIRED, 'The repository name')
24+
->addArgument('ref', InputArgument::REQUIRED, 'The git reference')
25+
;
26+
27+
$this
28+
->addOption(
29+
'output',
30+
'o',
31+
InputOption::VALUE_OPTIONAL,
32+
'File where yaml output will be persisted'
33+
);
34+
}
35+
36+
/**
37+
* @param InputInterface $input
38+
* @param OutputInterface $output
39+
* @return void
40+
*/
41+
protected function execute(InputInterface $input, OutputInterface $output)
42+
{
43+
parent::execute($input, $output);
44+
45+
$outFd = 'php://stdout';
46+
47+
if (null !== ($outOpt = $input->getOption('output'))) {
48+
$outFd = getcwd() . DIRECTORY_SEPARATOR . $outOpt;
49+
}
50+
51+
$ref = $input->getArgument('ref');
52+
$params = [
53+
'provider' => static::mapProviderToSdk($input->getArgument('provider')),
54+
'repository' => $input->getArgument('repository'),
55+
'ref' => $input->getArgument('ref'),
56+
];
57+
58+
$this->showLoader($output, 'Loading pipelines...');
59+
60+
/** @var Collection $collection */
61+
$collection = $this->continuousClient->getPipelines($params);
62+
$entity = null;
63+
64+
foreach ($collection->getIterator() as $entity) {
65+
/** @var Pipeline $entity */
66+
if ($ref === $entity->get('settingId')) {
67+
break;
68+
}
69+
70+
$entity = null;
71+
}
72+
73+
$exportDecorator = new PipelineExportDecorator($entity);
74+
75+
$this->hideLoader($output);
76+
file_put_contents($outFd, $exportDecorator->toYaml());
77+
}
78+
}

0 commit comments

Comments
 (0)