浏览代码

Add better support for bitbucket browsable URLs

Jordi Boggiano 6 年之前
父节点
当前提交
652947a73f

+ 14 - 0
src/Packagist/WebBundle/Entity/Package.php

@@ -631,6 +631,20 @@ class Package
         return $this->repository;
         return $this->repository;
     }
     }
 
 
+    /**
+     * Get a user-browsable version of the repository URL
+     *
+     * @return string $repository
+     */
+    public function getBrowsableRepository()
+    {
+        if (preg_match('{(://|@)bitbucket.org[:/]}i', $this->repository)) {
+            return preg_replace('{^(?:git@|https://|git://)bitbucket.org[:/](.+?)(?:\.git)?$}i', 'https://bitbucket.org/$1', $this->repository);
+        }
+
+        return preg_replace('{^(git://github.com/|git@github.com:)}', 'https://github.com/', $this->repository);
+    }
+
     /**
     /**
      * Add versions
      * Add versions
      *
      *

+ 1 - 1
src/Packagist/WebBundle/Resources/views/Package/viewPackage.html.twig

@@ -124,7 +124,7 @@
                                 {% endif %}
                                 {% endif %}
                             </p>
                             </p>
 
 
-                            {% set repoUrl = package.repository|replace({'git://github.com/': 'https://github.com/', 'git@github.com:': 'https://github.com/'}) %}
+                            {% set repoUrl = package.browsableRepository %}
                             <p class="canonical">
                             <p class="canonical">
                                 <a href="{{ repoUrl }}" title="Canonical Repository URL">{{ repoUrl|replace({'https://':'', 'http://':''}) }}</a>
                                 <a href="{{ repoUrl }}" title="Canonical Repository URL">{{ repoUrl|replace({'https://':'', 'http://':''}) }}</a>
                             </p>
                             </p>