From bd444dd1977e64f7e9dc7379a19d09d0520bda15 Mon Sep 17 00:00:00 2001 From: Piotr Stankowski Date: Sun, 13 Jun 2021 19:28:15 +0200 Subject: [PATCH 1/3] Fix generating links for gitlab repos in subgroups --- src/Url/GitGenerator.php | 6 +++--- src/Url/GitlabGenerator.php | 6 ++++-- tests/Url/GitlabGeneratorTest.php | 29 ++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) 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..53772b6 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 null; + } - 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..8aae0b3 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', + null, ), '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', + null, ), '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'), + null, + ), ); } From cb45148d03156d2c439fa5a31472007b0674608c Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Mon, 14 Jun 2021 12:07:05 +0800 Subject: [PATCH 2/3] return release URL when it's not possible to generate a compare URL --- src/Url/GitlabGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Url/GitlabGenerator.php b/src/Url/GitlabGenerator.php index 53772b6..89f20e2 100644 --- a/src/Url/GitlabGenerator.php +++ b/src/Url/GitlabGenerator.php @@ -40,7 +40,7 @@ public function getCompareUrl(PackageInterface $initialPackage, PackageInterface $baseMaintainer = $this->getUser($initialPackage); $targetMaintainer = $this->getUser($targetPackage); if ($baseMaintainer !== $targetMaintainer ) { - return null; + return $this->getReleaseUrl($targetPackage); // Could not get a compare URL, using release URL instead } return sprintf('%s/compare/%s...%s', $baseUrl, $this->getCompareRef($initialPackage), $this->getCompareRef($targetPackage)); From b2ab777eb73573567055d1ad1a23827c944557d8 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Mon, 14 Jun 2021 12:10:44 +0800 Subject: [PATCH 3/3] fix test --- tests/Url/GitlabGeneratorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Url/GitlabGeneratorTest.php b/tests/Url/GitlabGeneratorTest.php index 8aae0b3..6c9ec71 100644 --- a/tests/Url/GitlabGeneratorTest.php +++ b/tests/Url/GitlabGeneratorTest.php @@ -66,12 +66,12 @@ 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'), - null, + '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'), - null, + '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'), @@ -91,7 +91,7 @@ public function compareUrlProvider() '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'), - null, + 'https://gitlab.acme.org/ac/me/package/tags/3.12.1', ), ); }