javascript - 我怎样才能找到我在 github api 上搜索的提交?

标签 javascript github fetch github-api

我正在为 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 字符串

<表类="s-表"> <头> 搜索 GitHub 提交信息 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}`);

关于javascript - 我怎样才能找到我在 github api 上搜索的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70977951/

相关文章:

git - fork 后在 devOps 上设置 git 的默认存储库

github - 带有 GitHub Markdown 的表格中的图像

Javascript 生成具有等效突出显示的随机颜色

docker - 无法将 github 公共(public)存储库克隆到 Dockerfile 的运行顺序中

javascript - $数据刷新超时服务不起作用(Angularjs)

promise - 如何使用 SWR nextjs hook 在一个页面中进行多个调用?

sql-server - 如何在 SQL Server 中使用 OFFSET 和 Fetch 而无需 Order by

ios - 核心数据简单获取

javascript - 从匿名函数中访问 "this"

javascript - Heroku 上传 Node 应用程序和 Java jar