projectStore = $projectStore;
$this->buildService = $buildService;
}
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
->setName('php-censor:create-build')
->addArgument('projectId', InputArgument::REQUIRED, 'A project ID')
->addOption('commit', null, InputOption::VALUE_OPTIONAL, 'Commit ID to build')
->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Branch to build')
->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Committer email')
->addOption('message', null, InputOption::VALUE_OPTIONAL, 'Commit message')
->setDescription('Create a build for a project');
}
/**
* {@inheritDoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$projectId = $input->getArgument('projectId');
$commitId = $input->getOption('commit');
$branch = $input->getOption('branch');
$environment = $input->hasOption('environment') ? $input->getOption('environment') : null;
$ciEmail = $input->getOption('email');
$ciMessage = $input->getOption('message');
$project = $this->projectStore->getById($projectId);
if (empty($project) || $project->getArchived()) {
throw new InvalidArgumentException('Project does not exist: ' . $projectId);
}
try {
$this->buildService->createBuild($project, $environment, $commitId, $branch, null, $ciEmail, $ciMessage, Build::SOURCE_MANUAL_CONSOLE);
$output->writeln('Build Created');
} catch (\Exception $e) {
$output->writeln('Failed');
$output->writeln(sprintf('%s', $e->getMessage()));
}
}
}