Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using github search api without specifying the repository or organization

I want to get a list of repositories or files where the contents of the files contained in the repositories match the keywords I specify in the search. I tried doing a simple search using https GET request and it looks like the search is not possible without specifying the repository or organization name. I get the below error.

https://api.github.com/search/code?q=authorization+in:file

{
  "message": "Validation Failed",
  "errors": [
    {
      "message": "Must include at least one user, organization, or repository",
      "resource": "Search",
      "field": "q",
      "code": "invalid"
    }
  ],
  "documentation_url": "https://developer.github.com/v3/search/#search-code"
}

I understand that searching without repository or organization name will be resource-intensive operation. Is there any work-around for this? I was assuming that since I am able to get results by using online search, I should be able to achieve the same using git search api.

So basically I am trying to simulate the below:

https://github.com/search?utf8=%E2%9C%93&q=authorization&type=Code&ref=searchresults

like image 396
Zack Avatar asked Feb 09 '15 04:02

Zack


People also ask

How do I search for a specific project on GitHub?

GitHub Codesearch can be found at github.com/codesearch and will let you type in anything you're looking for in source code and get highlighted results of any files in our public repositories that match.

Can I use GitHub as a API?

If you want to use the GitHub REST API for personal use, you can create a personal access token. The REST API operations used in this article require repo scope for personal access tokens (classic) or, unless otherwise noted, read-only access to public repositories for fine-grained personal access tokens.

Does GitHub search support regex?

Github has its own search syntax with qualifiers you can add, but not full regex. The api uses the same syntax as the in-browser search. Save this answer.


1 Answers

Is there any work-around for this? I was assuming that since I am able to get results by using online search, I should be able to achieve the same using git search api.

The behavior you observed is expected for now -- you indeed need to specify a user, org or repository when using the code search API (something you don't need to do when using the Web UI), and currently there is no way around that.

https://developer.github.com/changes/2013-10-18-new-code-search-requirements/

like image 67
Ivan Zuzak Avatar answered Sep 19 '22 17:09

Ivan Zuzak