-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure bitbucket always ends with .git
- Loading branch information
Showing
2 changed files
with
30 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,8 @@ public static function fromRepoAndToken(string $repo, string $authToken) : strin | |
if (!empty($repo_parsed)) { | ||
switch ($repo_parsed['_protocol']) { | ||
case '[email protected]': | ||
$repo_path = sprintf('https://x-token-auth:%[email protected]/%s', $authToken, $repo_parsed['path']); | ||
if (strlen($authToken) < 50 && strpos($authToken, ':') !== false) { | ||
$repo_path = sprintf( | ||
'https://%[email protected]/%s', | ||
$authToken, | ||
$repo_parsed['path'] | ||
); | ||
} | ||
$path = sprintf('/%s', $repo_parsed['path']); | ||
$repo_path = self::replaceForBitbucket($authToken, $path); | ||
$has_replaced = true; | ||
break; | ||
|
||
|
@@ -58,18 +52,7 @@ public static function fromRepoAndToken(string $repo, string $authToken) : strin | |
|
||
case 'www.bitbucket.org': | ||
case 'bitbucket.org': | ||
$repo_path = sprintf( | ||
'https://x-token-auth:%[email protected]%s', | ||
$authToken, | ||
$repo_parsed["path"] | ||
); | ||
if (strlen($authToken) < 50 && strpos($authToken, ':') !== false) { | ||
$repo_path = sprintf( | ||
'https://%[email protected]%s', | ||
$authToken, | ||
$repo_parsed['path'] | ||
); | ||
} | ||
$repo_path = self::replaceForBitbucket($authToken, $repo_parsed['path']); | ||
break; | ||
|
||
default: | ||
|
@@ -114,4 +97,21 @@ public static function fromRepoAndToken(string $repo, string $authToken) : strin | |
} | ||
return $repo_path; | ||
} | ||
|
||
private static function replaceForBitbucket(string $authToken, string $path) | ||
{ | ||
$repo_path = sprintf('https://x-token-auth:%[email protected]%s', $authToken, $path); | ||
if (strlen($authToken) < 50 && strpos($authToken, ':') !== false) { | ||
$repo_path = sprintf( | ||
'https://%[email protected]%s', | ||
$authToken, | ||
$path | ||
); | ||
} | ||
// We also want to ensure it ends with .git. | ||
if (substr($repo_path, -4) !== '.git') { | ||
$repo_path .= '.git'; | ||
} | ||
return $repo_path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,11 @@ public static function provideAllCases() : array | |
'mytoken', | ||
'https://x-token-auth:[email protected]/user/repo.git', | ||
], | ||
[ | ||
'[email protected]:user/repo', | ||
'mytoken', | ||
'https://x-token-auth:[email protected]/user/repo.git', | ||
], | ||
[ | ||
'[email protected]:user/repo.git', | ||
'user:mytoken', | ||
|
@@ -69,6 +74,11 @@ public static function provideAllCases() : array | |
'token123', | ||
'https://x-token-auth:[email protected]/user/repo.git', | ||
], | ||
[ | ||
'https://www.bitbucket.org/user/repo', | ||
'token123', | ||
'https://x-token-auth:[email protected]/user/repo.git', | ||
], | ||
[ | ||
'https://www.bitbucket.org/user/repo.git', | ||
'user:token123', | ||
|