Example #1
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $parallelProcess = new ParallelProcess($this->getSymfonyStyle());
     $remoteBranch = null;
     if ($this->getInput()->hasArgument('remote-branch')) {
         $remoteBranch = $this->getInput()->getArgument('remote-branch');
     }
     /** @var RepositoryModel[] $list */
     $list = $repositories->getVendorModels();
     $progressBar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressBar->create(count($list));
     $model = null;
     foreach ($list as $model) {
         $progressBar->advance('Fetch status of ' . ($model->getPath() ?: 'project repository'));
         $currentBranch = $model->getBranch();
         $hasCommits = $model->hasCommits();
         $needPull = false;
         if ($currentBranch !== $remoteBranch || 'master' !== $currentBranch && 'master' !== $remoteBranch || $hasCommits) {
             $needPull = true;
         }
         if ($needPull) {
             $parallelProcess->add($model->getProvider()->buildCommand('fetch', []), $model->getAbsolutePath(), $this->isDryRun(), false);
             if ($model->getProvider()->hasRemoteBranch($currentBranch)) {
                 $parallelProcess->add($model->getProvider()->buildCommand('pull', ['origin', $currentBranch]), $model->getAbsolutePath(), $this->isDryRun(), false);
             }
             $needMerge = !empty($remoteBranch) && $remoteBranch != $currentBranch;
             if ($needMerge && $model->getProvider()->hasRemoteBranch($remoteBranch)) {
                 $parallelProcess->add($model->getProvider()->buildCommand('pull', ['origin', $remoteBranch]), $model->getAbsolutePath(), $this->isDryRun(), false);
             }
             if ($needMerge && !$model->hasConflicts() && $model->getProvider()->hasLocalBranch($remoteBranch)) {
                 $parallelProcess->add($model->getProvider()->buildCommand('merge', [$remoteBranch]), $model->getAbsolutePath(), $this->isDryRun(), true);
             }
         } else {
             $this->getLogger()->debug('Skipped', [$model->getPackageName(), 'current' => $currentBranch, 'remote' => $remoteBranch, 'hasCommits' => $hasCommits]);
         }
     }
     $progressBar->finish();
     $parallelProcess->run();
     foreach ($list as $model) {
         if ($model->hasConflicts()) {
             $this->getSymfonyStyle()->writeln($model->getPackageName());
             $this->getSymfonyStyle()->writeln($model->getConflicts());
         }
     }
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }
 /**
  * @param ProcessEvent $event
  */
 public function stopAfter(ProcessEvent $event)
 {
     $process = $event->getProcess();
     if (OutputInterface::VERBOSITY_DEBUG <= $this->getSymfonyStyle()->getVerbosity()) {
         $this->getSymfonyStyle()->writeln($process->getCommandLine());
         $error = trim($process->getErrorOutput());
         if ($error) {
             $this->getSymfonyStyle()->writeln($error);
         }
         $output = trim($process->getOutput());
         if ($output) {
             $this->getSymfonyStyle()->writeln($output);
         }
     } else {
         $this->progressBarHelper->advance($process->getWorkingDirectory());
     }
 }
