|
@@ -0,0 +1,67 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FD3\Command;
|
|
|
+
|
|
|
+use PHPGit\Exception\GitException;
|
|
|
+use PHPGit\Git;
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+
|
|
|
+class TagDeleteVendorsCommand extends Command
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('vendors:tag:delete')
|
|
|
+ ->setDescription('Remove Tag of all vendor')
|
|
|
+ ->setHelp('Remove Tag of all vendor')
|
|
|
+ ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
|
|
|
+ ->addArgument('tag', InputArgument::REQUIRED, 'Tag e.g. vX.Y.Z and branch X.Y to remove');
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ $file = $input->getArgument("ini_file");
|
|
|
+ $tag = $input->getArgument("tag");
|
|
|
+ if (strtolower(substr($tag, 0, 1)) == 'v') {
|
|
|
+ $realpath = realpath($file);
|
|
|
+ $dirname = dirname($realpath);
|
|
|
+ if (!chdir($dirname)) {
|
|
|
+ throw new \Exception("Can't change working directory to " . $dirname);
|
|
|
+ }
|
|
|
+
|
|
|
+ $content = parse_ini_file($realpath, true);
|
|
|
+ foreach ($content as $sec => $conf) {
|
|
|
+ try {
|
|
|
+ $git_path = $dirname . '/' . $sec;
|
|
|
+ if (!file_exists($git_path)) {
|
|
|
+ $git = new Git();
|
|
|
+ // agrego datos del usuario
|
|
|
+ $git->config->add('user.email', 'drone@flowdat.com', ["global" => true]);
|
|
|
+ $git->config->add('user.name', 'drone', ["global" => true]);
|
|
|
+ // clono el repositorio
|
|
|
+ $git->clone($content[$sec]["repo"], $git_path);
|
|
|
+ // agrego el path del repositorio
|
|
|
+ $git->setRepository($git_path);
|
|
|
+ $git->fetch('origin');
|
|
|
+ }
|
|
|
+
|
|
|
+ $command = "cd {$git_path} ; git tag -d {$tag} ; git push --delete origin {$tag}";
|
|
|
+
|
|
|
+ // ejecuto el comando git
|
|
|
+ shell_exec($command);
|
|
|
+ sleep(5);
|
|
|
+ } catch (GitException $e) {
|
|
|
+ $output->writeln($e->getTraceAsString());
|
|
|
+ $output->writeln($sec . ": " . $e->getMessage());
|
|
|
+
|
|
|
+ return $e->getCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+}
|