我正在为Github开发一个扩展程序,需要搜索一个提交(commit)。我使用Github API进行开发。首先,我尝试从API获取所有提交,但每页最大值是100。其次,我尝试了https://api.github.com/repos/{owner}/{repo}/commits?q={commit_message}
,但它不起作用。那么我该如何在Github API中找到我要寻找的提交(commit)呢?
我正在为Github开发一个扩展程序,需要搜索一个提交(commit)。我使用Github API进行开发。首先,我尝试从API获取所有提交,但每页最大值是100。其次,我尝试了https://api.github.com/repos/{owner}/{repo}/commits?q={commit_message}
,但它不起作用。那么我该如何在Github API中找到我要寻找的提交(commit)呢?
搜索 GitHub 提交信息 | 本地运行 |
---|
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}`);
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"
}
如果您检查响应,可以看到消息列,也许这会有所帮助。我还在另一个问题中找到了这个GET https://api.github.com/repos/izuzak/pmrpc/commits?path=examples&page=1&per_page=1