给定一个分叉的仓库,我如何使用 github3.py 来找到它被分叉的父仓库或上游仓库?这对于请求来说相当容易,但我不知道如何在 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
此用例类似于如何在 github 中找到用户贡献的所有公共存储库?但我们还需要检查用户的 repo 来自的父/上游 repo。