Finding uses of an API with the new GitHub Code Search
The GitHub Code Search beta is really powerful - it allows advanced search - including regular expression matches - against every public repo on GitHub.
It’s still in a preview (December 2022) - you can request access here.
Today I used it to figure out who was using a specific internal API from Datasette that I’m considering changing for Datasette 1.0.
The API is the permission_allowed(self, actor, action, resource=None, default=False) method - it’s intended to be used by plugins that need to check if a user has permission to perform a specific action.
I use it a lot in my own plugins, but I wanted to see if anyone else was using it for theirs.
After some perusing of their documentation I came up with this:
datasette permission_allowed -user:simonw -path:datasette/** -path:docs/** -path:tests/** language:python
datasette permission_allowedsearches for files that use both of those terms. I could also have used".permission_allowed("to find things that are definitely method calls - or crafted a regular expression - but for this search just the keywords worked fine.-user:simonwfilters out everything from my own repos - I write a lot of plugins that use this, but I didn’t want to see those in the search results-path:datasette/**filters out anything in a file within adatasette/parent folder. Without this my search was returning results from forks of my own simonw/datasette repository, which I didn’t want to see. I was hoping I could exclude-repo:*/datasetteor similar but that’s not currently supported.-path:docs/** -path:tests/**do the same thing but for mentions indocs/ortests/root dirctories.language:pythonrestricts the results to Python files (presumably.pyand.ipynband similar).
If you have access to the beta you can try that search here.
See also my research notes in this issue.