浏览代码

Ensure a `composer.json` file is present before to fetch information.

That allows to fetch information from repositories which don't have a
`composer.json` file on all branches/tags.
William DURAND 13 年之前
父节点
当前提交
32be787e10

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

@@ -71,8 +71,9 @@ EOF
 
             try {
                 foreach ($repository->getTags() as $tag => $identifier) {
-                    // TODO parse tag name (or fetch composer file?) w/ composer version parser, if no match, ignore the tag
-                    $this->fetchInformation($output, $doctrine, $package, $repository, $identifier);
+                    if ($repository->hasComposerFile($identifier)) {
+                        $this->fetchInformation($output, $doctrine, $package, $repository, $identifier);
+                    }
                 }
 
                 foreach ($repository->getBranches() as $branch => $identifier) {

+ 14 - 3
src/Packagist/WebBundle/Repository/Repository/GitHubRepository.php

@@ -97,8 +97,19 @@ class GitHubRepository implements RepositoryInterface
      */
     public function getBranches()
     {
-        // TODO implement
-        return array();
+        if (null === $this->branches) {
+            $branchesData = json_decode(file_get_contents('http://github.com/api/v2/json/repos/show/'.$this->owner.'/'.$this->repository.'/branches'), true);
+            $this->branches = $branchesData['branches'];
+        }
+        return $this->branches;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function hasComposerFile($identifier)
+    {
+        return (false !== @fopen('https://raw.github.com/'.$this->owner.'/'.$this->repository.'/'.$identifier.'/composer.json', 'r'));
     }
 
     protected function getRepositoryData()
@@ -112,4 +123,4 @@ class GitHubRepository implements RepositoryInterface
         }
         return $this->repositoryData;
     }
-}
+}

+ 9 - 1
src/Packagist/WebBundle/Repository/Repository/RepositoryInterface.php

@@ -54,4 +54,12 @@ interface RepositoryInterface
      * @return string
      */
     function getType();
-}
+    /**
+     * Return true if the repository has a composer file for a given identifier,
+     * false otherwise.
+     *
+     * @param string $identifier Any identifier to a specific branch/tag/commit
+     * @return boolean Whether the repository has a composer file for a given identifier.
+     */
+    function hasComposerFile($identifier);
+}