我正在为 github 开发一个扩展。我需要搜索提交。我正在使用 github api,首先我尝试获取 api 上的所有提交,但每页的最大值为 100。其次我尝试了 https://api.github.com/repos/{owner}/{repo}/commits ?q={commit_message}
但它不起作用。那么如何在 github api 中找到我正在寻找的提交?
最佳答案
您可以使用 search commit API .它足够灵活,可以通过不同的限定符进行搜索,例如提交者用户名、作者、存储库、组织等。
请注意,运行搜索有时间限制,如果您超过时间限制,API 会返回在超时之前已经找到的匹配项,并且响应具有 incomplete_results 属性设置为 true,阅读更多信息 here
这是一个使用 Octokit 的例子在 GitHub 组织中搜索 test 字符串
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}`);
关于javascript - 我怎样才能找到我在 github api 上搜索的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70977951/