Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to exclude paths in a GitHub Search API request?

I'm using the GitHub Code Search API in a tool I'm building for my organization.

I'd like to provide search functionality throughout our repos so you can search for a word (E.g. "array") and find it in any of the .md files inside any of the repos in our organization. (The use-case for this tool prevents us from using the in-platform search feature so I need to use the API.)

The problem I'm facing is that I'm getting results from our vendored lib folders. I would like to exclude those.

Is it possible to provide the Search API with an additional parameter to exclude (for example) folders named "lib" from the search results?

Here's an example of the query I'm currently using:

 https://api.github.com/search/code?q=user:bradsk88+extension:js+array&per_page=2

I've tried using path:!lib to no avail:

https://api.github.com/search/code?q=user:bradsk88+extension:js+path:!lib+array&per_page=2

... this gives me no results, despite the word "array" appearing in several of my repos

{
  "total_count": 0,
  "incomplete_results": false,
  "items": []
}
like image 868
Brad Johnson Avatar asked Mar 08 '23 07:03

Brad Johnson


1 Answers

You can add an exclude rule by using -QUALIFIER :

q=user:bradsk88+extension:js+array+-path:lib
like image 192
Bertrand Martel Avatar answered Apr 27 '23 05:04

Bertrand Martel