示例#1
0
 /**
  * GET /package/register.
  */
 public function registerAction()
 {
     if (!$this->app->request()->get('confirm')) {
         $this->app->render('extension/register.html', ['repository' => $this->app->request()->get('repository')]);
         return;
     }
     $transaction = $this->app->request()->get('id');
     $pathTransaction = $this->app->config('cache_dir') . '/' . $transaction . '.json';
     $pathMetaTransaction = $this->app->config('cache_dir') . '/' . $transaction . '_meta.json';
     if (!file_exists($pathTransaction)) {
         $this->app->flash('error', 'No active registration process');
         $this->app->redirect('/package/register');
         exit;
     }
     $serializeExtension = file_get_contents($pathTransaction);
     unlink($pathTransaction);
     $extension = new Extension();
     $extension->unserialize($serializeExtension);
     $serializeExtensionMeta = file_get_contents($pathMetaTransaction);
     unlink($pathMetaTransaction);
     $extensionMeta = json_decode($serializeExtensionMeta, true);
     $extension->setWatchers($extensionMeta['watchers']);
     $extension->setStars($extensionMeta['stars']);
     $packageName = $extension->getName();
     $vendorName = $extension->getVendor();
     $pathTransactionLog = $transaction . 'log';
     if (file_exists($pathTransactionLog)) {
         unlink($pathTransactionLog);
     }
     $user = $this->app->user();
     $user->addExtension($packageName);
     $userRepository = $this->app->container->get('user.repository');
     $userRepository->persist($user);
     $redis = $this->app->container->get('redis.client');
     $extensionRepository = $this->app->container->get('extension.repository');
     $extensionRepository->persist($extension, $user);
     $rest = new Rest($extension, $this->app);
     $rest->update();
     $es = $this->app->container->get('elastica.client');
     $indexer = new Indexer($es);
     $indexer->indexExtension($extension);
     $this->app->flash('warning', $packageName . ' has been registred');
     $this->app->redirect('/package/' . $packageName);
 }
示例#2
0
 /**
  * @param string $username
  *
  * Hook for github hooks. Only release and tag are supported.
  */
 public function hookAction($vendor, $repository)
 {
     $this->validPayload($vendor, $repository);
     $payloadPost = $this->app->request->getBody();
     $payload = json_decode($payloadPost);
     if (!$payload) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'invalid Payload'], 200);
         return;
     }
     $hubEvent = $this->app->request()->headers()->get('X-GitHub-Event');
     if ($hubEvent == 'ping') {
         $this->app->jsonResponse(['status' => 'ping', 'message' => 'hook setup'], 200);
         return;
     }
     if (!($hubEvent == 'create' || $hubEvent == 'delete')) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'operation not supported'], 400);
         return;
     }
     if (!($payload->ref_type == 'tag' || $payload->ref_type == 'release')) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'Only tag/release hooks are supported', 1], 200);
         return;
     }
     $extensionName = $payload->repository->full_name;
     $tag = $payload->ref;
     $repository = $payload->repository->git_url;
     $time = $payload->repository->pushed_at;
     $ownerId = $payload->repository->owner->id;
     $userRepository = $this->app->container->get('user.repository');
     $this->user = $userRepository->findByProviderId('github', $ownerId);
     if (!$this->user) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'Owner Id not found'], 401);
         return;
     }
     $versionParser = new VersionParser();
     try {
         $normalizedVersion = $versionParser->normalize($tag);
     } catch (\Exception $e) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'Invalid tag <' . $tag . '>'], 400);
         return;
     }
     if (!$normalizedVersion) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'This tag does not look like a release tag'], 200);
         return;
     }
     if (!$this->findRegisteredExension($extensionName)) {
         return;
     }
     $log = new BufferIO();
     try {
         $driver = new \PickleWeb\Repository\Github($repository, false, $this->app->config('cache_dir'), $log);
         $extension = new Extension();
         $extension->setFromRepository($driver, $log);
     } catch (\Exception $e) {
         $this->app->jsonResponse(['status' => 'error', 'message' => $extensionName . '-' . $tag . ' error on import:' . $e->getMessage()], 500);
         return;
     }
     $vendorName = $extension->getVendor();
     $packageName = $extension->getPackageName();
     $stargazersCount = $payload->repository->stargazers_count;
     $watchersCount = $payload->repository->watchers_count;
     /* only to set the meta, may be cleaner to do it in there */
     $extension->setStars($stargazersCount);
     $extension->setWatchers($watchersCount);
     $json = $extension->serialize();
     if (!$json) {
         $this->app->jsonResponse(['status' => 'error', 'message' => $extensionName . '-' . $tag . ' error on import: fail to store'], 500);
         return;
     }
     $redis = $this->app->container->get('redis.client');
     $extensionRepository = $this->app->container->get('extension.repository');
     $extensionRepository->persist($extension, $this->user);
     $rest = new Rest($extension, $this->app);
     $rest->update();
     $es = $this->app->container->get('elastica.client');
     $indexer = new Indexer($es);
     $indexer->index($extension);
     $this->app->jsonResponse(['status' => 'success', 'message' => $extensionName . '-' . $tag . ' imported'], 200);
     return;
 }