[英]how can i find a commit which i searched on github api?
我正在為 github 開發一個擴展。 我需要搜索提交。 I'm using github api, firstly i tried get all commits on api but max value of perpage is 100. Secondly i tried https://api.github.com/repos/{owner}/{repo}/commits?q={commit_message}
但它不起作用。 那么如何在 github api 中找到我正在尋找的提交?
閱讀以下內容: GitHub API 文檔在原始文檔中,它說使用 get get /repos/{owner}/{repo}/commits
。 錯誤可能是由此引起的。 您應該再次通過文檔 go 。
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
中發現了這一點
您可以使用搜索提交 API 。 它足夠靈活,可以通過不同的限定符進行搜索,例如提交者用戶名、作者、存儲庫、組織等。
考慮到運行搜索有時間限制,如果超過時間限制,API 會返回在超時之前已經找到的匹配項,並且響應的不完整結果屬性設置為 true,閱讀更多關於它在這里
這是一個使用Octokit的示例,它在 GitHub org 中搜索測試字符串
搜索 GitHub 提交信息 | 在 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}`);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.