如何找到我在 github api 上搜索的提交?
how can i find a commit which i searched on github api?
我正在为 github 开发一个扩展。我需要搜索提交。我正在使用 github api,首先我尝试获取 api 上的所有提交,但每页的最大值为 100。其次我尝试 https://api.github.com/repos/{owner}/{repo}/commits?q={commit_message}
但它不起作用。那么如何在 github api 中找到我正在寻找的提交?
读这个:GitHub API Docs
在原始文档中它说使用 get get /repos/{owner}/{repo}/commits
。错误可能由此引起。你应该再看一遍文档。
await octokit.request('GET /repos/{owner}/{repo}/commits', {
owner: 'octocat',
repo: 'hello-world'
})
[
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"node_id": "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
"commit": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"author": {
"name": "Monalisa Octocat",
"email": "support@github.com",
"date": "2011-04-14T16:00:49Z"
},
"committer": {
"name": "Monalisa Octocat",
"email": "support@github.com",
"date": "2011-04-14T16:00:49Z"
},
"message": "Fix all the bugs",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
如果您检查“回复”,您会看到消息列,这也许会有所帮助。我还在 another question GET https://api.github.com/repos/izuzak/pmrpc/commits?path=examples&page=1&per_page=1
中找到了这个
可以使用search commit API。它足够灵活,可以通过不同的限定符进行搜索,例如提交者用户名、作者、存储库、组织等。
请注意,运行 您的搜索有时间限制,如果您超过时间限制,API returns 之前已经找到的匹配项超时,并且响应将 incomplete_results 属性 设置为 true,阅读更多相关信息 here
这是一个使用 Octokit 在 GitHub 组织中搜索 test 字符串
的示例
Search GitHub commit message
View in Fusebit
const text = 'test';
const org = 'github';
const query =`${text} org:${org}`;
const searchResult = await github.rest.search.commits({
q: query
});
// In case there is a timeout running the query, you can use incomplete_results to check if there are likely more results
// for your query, read more here https://docs.github.com/en/rest/reference/search#timeouts-and-incomplete-results
const { items, total_count} = searchResult.data;
console.log(items.map(commit => commit.commit));
console.log(`Found ${total_count} commits for ${text} at GitHub org called ${org}`);
我正在为 github 开发一个扩展。我需要搜索提交。我正在使用 github api,首先我尝试获取 api 上的所有提交,但每页的最大值为 100。其次我尝试 https://api.github.com/repos/{owner}/{repo}/commits?q={commit_message}
但它不起作用。那么如何在 github api 中找到我正在寻找的提交?
读这个:GitHub API Docs
在原始文档中它说使用 get get /repos/{owner}/{repo}/commits
。错误可能由此引起。你应该再看一遍文档。
await octokit.request('GET /repos/{owner}/{repo}/commits', {
owner: 'octocat',
repo: 'hello-world'
})
[
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"node_id": "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
"commit": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"author": {
"name": "Monalisa Octocat",
"email": "support@github.com",
"date": "2011-04-14T16:00:49Z"
},
"committer": {
"name": "Monalisa Octocat",
"email": "support@github.com",
"date": "2011-04-14T16:00:49Z"
},
"message": "Fix all the bugs",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
如果您检查“回复”,您会看到消息列,这也许会有所帮助。我还在 another question GET https://api.github.com/repos/izuzak/pmrpc/commits?path=examples&page=1&per_page=1
可以使用search commit API。它足够灵活,可以通过不同的限定符进行搜索,例如提交者用户名、作者、存储库、组织等。
请注意,运行 您的搜索有时间限制,如果您超过时间限制,API returns 之前已经找到的匹配项超时,并且响应将 incomplete_results 属性 设置为 true,阅读更多相关信息 here
这是一个使用 Octokit 在 GitHub 组织中搜索 test 字符串
的示例Search GitHub commit message | View in Fusebit |
---|
const text = 'test';
const org = 'github';
const query =`${text} org:${org}`;
const searchResult = await github.rest.search.commits({
q: query
});
// In case there is a timeout running the query, you can use incomplete_results to check if there are likely more results
// for your query, read more here https://docs.github.com/en/rest/reference/search#timeouts-and-incomplete-results
const { items, total_count} = searchResult.data;
console.log(items.map(commit => commit.commit));
console.log(`Found ${total_count} commits for ${text} at GitHub org called ${org}`);