github3.py 可以用来查找分叉回购的 parent/upstream 吗?
Can github3.py be used to find the parent/upstream of a forked repo?
给定一个分叉的仓库,我如何使用 github3.py 找到它从中分叉的父仓库或上游仓库?使用 requests 相当容易,但我不知道如何在 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? 类似,但我们还需要检查 parent/upstream 用户回购从中分叉出来的回购。
文档显示它存储为 repo.parent,但是,仅在 Repository
对象上可用。 repositories_by
returns ShortRepository
个对象。
这看起来像:
for short_repo in gh.repositories_by(username):
repo = short_repo.refresh()
if repo.fork:
parent = repo.parent
给定一个分叉的仓库,我如何使用 github3.py 找到它从中分叉的父仓库或上游仓库?使用 requests 相当容易,但我不知道如何在 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? 类似,但我们还需要检查 parent/upstream 用户回购从中分叉出来的回购。
文档显示它存储为 repo.parent,但是,仅在 Repository
对象上可用。 repositories_by
returns ShortRepository
个对象。
这看起来像:
for short_repo in gh.repositories_by(username):
repo = short_repo.refresh()
if repo.fork:
parent = repo.parent