xaav 13 年之前
父節點
當前提交
e1d780134f

+ 3 - 15
src/Packagist/WebBundle/Command/UpdatePackagesCommand.php

@@ -63,10 +63,8 @@ EOF
 
         foreach ($qb->getQuery()->getResult() as $package) {
 
-            $repo = $provider->getRepository($package->getRepository());
-
             // Process GitHub via API
-            if ($repo) {
+            if ($repo = $provider->getRepository($package->getRepository())) {
 
                 $owner = $repo->getOwner();
                 $repository = $repo->getRepository();
@@ -78,8 +76,6 @@ EOF
                     continue;
                 }
 
-                $tagsData = $repo->getTagsData();
-
                 foreach ($repo->getAllComposerFiles() as $uniqid => $data) {
 
                     // TODO parse $data['version'] w/ composer version parser, if no match, ignore the tag
@@ -115,15 +111,7 @@ EOF
                     $version->setUpdatedAt(new \DateTime);
                     $version->setReleasedAt(new \DateTime($data['time']));
                     $version->setSource(array('type' => 'git', 'url' => $repo->getSource()));
-
-                    if ($repoData['repository']['has_downloads']) {
-                        //TODO: Abstraction broke this
-                        $downloadUrl = 'https://github.com/'.$owner.'/'.$repository.'/zipball/'.$tag;
-                        $checksum = hash_file('sha1', $downloadUrl);
-                        $version->setDist(array('type' => 'zip', 'url' => $downloadUrl, 'shasum' => $checksum ?: ''));
-                    } else {
-                        // TODO clone the repo and build/host a zip ourselves. Not sure if this can happen, but it'll be needed for non-GitHub repos anyway
-                    }
+                    $version->setDist($repo->getDist($uniqid));
 
                     if (isset($data['keywords'])) {
                         foreach ($data['keywords'] as $keyword) {
@@ -177,7 +165,7 @@ EOF
                 // TODO parse composer.json on every branch matching a "$num.x.x" version scheme, + the master one, for all "x.y.z-dev" versions, usable through "latest-dev"
             } else {
                 // TODO support other repos
-                //$output->writeln('Err: unsupported repository: '.$repo->getSource());
+                $output->writeln('Err: unsupported repository: '.$package->getRepository());
                 continue;
             }
             $package->setUpdatedAt(new \DateTime);

+ 12 - 1
src/Packagist/WebBundle/Repository/Repository/GitRepository.php

@@ -50,6 +50,17 @@ class GitRepository implements RepositoryInterface
         return $this->repository;
     }
 
+    public function getDist($tag)
+    {
+        $repoData = $this->getRepoData();
+        if ($repoData['repository']['has_downloads']) {
+            $downloadUrl = 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$tag;
+            $checksum = hash_file('sha1', $downloadUrl);
+            return array('type' => 'zip', 'url' => $downloadUrl, 'shasum' => $checksum ?: '');
+        } else {
+            // TODO clone the repo and build/host a zip ourselves. Not sure if this can happen, but it'll be needed for non-GitHub repos anyway
+        }
+    }
 
     public function getAllComposerFiles()
     {
@@ -58,7 +69,7 @@ class GitRepository implements RepositoryInterface
         $tagsData = $this->getTagsData();
         foreach ($tagsData['tags'] as $tag => $hash) {
             if($file = $this->getComposerFile($hash)) {
-                $files[$hash] = $file;
+                $files[$tag] = $file;
             }
         }
 

+ 2 - 0
src/Packagist/WebBundle/Repository/Repository/RepositoryInterface.php

@@ -10,4 +10,6 @@ interface RepositoryInterface
      * The array shall be in the form of $unique_identifier => $composer_file
      */
     public function getAllComposerFiles();
+
+    public function getDist($unique_identifier);
 }