Example #3
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $branch = $this->getInput()->getArgument('branch');
     /** @var RepositoryModel[] $list */
     if (!$this->getInput()->getOption('no-vendors')) {
         $list = array_reverse($repositories->getAll());
     } else {
         $list = [$repositories->getProjectModel()];
     }
     $progressBar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressBar->create(count($list));
     foreach ($list as $model) {
         $currentBranch = $model->getBranch();
         $progressBar->advance('Checkout of ' . ($model->getPath() ?: 'project repository'));
         if ($currentBranch == $branch) {
             continue;
         }
         $needCheckout = $model->getType() == RepositoryModel::TYPE_ROOT;
         $needCheckout = $needCheckout || $model->hasChanges();
         $needCheckout = $needCheckout || 'master' == $branch;
         $needCheckout = $needCheckout || $model->getProvider()->hasLocalBranch($branch);
         $needCheckout = $needCheckout || $model->getProvider()->hasRemoteBranch($branch);
         if ($model->hasCommits()) {
             $this->getSymfonyStyle()->newLine();
             $this->getSymfonyStyle()->warning(sprintf('Вы делаете checkout "%s" с закоммиченными но не запушенными правками', $model->getPackageName()));
         }
         if ($needCheckout) {
             $output = $model->getProvider()->run('fetch', [], $this->isDryRun(), true);
             if ($output) {
                 $this->getSymfonyStyle()->writeln($output);
             }
             $arguments = [];
             if (!$model->getProvider()->hasLocalBranch($branch) && !$model->getProvider()->hasRemoteBranch($branch)) {
                 $arguments[] = '-b';
             }
             $this->getSymfonyStyle()->newLine(2);
             $arguments[] = $branch;
             $model->getProvider()->run('checkout', $arguments, $this->isDryRun(), true);
             $this->getSymfonyStyle()->writeln(sprintf('%s: switched to [%s]', $model->getPath(), $branch));
         }
     }
     $progressBar->finish();
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }
Example #4
0
 /**
  * @param array $composerData
  * @param RepositoryModel[] $vendorsModels
  * @param string $projectBranch
  * @return array
  */
 protected function changeVersion(array $composerData, array $vendorsModels, $projectBranch)
 {
     $result = [];
     $progressbar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressbar->create(count($composerData));
     foreach ($composerData as $packageName => $sourceVersion) {
         $packageNameLower = strtolower($packageName);
         $this->getLogger()->debug('Check vendor version', [$packageName, $sourceVersion]);
         if (!array_key_exists($packageNameLower, $vendorsModels)) {
             $this->getLogger()->debug('Skipped, because not found in vendor list', ['packageNameLower' => $packageNameLower]);
             continue;
         }
         $model = $vendorsModels[$packageNameLower];
         $branch = $model->getBranch();
         $progressbar->advance($model->getPackageName());
         $parts = explode('as', $sourceVersion);
         $parts = array_map('trim', $parts);
         if (1 == count($parts)) {
             $currentBranch = 'master';
             $baseVersion = $parts[0];
         } elseif (2 == count($parts)) {
             $currentBranch = $parts[0];
             $baseVersion = $parts[1];
         } else {
             throw new \RuntimeException(sprintf('Invalid %s version %s in composer.json', $packageName, $sourceVersion));
         }
         if ($currentBranch != $branch) {
             if ('master' == $branch) {
                 $newVersion = $baseVersion;
             } else {
                 $newVersion = 'dev-' . $branch . ' as ' . $baseVersion;
             }
             if ($sourceVersion !== $newVersion) {
                 $result[$packageName] = $newVersion;
                 $this->getLogger()->debug('Change version', ['vendor' => $packageName, 'from' => $sourceVersion, 'to' => $newVersion]);
             }
         }
     }
     $progressbar->finish();
     return $result;
 }
