简体   繁体   English

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

[英]how can i find a commit which i searched on github api?

I am developing an extension for github.我正在为 github 开发一个扩展。 I need search a commit.我需要搜索提交。 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} but it doesn't work. 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}但它不起作用。 So how can I find a commit i'm looking for in github api?那么如何在 github api 中找到我正在寻找的提交?

Read this: GitHub API Docs In the original documentation it says to use get get /repos/{owner}/{repo}/commits .阅读以下内容: GitHub API 文档在原始文档中,它说使用 get get /repos/{owner}/{repo}/commits The error may be caused by this.错误可能是由此引起的。 You should go through the documentation again.您应该再次通过文档 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"
      }

If you examine the Respons you can see the message column, maybe this will help.如果您检查响应,您可以看到消息列,也许这会有所帮助。 I also found this in another question GET https://api.github.com/repos/izuzak/pmrpc/commits?path=examples&page=1&per_page=1我还在另一个问题GET https://api.github.com/repos/izuzak/pmrpc/commits?path=examples&page=1&per_page=1中发现了这一点

You can use the search commit API .您可以使用搜索提交 API It's flexible enough to search by different qualifiers, like committer username, author, repository, organization, etc.它足够灵活,可以通过不同的限定符进行搜索,例如提交者用户名、作者、存储库、组织等。

Take into account, there is a time limit for running your search, in case you exceed the time limit, the API returns the matches that were already found prior to the timeout, and the response has the incomplete_results property set to true, read more about it here考虑到运行搜索有时间限制,如果超过时间限制,API 会返回在超时之前已经找到的匹配项,并且响应的不完整结果属性设置为 true,阅读更多关于它在这里

Here's an example using Octokit that searches inside GitHub org the test string这是一个使用Octokit的示例,它在 GitHub org 中搜索测试字符串

Search GitHub commit message搜索 GitHub 提交信息 View in Fusebit 在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM