Github API - Finding Repos with Specific Labels

Hey GH Community! 

I’m working on a Hacktoberfest project and am having trouble with the GitHub API. I’m trying to query all repositories that match a specific language and have an open issue with a specific label, but I don’t want to lose the repo details. 

For example, find all Python repositories that have open issues with a label of “bug”. There is an example of this in the docs: While this works, it actually doesn’t give you the name of the repo or description. 

https://api.github.com/search/issues?q=label:bug+language:python+state:open&sort=created&order=desc

When searching by repos, you can get the name and description, but you lose all issue/label info. 

https://api.github.com/search/repositories?q=language:python&sort=stars&order=desc

Is there another query or alternate endpoint I could use that would provide me with both? :confused:

Hey dude! :wave:t3:

Since REST APIs typically have a single endpoint per resource, you would probably need to run a query like the above first, then get the IDs for the repos you’re interested in and fire off subsequent request(s) to get the labels, issues, etc. within each of those repos.

Since I’m a GraphQL fanboy (:stuck_out_tongue:) and GitHub has a fantasic GraphQL API, I would suggest looking into using their GraphQL API for this. Especially since it sounds like what you want to do is query for both the repos matching certain parameters, as well as data about those repos all at the same time – that’s where the data graph that GraphQL bring to the table shines. :star2:

Check out the first query in this post:

https://medium.com/@fabiomolinar/using-githubs-graphql-to-retrieve-a-list-of-repositories-their-commits-and-some-other-stuff-ccbbb4e96d78

I think you’ll need to do something similar. You can see that he’s searching for certain repos, then for each node, getting the info he wants for each repo.

And instead of doing


edges {

  node {

    ...

  }

}

like in that example, you could simplify it to just:


nodes {

  ...

}

GitHub’s GraphQL API documentation is here: https://developer.github.com/v4/

Best of luck! Lemme know how it turns out! :raised_hands:t3:

2 Likes