Skip to content

Commit

Permalink
Add bitbucket (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm authored Nov 17, 2024
1 parent e884733 commit 1f96ee3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ToCloneUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ public static function fromRepoAndToken(string $repo, string $authToken) : strin
case 'gitlab.com':
$repo_path = sprintf('https://oauth2:%[email protected]%s', $authToken, $repo_parsed["path"]);
break;

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']
);
}
break;
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ public static function provideAllCases() : array
'token123',
'https://oauth2:[email protected]/user/repo.git',
],
[
'https://bitbucket.org/user/repo.git',
'token123',
'https://x-token-auth:[email protected]/user/repo.git',
],
[
'https://www.bitbucket.org/user/repo.git',
'token123',
'https://x-token-auth:[email protected]/user/repo.git',
],
[
'https://www.bitbucket.org/user/repo.git',
'user:token123',
'https://user:[email protected]/user/repo.git',
],
];
}
}

0 comments on commit 1f96ee3

Please sign in to comment.