コード例 #1
0
 /**
  * @param Extension $extension
  * @param User      $extension
  */
 public function persist(Extension $extension, User $user)
 {
     $this->redisClient->hset(self::EXTENSION_HASH_STORE, $extension->getName(), $extension->serialize());
     $this->redisClient->hset(self::EXTENSION2USER_HASH_STORE, $extension->getName(), $user->getName());
     $meta = ['watchers' => $extension->getStars(), 'stars' => $extension->getWatchers()];
     $this->redisClient->hset(self::EXTENSIONMETA_HASH_STORE, $extension->getName(), json_encode($meta));
 }
コード例 #2
0
ファイル: Rest.php プロジェクト: Doanlmit/pickleweb
 /**
  * @return
  */
 public function update()
 {
     $extensionRepository = $this->app->container->get('extension.repository');
     $vendorDir = $this->app->config('json_path') . '/' . $this->extension->getVendor();
     if (!is_dir($vendorDir)) {
         mkdir($vendorDir);
     }
     $jsonPackage = $this->extension->serialize();
     $repositoryName = $this->extension->getPackageName();
     $this->sha = hash('sha256', $jsonPackage);
     $jsonPathSha = $vendorDir . '/' . $repositoryName . '$' . $this->sha . '.json';
     file_put_contents($jsonPathSha, $jsonPackage);
     $linkPath = $vendorDir . '/' . $repositoryName . '.json';
     if (file_exists($linkPath)) {
         $targetPath = readlink($linkPath);
         unlink($linkPath);
     }
     symlink($jsonPathSha, $vendorDir . '/' . $repositoryName . '.json');
     $shaProviders = $this->updateProviders();
     $this->updateRootPackageJson($shaProviders);
 }
コード例 #3
0
 /**
  * POST /package/register.
  */
 public function registerPackageAction()
 {
     $token = $_SESSION['github.token'];
     $repo = $this->app->request()->post('repository');
     $log = new BufferIO();
     try {
         $driver = new \PickleWeb\Repository\Github($repo, $token, $this->app->config('cache_dir'), $log);
         if ($driver->getOwnerId() != $this->app->user()->getGithubId()) {
             $this->app->flash('error', 'You are not the owner of this repository. Please request the owner to register.');
             $this->app->redirect('/package/register?repository=' . $repo);
         }
         $extension = new \PickleWeb\Entity\Extension();
         $extension->setFromRepository($driver, $log);
         $redis = $this->app->container->get('redis.client');
         $extensionRepository = $this->app->container->get('extension.repository');
         if ($extensionRepository->find($extension->getName())) {
             $this->app->flash('error', $extension->getName() . ' is already registred');
             $this->app->redirect('/package/register?repository=' . $repo);
             return;
         }
         $extension->setStars($driver->getStars());
         $extension->setWatchers($driver->getWatchers());
         $vendorName = $extension->getVendor();
         $repository = $extension->getPackageName();
         $extensionMeta = ['watchers' => $extension->getStars(), 'stars' => $extension->getWatchers()];
     } catch (\RuntimeException $exception) {
         /* todo: handle bad data in a better way =) */
         $this->app->flash('error', 'An error occurred while retrieving extension data. Please veriry your tag and try again later.' . $exception->getMessage());
         $this->app->redirect('/package/register?repository=' . $repo);
     }
     $serializedExtension = $extension->serialize();
     $transaction = hash('sha256', $serializedExtension);
     file_put_contents($this->app->config('cache_dir') . '/' . $transaction . '.json', $serializedExtension);
     $serializedMeta = json_encode($extensionMeta);
     file_put_contents($this->app->config('cache_dir') . '/' . $transaction . '_meta.json', $serializedMeta);
     $latest = $extension->getPackages()['dev-master'];
     $this->app->render('extension/confirm.html', ['log' => $log->getOutput(), 'transaction' => $transaction, 'latest' => $latest, 'tags' => $extension->getPackages(), 'vcs' => $repo]);
 }
コード例 #4
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;
 }