|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SymfonyRollbarBundle\Command; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Input\InputArgument; |
| 6 | +use Symfony\Component\Console\Input\InputInterface; |
| 7 | +use Symfony\Component\Console\Input\InputOption; |
| 8 | +use Symfony\Component\Console\Output\OutputInterface; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class DeployCommand |
| 12 | + * |
| 13 | + * @package SymfonyRollbarBundle\Command |
| 14 | + */ |
| 15 | +class DeployCommand extends \SymfonyRollbarBundle\Command\AbstractCommand |
| 16 | +{ |
| 17 | + protected static $defaultName = 'rollbar:deploy'; |
| 18 | + |
| 19 | + /** |
| 20 | + * @inheritdoc |
| 21 | + */ |
| 22 | + protected function configure() |
| 23 | + { |
| 24 | + parent::configure(); |
| 25 | + |
| 26 | + $help = implode("\n", [ |
| 27 | + '<info>%command.name%</info> - Track new build with Rollbar after successful deployment.', |
| 28 | + 'See: <info>https://rollbar.com/docs/deploys_other</info>', |
| 29 | + ]); |
| 30 | + |
| 31 | + $this |
| 32 | + ->setName(static::$defaultName) |
| 33 | + ->setDescription('Send notification about new build.') |
| 34 | + ->setHelp($help); |
| 35 | + |
| 36 | + $this->addArgument( |
| 37 | + 'revision', |
| 38 | + InputArgument::REQUIRED, |
| 39 | + 'String identifying the revision being deployed, such as a Git SHA.'); |
| 40 | + |
| 41 | + $this->addOption( |
| 42 | + 'comment', |
| 43 | + 'c', |
| 44 | + InputOption::VALUE_OPTIONAL, |
| 45 | + 'Additional text data to record with this deploy.' |
| 46 | + )->addOption( |
| 47 | + 'rollbar_username', |
| 48 | + 'ru', |
| 49 | + InputOption::VALUE_OPTIONAL, |
| 50 | + 'Rollbar username of the user who deployed.' |
| 51 | + )->addOption( |
| 52 | + 'local_username', |
| 53 | + 'lu', |
| 54 | + InputOption::VALUE_OPTIONAL, |
| 55 | + 'Username (on your system) who deployed.' |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @param \Symfony\Component\Console\Input\InputInterface $input |
| 61 | + * @param \Symfony\Component\Console\Output\OutputInterface $output |
| 62 | + * |
| 63 | + * @return int|null|void |
| 64 | + */ |
| 65 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 66 | + { |
| 67 | + /** @var \SymfonyRollbarBundle\Provider\RollbarHandler $rbHandler */ |
| 68 | + $rbHandler = $this->getContainer()->get('symfony_rollbar.provider.rollbar_handler'); |
| 69 | + |
| 70 | + $environment = $this->getContainer()->getParameter('kernel.environment'); |
| 71 | + $revision = $input->getArgument('revision'); |
| 72 | + $comment = $input->getOption('comment'); |
| 73 | + $rUser = $input->getOption('rollbar_username'); |
| 74 | + $lUser = $input->getOption('local_username'); |
| 75 | + |
| 76 | + $lUser = empty($lUser) ? get_current_user() : $lUser; |
| 77 | + |
| 78 | + try { |
| 79 | + $rbHandler->trackBuild($environment, $revision, $comment, $rUser, $lUser); |
| 80 | + } catch (\GuzzleHttp\Exception\ClientException $e) { |
| 81 | + $this->io->error("Build has been not tracked:\n" . $e->getMessage()); |
| 82 | + } |
| 83 | + |
| 84 | + $this->io->success('Done.'); |
| 85 | + } |
| 86 | +} |
0 commit comments