Наследование: extends Symfony\Component\Console\Helper\Helper
Пример #1
0
 /**
  * Use this for detecting the org and repo.
  *
  * Add the options to decorateDefinition.
  *
  * @param ConsoleEvent $event
  */
 public function initialize(ConsoleEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof InitCommand) {
         return;
     }
     if (!$this->gitHelper->isGitDir()) {
         throw new UserException(sprintf('You can only run the "%s" command when you are in a Git directory.', $command->getName()));
     }
     $input = $event->getInput();
     $input->setOption('repo-adapter', GitHelper::undefinedToDefault($input->getOption('repo-adapter'), $this->detectAdapterName()));
     $input->setOption('issue-adapter', GitHelper::undefinedToDefault($input->getOption('issue-adapter'), $input->getOption('repo-adapter')));
     if (!$this->application->getAdapterFactory()->supports($input->getOption('repo-adapter'), AdapterFactory::SUPPORT_REPOSITORY_MANAGER)) {
         return;
     }
     $org = GitHelper::undefinedToDefault($input->getOption('org'));
     $repo = GitHelper::undefinedToDefault($input->getOption('repo'));
     if (null === $org || null === $repo) {
         list($org, $repo) = $this->getRepositoryReference($this->getAdapter($input->getOption('repo-adapter')), $org, $repo);
         if (!$input->isInteractive()) {
             $this->styleHelper->note(['You did not provide an organization and/or repository name.', 'Gush automatically detected the missing information.', sprintf('Org: "%s" / repo: "%s"', $org, $repo)]);
         }
         $input->setOption('org', $org);
         $input->setOption('repo', $repo);
     }
     $input->setOption('issue-org', GitHelper::undefinedToDefault($input->getOption('issue-org'), $org));
     $input->setOption('issue-project', GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo));
 }
Пример #2
0
    public function testRemoteBranchExistsException()
    {
        $remote = 'phansys';
        $sourceBranch = 'my-feat-10';
        $remoteList = <<<'EOL'
8b64e4ecb74f2d2df582c0ab03a5c1ae890c43fb	HEAD
299aaa49cc5e1de3382c77d901736dcfd909d681	refs/heads/0.1
2ef49b196a50f481a4547b02817d9ee08dd8a0d4	refs/heads/0.2
d152871fd334619019df578a407b83ccb2c93ed7	refs/heads/0.3
5a7dbfd02ca80d5122827da832c579b116c29547	refs/heads/1.0
ae9c5ee4509cc5c141e5fd9d70c083936dc9a108	refs/heads/2.0
48e2a3a490abcad8e484d9189f001e9a222a48da	refs/heads/my-feat-10
b735c63268579326c3187e7a21ea46947b12a163	refs/heads/my-feat
538b6ba0a3b9943641657c30f9eea702bbe3b6dd	refs/heads/my-feat-1
bb590a7055e6338943346f9c445f298d89fb9ce9	refs/heads/my-feat-10
144c0c98ab5d216f4b208cf702838357d3fdb811	refs/heads/my-feat-100
704a8bc7030da0dd56f17fd8c736e620c26c42ef	refs/heads/my-feat-1001
ce8bafdd18a5d1753d7a9872d3f402657873f249	refs/heads/new-my-feat-10
70cc7f22e4d937621dee3bbbb79b2913f6037137	refs/heads/my-feat-2
611fedc6cc77fd9a0c0b96eadce375cb28937204	refs/heads/my-feat-200
eafa079bb55453b44fe02b98f7420703c532b849	refs/heads/my-feat-2000
EOL;
        $processHelper = $this->prophesize(ProcessHelper::class);
        $this->unitGit = new GitHelper($processHelper->reveal(), $this->gitConfigHelper->reveal(), $this->filesystemHelper->reveal());
        $processHelper->runCommand(['git', 'ls-remote', $remote], true)->willReturn($remoteList);
        $this->setExpectedException('\\RuntimeException', sprintf('Invalid refs found while searching for remote branch at "refs/heads/%s"', $sourceBranch));
        $this->assertTrue($this->unitGit->remoteBranchExists($remote, $sourceBranch));
    }
