gpt4 book ai didi

python - github3.py 可以用来查找 fork 存储库的父级/上游吗?

转载 作者:行者123 更新时间:2023-12-01 09:31:16 27 4
gpt4 key购买 nike

给定一个 fork 的存储库,我如何使用 github3.py 找到它 fork 的父存储库或上游存储库?对于请求来说这相当容易,但我不知道如何在 github3.py 中做到这一点。

有请求:

for repo in gh.repositories_by(username):  # github3.py provides a user's repos
if repo.fork: # we only care about forked repos
assert 'parent' not in repo.as_dict() # can't find parent using github3.py
repo_info = requests.get(repo.url).json() # try with requests instead
assert 'parent' in repo_info, repo_info # can find parent using requests
print(f'{repo_info["url"]} was forked from {repo_info["parent"]["url"]}')
# https://github.com/username/repo was forked from
# https://github.com/parent/repo

此用例类似于 How can I find all public repos in github that a user contributes to?但我们还需要检查用户的存储库从中 fork 的父/上游存储库。

最佳答案

文档显示它存储为 repo.parent ,但是,它仅适用于 Repository 对象。 repositories_by 返回 ShortRepository 对象。

这看起来像:

for short_repo in gh.repositories_by(username):
repo = short_repo.refresh()
if repo.fork:
parent = repo.parent

关于python - github3.py 可以用来查找 fork 存储库的父级/上游吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49955138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com