Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AdminBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Question\Question;
- class GitFlowCreateReleaseCommand extends ContainerAwareCommand
- {
- protected $em;
- protected function configure()
- {
- $this
- ->setName('app:gitflow:create-release')
- ->setHelp(<<<EOF
- The <info>%command.name%</info> creates a new GitFlow release (prompt for version number)
- <info>php app/console %command.name%</info>
- EOF
- );
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $lastTag = $this->getLatestGitTag();
- $output->writeln("== GitFlow Release Creator ==");
- $output->writeln("");
- /**
- * ask for next tag
- */
- $output->writeln(sprintf("Last created tag: %s", $lastTag));
- $nextReleaseTag = $this->askForNextReleaseTag($input, $output);
- $output->writeln(sprintf("Next tag: %s", $nextReleaseTag));
- /**
- * create release
- */
- $this->startAndFinishNewRelease($nextReleaseTag);
- }
- /**
- * Get the latest Git tag
- *
- * @return mixed
- */
- private function getLatestGitTag()
- {
- exec("git tag --sort=v:refname", $output);
- return array_pop($output);
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return mixed
- */
- private function askForNextReleaseTag(InputInterface $input, OutputInterface $output)
- {
- $helper = $this->getHelper('question');
- $question = new Question('Insert the next Release tag to create: ', '');
- $question->setValidator(function ($answer) {
- if (empty($answer)) {
- throw new \RuntimeException(
- 'You cannot create an empty Release tag'
- );
- }
- return $answer;
- });
- return $helper->ask($input, $output, $question);
- }
- /**
- * @param $nextReleaseTag
- */
- private function startAndFinishNewRelease($nextReleaseTag)
- {
- exec(sprintf(
- "git flow release start %s",
- $nextReleaseTag
- ));
- exec(sprintf(
- "git flow release finish -m \"%s\" %s",
- $nextReleaseTag,
- $nextReleaseTag
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement