diff --git a/src/Url/GitGenerator.php b/src/Url/GitGenerator.php index cad212e..5aa4b68 100644 --- a/src/Url/GitGenerator.php +++ b/src/Url/GitGenerator.php @@ -38,7 +38,7 @@ protected function getCompareRef(PackageInterface $package) protected function getUser(PackageInterface $package) { return preg_replace( - "/^https:\/\/{$this->getQuotedDomain()}\/([^\/]+)\/([^\/]+)$/", + "/^https:\/\/{$this->getQuotedDomain()}\/(.+)\/([^\/]+)$/", '$1', $this->getRepositoryUrl($package) ); @@ -50,7 +50,7 @@ protected function getUser(PackageInterface $package) protected function getRepo(PackageInterface $package) { return preg_replace( - "/^https:\/\/{$this->getQuotedDomain()}\/([^\/]+)\/([^\/]+)$/", + "/^https:\/\/{$this->getQuotedDomain()}\/(.+)\/([^\/]+)$/", '$2', $this->getRepositoryUrl($package) ); @@ -62,7 +62,7 @@ protected function getRepo(PackageInterface $package) protected function getRepositoryUrl(PackageInterface $package) { $httpsUrl = preg_replace( - "/^git@({$this->getQuotedDomain()}):([^\/]+)\/([^\/]+)(\.git)?$/", + "/^git@({$this->getQuotedDomain()}):(.+)\/([^\/]+)(\.git)?$/", 'https://$1/$2/$3', $package->getSourceUrl() ); diff --git a/src/Url/GitlabGenerator.php b/src/Url/GitlabGenerator.php index 05fc823..89f20e2 100644 --- a/src/Url/GitlabGenerator.php +++ b/src/Url/GitlabGenerator.php @@ -39,9 +39,11 @@ public function getCompareUrl(PackageInterface $initialPackage, PackageInterface $baseUrl = $this->getRepositoryUrl($initialPackage); $baseMaintainer = $this->getUser($initialPackage); $targetMaintainer = $this->getUser($targetPackage); - $targetVersion = ($baseMaintainer !== $targetMaintainer ? $targetMaintainer.':' : '').$this->getCompareRef($targetPackage); + if ($baseMaintainer !== $targetMaintainer ) { + return $this->getReleaseUrl($targetPackage); // Could not get a compare URL, using release URL instead + } - return sprintf('%s/compare/%s...%s', $baseUrl, $this->getCompareRef($initialPackage), $targetVersion); + return sprintf('%s/compare/%s...%s', $baseUrl, $this->getCompareRef($initialPackage), $this->getCompareRef($targetPackage)); } /** diff --git a/tests/Url/GitlabGeneratorTest.php b/tests/Url/GitlabGeneratorTest.php index a8b589e..6c9ec71 100644 --- a/tests/Url/GitlabGeneratorTest.php +++ b/tests/Url/GitlabGeneratorTest.php @@ -26,9 +26,17 @@ public function releaseUrlProvider() 'https://gitlab.acme.org/acme/package/tags/3.12.1', ), 'dev version' => array( - $this->getPackageWithSource('acme/package', 'dev-master', 'git@gitlab.acme.org:acme/package'), + $this->getPackageWithSource('acme/package', 'dev-master', 'git@gitlab.acme.org:ac/me/package'), null, ), + 'https in subgroup' => array( + $this->getPackageWithSource('ac/me/package', '3.12.1', 'https://gitlab.acme.org/ac/me/package.git'), + 'https://gitlab.acme.org/ac/me/package/tags/3.12.1', + ), + 'ssh in subgroup' => array( + $this->getPackageWithSource('ac/me/package', '3.12.1', 'git@gitlab.acme.org:ac/me/package.git'), + 'https://gitlab.acme.org/ac/me/package/tags/3.12.1', + ), ); } @@ -58,18 +66,33 @@ public function compareUrlProvider() 'compare with base fork' => array( $this->getPackageWithSource('acme/package', '3.12.0', 'https://gitlab.acme.org/IonBazan/package.git'), $this->getPackageWithSource('acme/package', '3.12.1', 'https://gitlab.acme.org/acme/package.git'), - 'https://gitlab.acme.org/IonBazan/package/compare/3.12.0...acme:3.12.1', + 'https://gitlab.acme.org/acme/package/tags/3.12.1', ), 'compare with head fork' => array( $this->getPackageWithSource('acme/package', '3.12.0', 'https://gitlab.acme.org/acme/package.git'), $this->getPackageWithSource('acme/package', '3.12.1', 'https://gitlab.acme.org/IonBazan/package.git'), - 'https://gitlab.acme.org/acme/package/compare/3.12.0...IonBazan:3.12.1', + 'https://gitlab.acme.org/IonBazan/package/tags/3.12.1', ), 'compare with different repository provider' => array( $this->getPackageWithSource('acme/package', '3.12.0', 'https://gitlab.acme.org/acme/package.git'), $this->getPackageWithSource('acme/package', '3.12.1', 'https://gitlab.org/acme/package.git'), null, ), + 'compare from https in subgroup' => array( + $this->getPackageWithSource('acme/package', '3.12.0', 'https://gitlab.acme.org/ac/me/package'), + $this->getPackageWithSource('acme/package', '3.12.1', 'https://gitlab.acme.org/ac/me/package'), + 'https://gitlab.acme.org/ac/me/package/compare/3.12.0...3.12.1', + ), + 'compare from ssh in subgroup' => array( + $this->getPackageWithSource('acme/package', '3.12.0', 'git@gitlab.acme.org:ac/me/package.git'), + $this->getPackageWithSource('acme/package', '3.12.1', 'git@gitlab.acme.org:ac/me/package.git'), + 'https://gitlab.acme.org/ac/me/package/compare/3.12.0...3.12.1', + ), + 'compare with base fork from subgroups' => array( + $this->getPackageWithSource('acme/package', '3.12.0', 'https://gitlab.acme.org/Ion/Bazan/package.git'), + $this->getPackageWithSource('acme/package', '3.12.1', 'https://gitlab.acme.org/ac/me/package.git'), + 'https://gitlab.acme.org/ac/me/package/tags/3.12.1', + ), ); }