When the "contact" field in the metadata dictionary contains a link to a GitHub profile instead of a repository, the following error is raised:
Traceback (most recent call last):
File "/home/paulb/.pyenv/versions/modpack-creator/lib/python3.10/site-packages/tenacity/_asyncio.py", line 51, in __call__
result = await fn(*args, **kwargs)
File "/home/paulb/.pyenv/versions/modpack-creator/lib/python3.10/site-packages/mmc_export/Helpers/resourceAPI.py", line 99, in _get_github
owner, repo = parsed_link.path[1:].split('/')[:2]
ValueError: not enough values to unpack (expected 2, got 1)
This is caused by the _get_github function trying to unpack the link into two parts (owner and repository), but only receiving one when the link is not to a repository.
Reproduce
Run the function with the following meta, or another meta containing a link to a github profile page in the contact dictionary. This one is the meta from the Not Enough Animations mod:
The program should not raise an error and should handle the link to the GitHub profile appropriately.
Actual Results
The program raises a ValueError and fails to handle the link to the GitHub profile.
Reproducibility
This bug can be reproduced consistently by adding a link to a GitHub profile in the "contact" field of the metadata dictionary.
Fix
To fix this issue, the _get_github function should check if the link points to a repository or a profile before attempting to unpack it. If it is a profile, the function should handle it appropriately without trying to unpack it into two parts. Below is a modified version of the function with this fix implemented:
async def _get_github(self, meta: dict, resource: Resource) -> None:
if "contact" not in meta or "GitHub" in self.excluded_providers:
return
for link in meta['contact'].values():
parsed_link = urlparse(link)
if parsed_link.netloc == "github.com":
path_parts = parsed_link.path[1:].split('/')
if len(path_parts) < 2:
resource.links.append(f"https://github.com/{path_parts[0]}")
else:
owner, repo = path_parts[:2]
repo = repo.removesuffix(".git")
resource.links.append(f"https://github.com/{owner}/{repo}")
break
else:
return
!!!The fix was generated by chatGPT. It's just an idea of how to fix it and I didn't test it myself.!!! (I think you use owner variable lower in the same function for example)
Bug in _get_github function
Description
When the "contact" field in the metadata dictionary contains a link to a GitHub profile instead of a repository, the following error is raised:
This is caused by the _get_github function trying to unpack the link into two parts (owner and repository), but only receiving one when the link is not to a repository.
Reproduce
Run the function with the following meta, or another meta containing a link to a github profile page in the contact dictionary. This one is the meta from the Not Enough Animations mod:
Expected Results
The program should not raise an error and should handle the link to the GitHub profile appropriately.
Actual Results
The program raises a ValueError and fails to handle the link to the GitHub profile.
Reproducibility
This bug can be reproduced consistently by adding a link to a GitHub profile in the "contact" field of the metadata dictionary.
Fix
To fix this issue, the _get_github function should check if the link points to a repository or a profile before attempting to unpack it. If it is a profile, the function should handle it appropriately without trying to unpack it into two parts. Below is a modified version of the function with this fix implemented:
!!!The fix was generated by chatGPT. It's just an idea of how to fix it and I didn't test it myself.!!! (I think you use owner variable lower in the same function for example)