我如何找到我在 github api 上搜索的提交?

Fur*_*uzu 3 javascript github fetch github-api

我正在开发 github 的扩展。我需要搜索一个提交。我正在使用 github api,首先我尝试获取 api 上的所有提交,但每页的最大值是 100。其次我尝试了,https://api.github.com/repos/{owner}/{repo}/commits?q={commit_message}但它不起作用。那么我怎样才能在 github api 中找到我正在寻找的提交呢?

Rub*_*epo 6

您可以使用搜索提交 API。它足够灵活,可以按不同的限定符进行搜索,例如提交者用户名、作者、存储库、组织等。

\n

请考虑到,运行搜索有时间限制,如果超过时间限制,API 将返回超时之前已找到的匹配项,并且响应会将 incomplete_results 属性设置为 true,了解更多信息这里

\n

这是一个使用Octokit 的示例,它在 GitHub org 内搜索测试字符串

\n
\n\n\n\n\n\n\n\n
搜索 GitHub 提交消息 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2 \xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2 \xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2 \xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0Run locally\xc2\xa0
\n
\n
const text = \'test\';\nconst org = \'github\';\nconst query =`${text} org:${org}`;\nconst searchResult = await github.rest.search.commits({\n  q: query\n});\n  \n// In case there is a timeout running the query, you can use incomplete_results to check if there are likely more results\n// for your query, read more here https://docs.github.com/en/rest/reference/search#timeouts-and-incomplete-results\nconst { items, total_count} = searchResult.data;\nconsole.log(items.map(commit => commit.commit));\nconsole.log(`Found ${total_count} commits for ${text} at GitHub org called ${org}`);\n\n
Run Code Online (Sandbox Code Playgroud)\n