15

Is there a way to grep for partial words inside all code belonging to a GitHub Organization, using the web UI?

Of course, the intent is to avoid having to clone all the organization's repositories and do a local grep; that would be a cumbersome, tedious and error-prone task.

I'm aware of Search code inside a Github project, but I find the search is very misleading as it doesn't really find all results.

For example, I want to find all uses of the string DISABLE_LIBRARIES_GENERATION in all files from the Kurento organization. Using any of these Advanced Search terms

DISABLE_LIBRARIES_GENERATION user:Kurento
DISABLE_LIBRARIES_GENERATION org:Kurento

yields these results:

  • Finds ${DISABLE_LIBRARIES_GENERATION} in kms-core/src/server/CMakeLists.txt.
  • Finds set (DISABLE_LIBRARIES_GENERATION FALSE in kms-core/CMake/CodeGenerator.cmake.
  • Finds the string in kms-core/debian/changelog.
  • Doesn't find -DDISABLE_LIBRARIES_GENERATION=TRUE as used in adm-scripts/kurento_get_version.sh, adm-scripts/kurento_generate_js_module.sh and adm-scripts/kurento_generate_java_module.sh.
Community
  • 1
  • 1
j1elo
  • 1,029
  • 8
  • 21
  • @Val the original post included the tag [tag:elasticsearch] because GitHub's search is based on Elasticsearch, and the answer to this question may be a matter of finding the proper syntax. I'm not sure I agree to removing that tag. – j1elo May 10 '17 at 12:24
  • 2
    Github does indeed use ES underneath, but the advanced search syntax is their own and not at all related to ES. They probably do all kinds of stuff (cleaning, etc) in between and the user input in the search box is most certainly not sent verbatim to ES. – Val May 10 '17 at 12:26
  • I understand, and now I agree to removing it. Thanks for the explanation. – j1elo May 10 '17 at 12:28
  • My bad, I should have commented why I removed the tag in the first place ;-) – Val May 10 '17 at 12:29

1 Answers1

20

The answer to my question is: No, it is not currently possible.

Source
I contacted GitHub with this same question, and their response included this explanation:

Currently, we do not support substring matching in our search. We do break words apart for common variable naming patterns like camel case, so if your variable is named something like myNewVariable, you could search for "my new variable" and this would show up.

However, in your example, the string "-DDISABLE_LIBRARIES_GENERATION=TRUE" wouldn't be broken into substrings like this, so "disable_libraries_generation" would not result in a match.

[...] cloning the repository and using grep or another search functionality locally is likely your best option in this case.

UPDATE (2021-12-14)
On December 8, 2021, GitHub announced code search improvements, including "Search for an exact string, with support for substring matches". This is still a technology preview (available here: https://cs.github.com/), but when fully integrated, looks like it might be a satisfactory answer to this question.

UPDATE (2023-05-08)
Now that GitHub code search is generally available, a search such as DISABLE_LIBRARIES_GENERATION org:Kurento is able to find instances such as -DDISABLE_LIBRARIES_GENERATION=TRUE.

Thus, I'm happy to say that 6 years after the question was posted, we can give it the closure it deserved with a glorious yes, at last it works :-)

j1elo
  • 1,029
  • 8
  • 21
  • 2
    Nice to know. At the end of 2021 the same thing. If you have `myNewVariable`, `hisNewVariable` then looking for `NewVariable` in the repository returns nothing but `new variable` will return both results. – Cheburek Dec 01 '21 at 12:09
  • Search still not fixed in January 2023, just sad, a rant here: https://twitter.com/martinkrung/status/1619288727410581504?s=20&t=4pT9w-3aFvw1hvzD9FVilw – Martin Krung Jan 28 '23 at 11:17