Пример #1
0
 public function testGitHubAuthentication()
 {
     $remote = new GitHubRemote();
     $this->assertEquals([], $remote->getAuthenticationPart());
     $remote->setOptions(['personal_token' => 'testpersonaltoken', 'username' => 'testusername']);
     $this->assertEquals(['auth' => ['testusername', 'testpersonaltoken']], $remote->getAuthenticationPart());
     $repository = new GitHubRepository('text/test', 'just a test', $anon = 'https://github.com/test/test.git');
     $repository->setRemote($remote);
     $this->assertEquals($anon, $repository->getAnonymousUri());
     $this->assertEquals('https://*****:*****@github.com/test/test.git', $repository->getUri());
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!in_array($input->getOption('adapter'), ['BitBucket', 'GitHub'])) {
         throw new InvalidArgumentException(sprintf('The given adapter "%s" is not supported (yet)', $input->getOption('adapter')));
     }
     $guardian = new GitGuardian();
     $emitter = $guardian->getEmitter();
     if ('GitHub' === $input->getOption('adapter')) {
         $users = $input->getArgument('owner');
         if (count($users) && !strstr($users[0], '/')) {
             $username = array_shift($users);
             $gitHubCredentials = ['personal_token' => $input->getOption('personal-token'), 'username' => $username];
             $remote = new GitHubRemote();
             $remote->setEmitter($emitter);
             $remote->setOptions($gitHubCredentials);
             $guardian->addRemote($remote);
         }
         foreach ($users as $owner) {
             $remote = new GitHubRemote();
             $remote->setEmitter($emitter);
             $remote->setUser($owner);
             $guardian->addRemote($remote);
         }
     } else {
         $bitBucketCredentials = ['client_id' => $input->getOption('client-id'), 'client_secret' => $input->getOption('client-secret')];
         foreach ($input->getArgument('owner') as $owner) {
             $remote = new BitBucketRemote();
             $remote->setEmitter($emitter);
             $remote->setOptions($bitBucketCredentials);
             $remote->setUser($owner);
             $guardian->addRemote($remote);
         }
     }
     $this->setupListeners($emitter, $output);
     $guardian->cloneAll($input->getOption('destination'));
 }