如何从一个GitHub repo list操作中获取所有fork源?
我想获取GitHub用户的所有源repo。我得分两步做。例如,首先,我可以使用如何从一个GitHub repo list操作中获取所有fork源?,github,github-api,go,Github,Github Api,go,我想获取GitHub用户的所有源repo。我得分两步做。例如,首先,我可以使用https://api.github.com/users/nmap/repos获取用户的所有回购nmap。但是源代码和父代码不存在。只有当我呼叫https://api.github.com/repos/nmap/:repo_name对于每次回购,我可以获得来源和父公司: { "id": 63894766, "name": "libpcap", "full_name": "nmap/libpcap", "
https://api.github.com/users/nmap/repos
获取用户的所有回购nmap
。但是源代码和父代码不存在。只有当我呼叫https://api.github.com/repos/nmap/:repo_name
对于每次回购,我可以获得来源和父公司:
{
"id": 63894766,
"name": "libpcap",
"full_name": "nmap/libpcap",
"owner": {
"login": "nmap",
"id": 63385,
"avatar_url": "https://avatars3.githubusercontent.com/u/63385?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nmap",
"html_url": "https://github.com/nmap",
"followers_url": "https://api.github.com/users/nmap/followers",
"following_url": "https://api.github.com/users/nmap/following{/other_user}",
"gists_url": "https://api.github.com/users/nmap/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nmap/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nmap/subscriptions",
"organizations_url": "https://api.github.com/users/nmap/orgs",
"repos_url": "https://api.github.com/users/nmap/repos",
"events_url": "https://api.github.com/users/nmap/events{/privacy}",
"received_events_url": "https://api.github.com/users/nmap/received_events",
"type": "Organization",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/nmap/libpcap",
"description": "the LIBpcap interface to various kernel packet capture mechanism",
"fork": true,
"url": "https://api.github.com/repos/nmap/libpcap",
"forks_url": "https://api.github.com/repos/nmap/libpcap/forks",
"keys_url": "https://api.github.com/repos/nmap/libpcap/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/nmap/libpcap/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/nmap/libpcap/teams",
"hooks_url": "https://api.github.com/repos/nmap/libpcap/hooks",
"issue_events_url": "https://api.github.com/repos/nmap/libpcap/issues/events{/number}",
"events_url": "https://api.github.com/repos/nmap/libpcap/events",
"assignees_url": "https://api.github.com/repos/nmap/libpcap/assignees{/user}",
"branches_url": "https://api.github.com/repos/nmap/libpcap/branches{/branch}",
"tags_url": "https://api.github.com/repos/nmap/libpcap/tags",
"blobs_url": "https://api.github.com/repos/nmap/libpcap/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/nmap/libpcap/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/nmap/libpcap/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/nmap/libpcap/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/nmap/libpcap/statuses/{sha}",
"languages_url": "https://api.github.com/repos/nmap/libpcap/languages",
"stargazers_url": "https://api.github.com/repos/nmap/libpcap/stargazers",
"contributors_url": "https://api.github.com/repos/nmap/libpcap/contributors",
"subscribers_url": "https://api.github.com/repos/nmap/libpcap/subscribers",
"subscription_url": "https://api.github.com/repos/nmap/libpcap/subscription",
"commits_url": "https://api.github.com/repos/nmap/libpcap/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/nmap/libpcap/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/nmap/libpcap/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/nmap/libpcap/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/nmap/libpcap/contents/{+path}",
"compare_url": "https://api.github.com/repos/nmap/libpcap/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/nmap/libpcap/merges",
"archive_url": "https://api.github.com/repos/nmap/libpcap/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/nmap/libpcap/downloads",
"issues_url": "https://api.github.com/repos/nmap/libpcap/issues{/number}",
"pulls_url": "https://api.github.com/repos/nmap/libpcap/pulls{/number}",
"milestones_url": "https://api.github.com/repos/nmap/libpcap/milestones{/number}",
"notifications_url": "https://api.github.com/repos/nmap/libpcap/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/nmap/libpcap/labels{/name}",
"releases_url": "https://api.github.com/repos/nmap/libpcap/releases{/id}",
"deployments_url": "https://api.github.com/repos/nmap/libpcap/deployments",
"created_at": "2016-07-21T18:55:31Z",
"updated_at": "2017-11-12T14:13:21Z",
"pushed_at": "2016-10-27T03:27:01Z",
"git_url": "git://github.com/nmap/libpcap.git",
"ssh_url": "git@github.com:nmap/libpcap.git",
"clone_url": "https://github.com/nmap/libpcap.git",
"svn_url": "https://github.com/nmap/libpcap",
"homepage": "http://www.tcpdump.org/",
"size": 7706,
"stargazers_count": 10,
"watchers_count": 10,
"language": "C",
"has_issues": false,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"forks_count": 6,
"mirror_url": null,
"archived": false,
"open_issues_count": 0,
"license": null,
"forks": 6,
"open_issues": 0,
"watchers": 10,
"default_branch": "master",
"organization": {
"login": "nmap",
"id": 63385,
"avatar_url": "https://avatars3.githubusercontent.com/u/63385?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nmap",
"html_url": "https://github.com/nmap",
"followers_url": "https://api.github.com/users/nmap/followers",
"following_url": "https://api.github.com/users/nmap/following{/other_user}",
"gists_url": "https://api.github.com/users/nmap/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nmap/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nmap/subscriptions",
"organizations_url": "https://api.github.com/users/nmap/orgs",
"repos_url": "https://api.github.com/users/nmap/repos",
"events_url": "https://api.github.com/users/nmap/events{/privacy}",
"received_events_url": "https://api.github.com/users/nmap/received_events",
"type": "Organization",
"site_admin": false
},
"parent": {
"id": 9435887,
"name": "libpcap",
"full_name": "the-tcpdump-group/libpcap",
"owner": {
"login": "the-tcpdump-group",
"id": 4154908,
"avatar_url": "https://avatars0.githubusercontent.com/u/4154908?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/the-tcpdump-group",
"html_url": "https://github.com/the-tcpdump-group",
"followers_url": "https://api.github.com/users/the-tcpdump-group/followers",
"following_url": "https://api.github.com/users/the-tcpdump-group/following{/other_user}",
"gists_url": "https://api.github.com/users/the-tcpdump-group/gists{/gist_id}",
"starred_url": "https://api.github.com/users/the-tcpdump-group/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/the-tcpdump-group/subscriptions",
"organizations_url": "https://api.github.com/users/the-tcpdump-group/orgs",
"repos_url": "https://api.github.com/users/the-tcpdump-group/repos",
"events_url": "https://api.github.com/users/the-tcpdump-group/events{/privacy}",
"received_events_url": "https://api.github.com/users/the-tcpdump-group/received_events",
"type": "Organization",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/the-tcpdump-group/libpcap",
"description": "the LIBpcap interface to various kernel packet capture mechanism",
"fork": false,
"url": "https://api.github.com/repos/the-tcpdump-group/libpcap",
"forks_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/forks",
"keys_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/teams",
"hooks_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/hooks",
"issue_events_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/issues/events{/number}",
"events_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/events",
"assignees_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/assignees{/user}",
"branches_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/branches{/branch}",
"tags_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/tags",
"blobs_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/statuses/{sha}",
"languages_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/languages",
"stargazers_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/stargazers",
"contributors_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/contributors",
"subscribers_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/subscribers",
"subscription_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/subscription",
"commits_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/contents/{+path}",
"compare_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/merges",
"archive_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/downloads",
"issues_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/issues{/number}",
"pulls_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/pulls{/number}",
"milestones_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/milestones{/number}",
"notifications_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/labels{/name}",
"releases_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/releases{/id}",
"deployments_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/deployments",
"created_at": "2013-04-14T21:46:36Z",
"updated_at": "2017-12-13T16:20:18Z",
"pushed_at": "2017-12-11T20:56:20Z",
"git_url": "git://github.com/the-tcpdump-group/libpcap.git",
"ssh_url": "git@github.com:the-tcpdump-group/libpcap.git",
"clone_url": "https://github.com/the-tcpdump-group/libpcap.git",
"svn_url": "https://github.com/the-tcpdump-group/libpcap",
"homepage": "https://www.tcpdump.org/",
"size": 10255,
"stargazers_count": 686,
"watchers_count": 686,
"language": "C",
"has_issues": true,
"has_projects": false,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"forks_count": 328,
"mirror_url": null,
"archived": false,
"open_issues_count": 97,
"license": {
"key": "other",
"name": "Other",
"spdx_id": null,
"url": null
},
"forks": 328,
"open_issues": 97,
"watchers": 686,
"default_branch": "master"
},
"source": {
"id": 9435887,
"name": "libpcap",
"full_name": "the-tcpdump-group/libpcap",
"owner": {
"login": "the-tcpdump-group",
"id": 4154908,
"avatar_url": "https://avatars0.githubusercontent.com/u/4154908?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/the-tcpdump-group",
"html_url": "https://github.com/the-tcpdump-group",
"followers_url": "https://api.github.com/users/the-tcpdump-group/followers",
"following_url": "https://api.github.com/users/the-tcpdump-group/following{/other_user}",
"gists_url": "https://api.github.com/users/the-tcpdump-group/gists{/gist_id}",
"starred_url": "https://api.github.com/users/the-tcpdump-group/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/the-tcpdump-group/subscriptions",
"organizations_url": "https://api.github.com/users/the-tcpdump-group/orgs",
"repos_url": "https://api.github.com/users/the-tcpdump-group/repos",
"events_url": "https://api.github.com/users/the-tcpdump-group/events{/privacy}",
"received_events_url": "https://api.github.com/users/the-tcpdump-group/received_events",
"type": "Organization",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/the-tcpdump-group/libpcap",
"description": "the LIBpcap interface to various kernel packet capture mechanism",
"fork": false,
"url": "https://api.github.com/repos/the-tcpdump-group/libpcap",
"forks_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/forks",
"keys_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/teams",
"hooks_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/hooks",
"issue_events_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/issues/events{/number}",
"events_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/events",
"assignees_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/assignees{/user}",
"branches_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/branches{/branch}",
"tags_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/tags",
"blobs_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/statuses/{sha}",
"languages_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/languages",
"stargazers_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/stargazers",
"contributors_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/contributors",
"subscribers_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/subscribers",
"subscription_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/subscription",
"commits_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/contents/{+path}",
"compare_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/merges",
"archive_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/downloads",
"issues_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/issues{/number}",
"pulls_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/pulls{/number}",
"milestones_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/milestones{/number}",
"notifications_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/labels{/name}",
"releases_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/releases{/id}",
"deployments_url": "https://api.github.com/repos/the-tcpdump-group/libpcap/deployments",
"created_at": "2013-04-14T21:46:36Z",
"updated_at": "2017-12-13T16:20:18Z",
"pushed_at": "2017-12-11T20:56:20Z",
"git_url": "git://github.com/the-tcpdump-group/libpcap.git",
"ssh_url": "git@github.com:the-tcpdump-group/libpcap.git",
"clone_url": "https://github.com/the-tcpdump-group/libpcap.git",
"svn_url": "https://github.com/the-tcpdump-group/libpcap",
"homepage": "https://www.tcpdump.org/",
"size": 10255,
"stargazers_count": 686,
"watchers_count": 686,
"language": "C",
"has_issues": true,
"has_projects": false,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"forks_count": 328,
"mirror_url": null,
"archived": false,
"open_issues_count": 97,
"license": {
"key": "other",
"name": "Other",
"spdx_id": null,
"url": null
},
"forks": 328,
"open_issues": 97,
"watchers": 686,
"default_branch": "master"
},
"network_count": 328,
"subscribers_count": 8
}
我只想知道叉子的来源。e、 g.通过nmap/libpcap
了解tcpdump组/libpcap
。我想知道是否有一种方法可以只需一步就从GitHub repo list操作中获取所有fork源代码 您可以使用获取特定用户/组织的分叉回购列表,并获取父回购名称:
{
组织(登录名:“nmap”){
存储库(first:100,isFork:true){
边缘{
节点{
母公司{
所有者姓名
}
}
}
}
}
}
示例使用:
主程序包
进口(
“fmt”
“编码/json”
“net/http”
“字节”
“io/ioutil”
)
var token string=“您的\u访问\u令牌”
func main(){
jsonMap:=映射[string]字符串{“查询”:`{
组织(登录名:“nmap”){
存储库(first:100,isFork:true){
页面信息{
下一页
结束光标
}
边缘{
节点{
母公司{
所有者姓名
}
}
}
}
}
}
`}
jsonData,:=json.Marshal(jsonMap)
客户端:=&http.client{}
req,u3;:=http.NewRequest(“POST”https://api.github.com/graphql,bytes.NewBuffer(jsonData))
请求头添加(“授权”,fmt.Sprint(“令牌”,令牌))
req.Header.Add(“内容类型”、“应用程序/json”)
resp,u:=client.Do(请求)
fmt打印LN(各自状态)
如果resp.StatusCode==http.StatusOK{
bodyBytes,Util:=ioutil.ReadAll(resp.Body)
bodyString:=字符串(bodyBytes)
格式打印项次(正文)
}
}
要进行分页,您可以检查hasNextPage
值,检查是否必须发送另一个查询以获取下一个100叉式回购,在RepositoryConnection
中使用after
获取给定光标后的下一个100值(如果hasNextPage
为true
,则存储上一个endCursor
的值)
第一项请求:
{
组织(登录名:“appcelerator forks”){
存储库(first:100,isFork:true){
页面信息{
下一页
结束光标
}
边缘{
节点{
母公司{
所有者姓名
}
}
}
}
}
}
给出“hasNextPage”:true
和“endCursor”:“Y3Vyc29yOnYyOpHOAQ1VZg==”
。下一个请求将是:
{
组织(登录名:“appcelerator forks”){
存储库(first:100,isFork:true,后面是:“Y3Vyc29yOnYyOpHOAQ1VZg=”){
页面信息{
下一页
结束光标
}
边缘{
节点{
母公司{
所有者姓名
}
}
}
}
}
}
我用它进行了测试。效果很好。但是我用的是Golang,很难开发Golang GraphQL客户端。有没有办法用传统的REST API v3来实现这一点?这段代码太棒了!它可以在一个请求中完成我的任务。但是我发现它只能获得100条记录。那么如何获得101-200条记录呢?@hsluoyz我已经更新了一些关于pagin的详细信息这就做到了: