我想知道如何从我的分叉存储库中获取原始存储库。
我正在使用https://api.github.com/users/:user/repos?type=forks
来获取分叉存储库列表。它返回了forks上的各种链接,但我找不到如何获取原始存储库。
有什么想法吗?
注意:循环https://api.github.com/users/:user/events
答案 0 :(得分:3)
您可以仅使用您提到的端点加载分叉存储库的列表:
curl https://api.github.com/users/:user/repos?type=forks
将返回类似以下 JSON Feed的内容(省略不相关的信息):
[
{
"id": 24328834,
"name": "repo_name",
"full_name": ":user/repo_name",
"owner": {
}
...
"url": "https://api.github.com/repos/:user/repo_name",
...
}
{
"id": 24328835,
"name": "repo_name_2",
"full_name": ":user/repo_name_2",
"owner": {
...
}
...
"url": "https://api.github.com/repos/:user/repo_name_2"
...
}
]
然后,从返回的列表中,取出 name 元素键下的 repo_name ,并使用它来构建存储库URL,或者只是引用< strong> url 元素发出GET请求,如下所示:
curl https://api.github.com/repos/:user/repo_name
作为回报,它将为您提供所请求的用户存储库信息(请注意,这是最简单的查询网址),您可以从中检索:
类似下面的内容(这里的父项只是源代码,即存储库是从原始库中分叉出来的):
{
"id": 24328834,
"name": "repo_name",
"full_name": "user/repo_name",
"owner": {
...
},
...
"parent": {
"id": 354448,
"name": "repo_name",
"full_name": "real_owner_name/repo_name",
"owner": {
...
}
}
"source": {
"id": 354448,
"name": "repo_name",
"full_name": "real_owner_name/repo_name",
"owner": {
...
}
}
}