Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a GitHub fork for code using the GitHub Search API?

I can't figure out how to get search results from a fork of a GitHub repository.

I'm using the GitHub API for this, but I can reproduce the problem using the search dialogs on github.com. Here's an example: The repository PEZ/Sketch-Plugin-Testing-Repo is a fork of getflourish/Sketch-Mate. They both contain a manifest.json file with several mentions of the word shortcut. The GitHub Code Search documentation says:

Much like with repositories, you can opt to search code files that exist within forked repositories. However, to ensure better relevancy, repository forks will not be searchable unless the fork has more stars than the parent repository.

If you would like forked results to appear, add the fork:true qualifier. For example:

android language:java fork:true Matches code in a forked repository with the word "android" that's written in Java.

Thus, a search for shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate fork:true, should return results from both repos. But it contains no search results at all.

Omitting the fork:true qualifier - shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate, we do get search results from the original (non-fork) repository.

What am I not understanding in this?

To make things a bit more mysterious consider the repository repo:TeamTwisted/external_chromium_org which is a fork of OptiPop/external_chromium_org. These two repositories also contain manifest.json files containing the word shortcut.

Searching for shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate repo:TeamTwisted/external_chromium_org repo:OptiPop/external_chromium_org fork:true, includes results only from the TeamTwisted/external_chromium_org repository. While omitting the fork:true qualifier return results from all repositories except PEZ/Sketch-Plugin-Testing-Repo.

Anyone has a clue on what's going on? Is the PEZ/Sketch-Plugin-Testing-Repo just fully unsearchable for some reason? The only thing special with my testing repo would be that it is a freshly made fork. Maybe I forked it off on November 8 or some such (two days ago at the time of this writing).

Ideally I'd like to use one search query and get back results from a given set of repositories wether they are forks or not. But to just consistently get results from forks would be a good start...

like image 540
PEZ Avatar asked Nov 10 '15 09:11

PEZ


1 Answers

You reached out to GitHub support as well, so I wanted to share the answer you got from Jess here, in case that helps.

When a fork has less stars than its parent, it is not indexed at all for code search. So it won't show up even when you use fork:true. The fork:true search filter is used to show results for forks that have been indexed for search.

In the example of the TeamTwisted/external_chromium_org fork, that code is searchable because it has more stars than its parent repo. However the PEZ/Sketch-Plugin-Testing-Repo fork does not, so it won't be searchable at all with any filter.

like image 76
Ivan Zuzak Avatar answered Sep 28 '22 14:09

Ivan Zuzak