如果是分叉回购,我如何使用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中找到用户贡献的所有公共回复?,但我们也需要检查用户回购的父/上游回购。
发布于 2018-04-22 18:31:51
文档显示,这是以repo.parent的形式存储的,但是只能在Repository对象上使用。repositories_by返回ShortRepository对象。
这看起来应该是:
for short_repo in gh.repositories_by(username):
repo = short_repo.refresh()
if repo.fork:
parent = repo.parenthttps://stackoverflow.com/questions/49955138
复制相似问题