/** * @param RepositoryList $repositories */ public function execute(RepositoryList $repositories) { $model = $repositories->getProjectModel(); $currentBranch = $model->getBranch(); if ($model->hasConflicts()) { if (false !== stripos($model->getConflicts(), ComposerHelper::COMPOSER_JSON)) { $this->getSymfonyStyle()->error('You should resolve composer.json conflict first'); $this->stopPropagation(); return; } if (false !== stripos($model->getConflicts(), ComposerHelper::COMPOSER_LOCK)) { try { $this->getLogger()->debug('Auto-resolve composer.lock conflict'); $vendorsForUpdate = $this->findVendorsForUpdate($model); $this->resolveComposerConflict($model, ComposerHelper::COMPOSER_LOCK, $currentBranch); if ($vendorsForUpdate) { $cmd = $this->getConfig()->getComposerBin() . ' update ' . implode(' ', $vendorsForUpdate); $this->getSymfonyStyle()->writeln($cmd); $model->getProvider()->runCommand($cmd, $this->isDryRun(), true); } $model->getProvider()->run('add', [ComposerHelper::COMPOSER_LOCK], $this->isDryRun(), false); } catch (\Exception $e) { $this->getLogger()->error($e->getMessage(), [$e->getTraceAsString()]); $this->getSymfonyStyle()->error($e->getMessage()); $this->stopPropagation(); } } } }
/** * @param RepositoryList $repositories * @description * проверить измененные файлы в директории * если есть измененные - проверяем название ветки * берем название проектной ветки * собираем вендоры для которых нужно создать ветки * если ветки есть - запрашиваем подтверждение */ public function execute(RepositoryList $repositories) { $this->getLogger()->debug('Run plugin', [get_called_class()]); $branch = $repositories->getProjectModel()->getBranch(); $vendorsWithoutBranch = $this->findVendorsWithoutBranch($repositories->getVendorModels(), $branch); $this->createBranches($branch, $vendorsWithoutBranch); $this->getLogger()->debug('End plugin', [get_called_class()]); }
/** * @param RepositoryList $repositories */ public function execute(RepositoryList $repositories) { $this->getLogger()->debug('Run plugin', [get_called_class()]); $model = $repositories->getProjectModel(); if ($model->hasConflicts()) { if (false !== stripos($model->getConflicts(), ComposerHelper::COMPOSER_JSON)) { $this->getSymfonyStyle()->error('You should resolve composer.json conflict first'); $this->stopPropagation(); return; } } $composerFilename = $repositories->getProjectModel()->getAbsolutePath() . DIRECTORY_SEPARATOR . 'composer.json'; $helper = new ComposerHelper(); $composerData = $helper->jsonDecode(file_get_contents($composerFilename)); $data = $repositories->getVendorModels(); $vendorsModels = []; foreach ($data as $model) { $vendorsModels[strtolower($model->getPackageName())] = $model; } $projectBranch = $repositories->getProjectModel()->getBranch(); $updateFlag = false; if (!empty($composerData['require'])) { $changes = $this->changeVersion($composerData['require'], $vendorsModels, $projectBranch); $composerData['require'] = array_merge($composerData['require'], $changes); $updateFlag = $updateFlag || !empty($changes); } if (!empty($composerData['require-dev'])) { $changes = $this->changeVersion($composerData['require-dev'], $vendorsModels, $projectBranch); $composerData['require-dev'] = array_merge($composerData['require-dev'], $changes); $updateFlag = $updateFlag || !empty($changes); } if (!$this->isDryRun()) { $jsonEncodedData = json_encode($composerData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); file_put_contents($composerFilename, $jsonEncodedData); } if ($updateFlag) { $this->getSymfonyStyle()->success('File composer.json updated'); } $this->getLogger()->debug('End plugin', [get_called_class()]); }
/** * @param RepositoryList $repositories */ public function execute(RepositoryList $repositories) { $this->getLogger()->debug('Run plugin', [get_called_class()]); $all = $this->getInput()->hasOption('all') && $this->getInput()->getOption('all'); $prune = $this->getInput()->hasOption('prune') && $this->getInput()->getOption('prune'); $arguments = []; if ($all) { $arguments[] = '--all'; } if ($prune) { $arguments[] = '--prune'; } $model = $repositories->getProjectModel(); $model->getProvider()->run('fetch', $arguments, $this->isDryRun(), true); $this->getLogger()->debug('End plugin', [get_called_class()]); }
/** * @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()]); }
/** * @param RepositoryList $repositories * @return string */ public function execute(RepositoryList $repositories) { $this->getLogger()->debug('Run plugin', [get_called_class()]); $comment = $this->getInput()->getOption('message'); $model = $repositories->getProjectModel(); if ($model->hasChanges()) { $model->getProvider()->run('add', ['.'], $this->isDryRun()); $params = []; if ($this->getInput()->hasOption('no-verify') && $this->getInput()->getOption('no-verify')) { $params[] = '--no-verify'; } $params[] = '-m'; $params[] = CommentHelper::buildComment($comment, $model->getBranch()); $model->getProvider()->run('commit', $params, $this->isDryRun(), true); } else { $this->getLogger()->debug('Changes not found', ['commit']); } $this->getLogger()->debug('End plugin', [get_called_class()]); }
/** * @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()]); }
/** * @param RepositoryList $repositories */ public function execute(RepositoryList $repositories) { $this->getLogger()->debug('Run plugin', [get_called_class()]); $onlyVendor = $this->getInput()->getOption('only-vendor'); if (!$onlyVendor) { /** @var RepositoryModel $list */ $model = $repositories->getProjectModel(); if ($model->hasCommits() || !$model->hasRemote()) { $branch = $model->getBranch(); if ($model->hasRemote()) { $model->getProvider()->run('pull', ['origin', $branch], $this->isDryRun(), true); } $model->getProvider()->run('push', ['origin', $branch], $this->isDryRun(), true); $this->getSymfonyStyle()->writeln(sprintf('Project pushed to %s', $branch)); } else { $this->getLogger()->debug('Nothing to push', ['name' => $model->getPath()]); } } else { $this->getLogger()->debug('Only vendor option enabled'); } $this->getLogger()->debug('End plugin', [get_called_class()]); }
/** * @param RepositoryList $repositories */ public function execute(RepositoryList $repositories) { $this->getLogger()->debug('Run plugin', [get_called_class()]); $remoteBranch = null; if ($this->getInput()->hasArgument('remote-branch')) { $remoteBranch = $this->getInput()->getArgument('remote-branch'); } /** @var RepositoryModel $list */ $model = $repositories->getProjectModel(); $currentBranch = $model->getBranch(); $model->getProvider()->run('fetch', [], $this->isDryRun(), false); if ($model->getProvider()->hasRemoteBranch($currentBranch)) { $model->getProvider()->run('pull', ['origin', $currentBranch], $this->isDryRun(), false); } $needMerge = !empty($remoteBranch) && $remoteBranch != $currentBranch; if ($needMerge && $model->getProvider()->hasRemoteBranch($remoteBranch)) { $model->getProvider()->run('pull', ['origin', $remoteBranch], $this->isDryRun(), false); } if ($needMerge && $model->getProvider()->hasLocalBranch($remoteBranch)) { $model->getProvider()->run('merge', [$remoteBranch], $this->isDryRun(), false); } $this->getLogger()->debug('End plugin', [get_called_class()]); }
/** * @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()]); }