Skip to content

Commit 817bb8f

Browse files
committed
Improve github, bitbucket url matchers, php 5.3 compat
1 parent fdc0002 commit 817bb8f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

composer-lock-diff

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ function makeCompareUrl($pkg, $diff) {
213213
}
214214

215215
function getSourceRepoType($url) {
216-
if (preg_match('/^git@bitbucket.org:(.*)\.git$/', $url)) {
216+
if (preg_match('/^git@bitbucket\..+:.+\.git$/', $url)) {
217217
return 'bitbucket';
218218
}
219-
if (preg_match('/^git@github.com:(.*)\.git$/', $url)) {
219+
if (preg_match('/^git@github\..+:.+\.git$/', $url)) {
220220
return 'github';
221221
}
222222
if (preg_match('/^git@gitlab\..+:.+\.git$/', $url)) {
@@ -245,12 +245,18 @@ function formatCompareUnknown($url, $from, $to) {
245245
}
246246

247247
function formatCompareGithub($url, $from, $to) {
248-
$url = preg_replace(['/\.git$/', '/^git@github.com:/'], ['', 'https://github.com/'], $url);
248+
if (strpos($url, 'http') === false) {
249+
$url = preg_replace('/^git@(github\.[^:]+):/', 'https://$1/', $url);
250+
}
251+
$url = preg_replace('/\.git$/', '', $url);
249252
return sprintf('%s/compare/%s...%s', $url, urlencode($from), urlencode($to));
250253
}
251254

252255
function formatCompareBitbucket($url, $from, $to) {
253-
$url = preg_replace(['/\.git$/', '/^git@bitbucket.org:/'], ['', 'https://bitbucket.org/'], $url);
256+
if (strpos($url, 'http') === false) {
257+
$url = preg_replace('/^git@(bitbucket\.[^:]+):/', 'https://$1/', $url);
258+
}
259+
$url = preg_replace('/\.git$/', '', $url);
254260
return sprintf('%s/branches/compare/%s%%0D%s', $url, urlencode($to), urlencode($from));
255261
}
256262

0 commit comments

Comments
 (0)