Example #5
0
 /**
  * @param RepositoryList $repositories
  * @return string
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $comment = $this->getInput()->getOption('message');
     $branch = $repositories->getProjectModel()->getBranch();
     $comment = CommentHelper::buildComment($comment, $branch);
     $vendors = $repositories->getVendorModels();
     $this->getSymfonyStyle()->newLine();
     $progressBar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressBar->create(count($vendors));
     foreach ($vendors as $model) {
         $progressBar->advance($model->getPath());
         if ($model->hasChanges()) {
             if ($model->hasConflicts()) {
                 $progressBar->finish();
                 $this->getSymfonyStyle()->newLine();
                 $this->getSymfonyStyle()->error('Conflicts detected');
                 $this->getSymfonyStyle()->writeln($model->getPath());
                 $this->getSymfonyStyle()->writeln($model->getConflicts());
                 $this->getSymfonyStyle()->newLine();
                 $this->stopPropagation();
                 break;
             }
             $model->getProvider()->run('add', ['.'], $this->isDryRun());
             $params = [];
             if ($this->getInput()->hasOption('no-verify') && $this->getInput()->getOption('no-verify')) {
                 $params[] = '--no-verify';
             }
             $params[] = '-m';
             $params[] = $comment;
             $this->getSymfonyStyle()->newLine();
             $model->getProvider()->run('commit', $params, $this->isDryRun(), true);
             $this->getSymfonyStyle()->writeln(sprintf('%s: commit changes to (%s)', $model->getPath(), $model->getBranch()));
         } else {
             $this->getLogger()->debug('Changes not found', ['commit vendor']);
         }
     }
     $progressBar->finish();
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }
Example #6
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $progressBar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressBar->create($repositories->count());
     $hasChanges = false;
     $projectBranch = $repositories->getProjectModel()->getBranch();
     $result = [];
     foreach ($repositories->getAll() as $model) {
         $progressBar->advance('Status of ' . ($model->getPath() ?: 'project repository'));
         $branch = $model->getBranch();
         $differentBranch = $this->isDifferentBranches($projectBranch, $branch);
         $path = $model->getType() === RepositoryModel::TYPE_ROOT ? 'project repository' : $model->getPath();
         /**
          * Check full state of repo
          * Also check branch of repo (if it is not according to project branch - show it)
          */
         $unpushedCommits = $model->getUnpushedCommits();
         $gitHasUnpushedCommits = $model->hasCommits();
         $gitHasChanges = $model->hasChanges();
         $modelHasChanges = $gitHasChanges || $gitHasUnpushedCommits || $differentBranch;
         $hasChanges = $hasChanges || $modelHasChanges;
         if ($modelHasChanges) {
             $result[$path] = ['path' => null, 'branch' => null, 'hasCommits' => null, 'hasChanges' => null, 'hasConflicts' => null, 'unpushedCommit' => null];
             $result[$path]['path'] = sprintf('<info>%s</info> ', $path);
             if ($projectBranch == $branch) {
                 $result[$path]['branch'] = sprintf('<question>[%s]</question>', $branch);
             } else {
                 if (self::MASTER_BRANCH == $projectBranch) {
                     if ($projectBranch != $branch) {
                         $result[$path]['branch'] = sprintf('<error>[%s -> %s]</error>', $branch, $projectBranch);
                     }
                 } else {
                     if (self::MASTER_BRANCH == $branch) {
                         if ($gitHasChanges) {
                             $result[$path]['branch'] = sprintf('<error>[%s -> %s]</error>', $branch, $projectBranch);
                         } else {
                             $result[$path]['branch'] = sprintf('<error>[%s]</error>', $branch);
                         }
                     } else {
                         if ($projectBranch != $branch) {
                             if ($gitHasChanges) {
                                 $result[$path]['branch'] = sprintf('<error>[%s -> %s]</error>', $branch, $projectBranch);
                             } else {
                                 $result[$path]['branch'] = sprintf('<error>[%s]</error>', $branch);
                             }
                         }
                     }
                 }
             }
             if ($gitHasUnpushedCommits) {
                 $result[$path]['hasCommits'] = ' <comment>(has unpushed commits)</comment>';
             }
             if ($model->hasConflicts()) {
                 $result[$path]['hasConflicts'] = ' <error>(has conflicts)</error>';
             }
             if ($gitHasChanges) {
                 $result[$path]['hasChanges'] = ltrim($model->getRawStatus());
             }
             if ($gitHasUnpushedCommits) {
                 $result[$path]['unpushedCommit'] .= "<comment>Unpushed commits:</comment>\n";
                 foreach ($unpushedCommits as $unpushedCommit) {
                     $result[$path]['unpushedCommit'] .= sprintf("<comment>%s</comment>\n", $unpushedCommit);
                 }
             }
         }
     }
     $progressBar->finish();
     if (!$hasChanges) {
         $this->getSymfonyStyle()->writeln('<comment>no changes</comment>');
     } else {
         $this->displayStatus($result);
     }
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }