diff --git a/swh/core/github/tests/test_github_utils.py b/swh/core/github/tests/test_github_utils.py --- a/swh/core/github/tests/test_github_utils.py +++ b/swh/core/github/tests/test_github_utils.py @@ -18,9 +18,9 @@ KNOWN_GH_REPO = "https://github.com/user/repo" -def _url_github_html(user_repo: str, protocol: str = "https") -> str: +def _url_github_html(user_repo: str, protocol: str = "https://") -> str: """Given the user repo, returns the expected github html url.""" - return f"{protocol}://github.com/{user_repo}" + return f"{protocol}github.com/{user_repo}" @pytest.mark.parametrize( @@ -39,7 +39,16 @@ user_repo, expected_url, requests_mock, github_credentials ): """It should return a canonical github origin when it exists, None otherwise""" - for protocol in ["https", "git", "http"]: + for protocol in [ + "http://", + "https://", + "git://", + "ssh://", + "//", + "git@", + "ssh://git@", + "https://${env.GITHUB_TOKEN_USR}:${env.GITHUB_TOKEN_PSW}@", + ]: html_input_url = _url_github_html(user_repo, protocol=protocol) html_url = _url_github_html(user_repo) api_url = _url_github_api(_sanitize_github_url(user_repo)) diff --git a/swh/core/github/utils.py b/swh/core/github/utils.py --- a/swh/core/github/utils.py +++ b/swh/core/github/utils.py @@ -19,7 +19,9 @@ wait_exponential, ) -GITHUB_PATTERN = re.compile(r"(git|https?)://github.com/(?P.*)") +GITHUB_PATTERN = re.compile( + r"(//|git://|git@|git//|https?://|ssh://|.*@)github.com[/:](?P.*)" +) logger = logging.getLogger(__name__)