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

标签 python git-fork github3.py

给定一个 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/

相关文章:

python - github3.py 带有 IssueEvents 的 AttributeError

python - unittest.Mock - 结合 return_value 和 side_effect

python - 将一列数据帧转换为基于其他列的 numpy 数组或张量

python 使用 pool.map_async 时没有输出

git - 设置 fork 仓库的 pull 请求默认分支

python - Python/Django 中 PHP "ob"函数的等效函数

git - 删除 GitHub 存储库的分支是否安全,当原始文件引用我的时?

python - 列出用户的 repo

python - github3.py 登录时用户属性错误