GraphQL API v4 - search for specific file and specific text

I’ve been trying to find a way to use GraphQL to search for all repos (above a certain star count) which contain a file named “AndroidManifest.xml”.  However, with the sparse query documentation on GraphQL I have found so far it doesn’t seem like this is possible.

Is there a way to search all repos in github for any repo that contains a file named “AndroidManifest.xml”?

If that’s possible is there anyway to search within that specific file (in repos that contain it) to see if certain strings are present?

I’ve been able to put together something in Rest API v3 to achieve this but was interested in trying to get it working with Graphql, due to the large volume of extra info the rest queries pull back.

Thanks

You can almost do what you’re asking. You can’t perform a single search that searches repositories based on star count  and presence of a file with specific contents. But you can search for repositories based on star count and then dive into each one to see if they have a file by a certain name. I was able to put this together:

{
  search(query: "stars:>=100", type: REPOSITORY, last: 10) {
    edges {
      node {
        ... on Repository {
          nameWithOwner
          object(expression: "master:README.md") {
            ... on Blob {
              text
            }
          }
        }
      }
    }
  }
}

So what this query does is:

  1. Gets all repositories with greater than 100 stars
  2. In those repositories, gets the nameWithOwner attribute and the git object at master:README.md (see the git rev-parse documentation for syntax)
  3. Get the text of that git object, if it exists

Then you can search the text of each one that doesn’t return null for the git object to see if they match.

You might also be able to reverse the process by searching for files and then checking to see how many stars the repo it belongs to has. But I figured that searching repos will return fewer results than searching files, making the second step of the process easier.

I hope that helps!

4 Likes

Hello @dolos-lelantos,

Did you revolve this issue? I am trying to find a way to search for all repos which contain files with an specific name, but I have found problems with that. I would be grateful if you share your solucions.

Thanks