Add more checks in parse_metadata.py for the upstream_repository field (#10513)

This commit is contained in:
Alex Waygood
2023-07-28 14:04:58 +01:00
committed by GitHub
parent 852882b8bf
commit 0d8a6bc200
2 changed files with 26 additions and 8 deletions

View File

@@ -255,16 +255,18 @@ async def get_github_repo_info(session: aiohttp.ClientSession, stub_info: StubIn
Else, return None.
"""
if stub_info.upstream_repository:
# We have various sanity checks for the upstream_repository field in tests/parse_metadata.py,
# so no need to repeat all of them here
split_url = urllib.parse.urlsplit(stub_info.upstream_repository)
if split_url.netloc == "github.com" and not split_url.query and not split_url.fragment:
if split_url.netloc == "github.com":
url_path = split_url.path.strip("/")
if len(Path(url_path).parts) == 2:
github_tags_info_url = f"https://api.github.com/repos/{url_path}/tags"
async with session.get(github_tags_info_url, headers=get_github_api_headers()) as response:
if response.status == 200:
tags: list[dict[str, Any]] = await response.json()
assert isinstance(tags, list)
return GithubInfo(repo_path=url_path, tags=tags)
assert len(Path(url_path).parts) == 2
github_tags_info_url = f"https://api.github.com/repos/{url_path}/tags"
async with session.get(github_tags_info_url, headers=get_github_api_headers()) as response:
if response.status == 200:
tags: list[dict[str, Any]] = await response.json()
assert isinstance(tags, list)
return GithubInfo(repo_path=url_path, tags=tags)
return None