Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $ownerName = $input->getArgument('owner');
     $repositoryName = $input->getArgument('repository');
     $branch = $input->getArgument('branch');
     $github = $input->getOption('github');
     $local = $input->getOption('local');
     $repository = new Repository();
     $repository->setOwnerName($ownerName);
     $repository->setRepositoryName($repositoryName);
     $repository->setMasterBranch($branch);
     $repository->setCommitBranch($branch);
     if ($github) {
         $url = sprintf('https://api.github.com/repos/%s/%s/commits/%s', $ownerName, $repositoryName, $branch);
         $client = new Client();
         $request = $client->get($url);
         $response = $request->send();
         $json = $response->json();
         $repository->setCommitMessage($json['commit']['message']);
         $source = new GithubSource();
     } else {
         if ($local) {
             $source = new LocalGitSource($local);
             $git = ProcessBuilder::create()->add('git')->add('show')->add('--format=%s')->add('-s')->setWorkingDirectory($source->getRepositoryUrl($repository))->getProcess();
             $git->run();
             if (!$git->isSuccessful()) {
                 throw new \RuntimeException($git->getErrorOutput());
             }
             $repository->setCommitMessage(trim($git->getOutput()));
         } else {
             throw new \InvalidArgumentException('You must specify at least one source');
         }
     }
     $hook = new Hook();
     $hook->run($repository, $source);
 }