我想知道如何从我的派生存储库中获取原始存储库。
我正在使用https://api.github.com/users/:user/repos?type=forks
来获取派生存储库的列表。它返回了各种分支的链接,但我找不到如何获取原始存储库。
有什么想法吗?
注意:还有一些循环遍历https://api.github.com/users/:user/events
的东西。
我想知道如何从我的派生存储库中获取原始存储库。
我正在使用https://api.github.com/users/:user/repos?type=forks
来获取派生存储库的列表。它返回了各种分支的链接,但我找不到如何获取原始存储库。
有什么想法吗?
注意:还有一些循环遍历https://api.github.com/users/:user/events
的东西。
curl https://api.github.com/users/:user/repos?type=forks
这将会返回类似以下的JSON数据流(省略了无关信息):
[
{
"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,或者只需引用 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": {
...
}
}
}
query {
viewer {
repositories(first:10) {
nodes {
name,
isFork,
parent {
url
}
}
}
}
}
输出
{
"data": {
"viewer": {
"repositories": {
"nodes": [
{
"name": "cucumber",
"isFork": true,
"parent": {
"url": "https://github.com/cucumber/cucumber-ruby"
}
},
...
]
}
}
}
}
parent.url
是从原始仓库克隆的分支的URL。