Пример #3
0
 /**
  * @test
  */
 public function merges_remote_branch_fast_forward_in_clean_wc()
 {
     $base = 'master';
     $sourceBranch = 'amazing-feature';
     $processHelper = $this->prophesize('Gush\\Helper\\ProcessHelper');
     $this->unitGit = new GitHelper($processHelper->reveal(), $this->gitConfigHelper->reveal(), $this->filesystemHelper->reveal());
     $processHelper->runCommand('git status --porcelain --untracked-files=no')->willReturn("\n");
     $processHelper->runCommand('git rev-parse --abbrev-ref HEAD')->willReturn('master');
     $processHelper->runCommand(['git', 'checkout', 'master'])->shouldBeCalled();
     $processHelper->runCommand(['git', 'merge', '--ff', 'amazing-feature'])->shouldBeCalled();
     $this->assertNull($this->unitGit->mergeBranch($base, $sourceBranch, null, true));
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Gush\Application $application */
     $application = $this->getApplication();
     $config = $application->getConfig();
     $valid = true;
     /** @var StyleHelper $styleHelper */
     $styleHelper = $this->getHelper('gush_style');
     $adapters = $this->getAdapters();
     $repositoryManagers = $adapters[0];
     $issueTrackers = $adapters[1];
     $repositoryManager = GitHelper::undefinedToDefault($input->getOption('repo-adapter'));
     $issueTracker = GitHelper::undefinedToDefault($input->getOption('issue-adapter'));
     $org = GitHelper::undefinedToDefault($input->getOption('org'));
     $repo = GitHelper::undefinedToDefault($input->getOption('repo'));
     $issueOrg = GitHelper::undefinedToDefault($input->getOption('issue-org'), $org);
     $issueRepo = GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo);
     $this->validateAdapter($repositoryManager, $repositoryManagers, 'Repository-manager', $valid);
     $this->validateAdapter($issueTracker, $issueTrackers, 'Issue-tracker', $valid);
     if (!$valid) {
         return self::COMMAND_FAILURE;
     }
     $this->checkAdapterConfigured($repositoryManager, $repositoryManagers[$repositoryManager], 'Repository-manager', $valid);
     $this->checkAdapterConfigured($issueTracker, $issueTrackers[$issueTracker], 'Issue-tracker', $valid);
     if (!$valid) {
         if ($input->isInteractive() && $styleHelper->confirm('Would you like to configure the missing adapters now?')) {
             $application->doRun(new ArrayInput(['command' => 'core:configure']), $output);
         } else {
             $styleHelper->note(['You cannot use the selected repository-manager and/or issue-tracker until its configured.', 'Run the "core:configure" command to configure the adapters.']);
         }
     }
     $params = ['repo_adapter' => $repositoryManager, 'issue_tracker' => $issueTracker, 'repo_org' => $org, 'repo_name' => $repo, 'issue_project_org' => $issueOrg, 'issue_project_name' => $issueRepo];
     $config->merge($params, Config::CONFIG_LOCAL);
     ConfigFactory::dumpToFile($config, Config::CONFIG_LOCAL);
     $styleHelper->success('Configuration file saved successfully.');
     return self::COMMAND_SUCCESS;
 }
Пример #5
0
 /**
  * @param ConsoleCommandEvent $event
  * @param string              $org
  * @param string              $repo
  * @param string              $adapterName
  */
 private function initializeIssueTracker(ConsoleCommandEvent $event, $org, $repo, $adapterName)
 {
     $input = $event->getInput();
     $issueOrg = GitHelper::undefinedToDefault($input->getOption('issue-org'), $org);
     $issueRepo = GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo);
     $issueAdapterName = $input->getOption('issue-adapter') ?: $adapterName;
     $input->setOption('issue-org', $issueOrg);
     $input->setOption('issue-project', $issueRepo);
     $input->setOption('issue-adapter', $issueAdapterName);
     $config = $this->application->getConfig()->get(['adapters', $issueAdapterName], Config::CONFIG_SYSTEM);
     /** @var \Gush\Adapter\BaseIssueTracker $issueTracker */
     $issueTracker = $this->application->getAdapterFactory()->createIssueTracker($issueAdapterName, $config, $this->application->getConfig());
     $issueTracker->authenticate();
     $issueTracker->setRepository($issueRepo)->setUsername($issueOrg);
     $this->application->setIssueTracker($issueTracker);
 }
Пример #6
0
 public function restoreStashedBranch()
 {
     $this->gitHelper->restoreStashedBranch();
 }