Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Url/GitGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
);
Expand All @@ -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()
);
Expand Down
6 changes: 4 additions & 2 deletions src/Url/GitlabGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
29 changes: 26 additions & 3 deletions tests/Url/GitlabGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
);
}

Expand Down Expand Up @@ -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',
),
);
}

Expand Down