Reputation: 290
Is there any way to download a list of projects matching a GitHub topic? For example if I write:
https://github.com/topics/haskell
in a web browser, returns a page with GitHub projects related with Haskell. I read their GitHub API but they don't seem to implement the feature: https://developer.github.com/v3/
Also the endpoint https://api.github.com/ does not seem to contain any option. All I get for my attempts like https://api.github.com/topics/haskell is:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
Upvotes: 5
Views: 1750
Reputation: 7473
You can use the GraphQL API to get the repositories in a topic.
Try it out at: https://docs.github.com/en/graphql/overview/explorer
query {
search(first: 10, type: REPOSITORY, query: "topic:databases") {
repositoryCount
nodes {
... on Repository {
nameWithOwner
}
}
}
}
{
"data": {
"search": {
"repositoryCount": 831,
"nodes": [
{
"nameWithOwner": ".../..."
},
{
"nameWithOwner": ".../..."
},
...
Caveat: You cannot use the GraphQL api to get the list of topics.
Topic querying is limited.
There is Query.topic
to search for a single topic and Repository.repositoryTopics
. Topic.relatedTopics
exists as "A list of related topics, including aliases of this topic, sorted with the most relevant first. Returns up to 10 Topics.".
Upvotes: 0
Reputation: 1
"You can search for code globally across all of GitHub Enterprise, or search for code within a particular repository or organization. To search for code across all public repositories, you must be signed in to a GitHub Enterprise account."
This curl will only return tags or topics curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=haskell'
Upvotes: 0
Reputation: 45433
If you want to search repositories matching a topic, use /search/repositories
with topic
properties :
curl -H "Accept: application/vnd.github.mercy-preview+json" \
https://api.github.com/search/repositories?q=topic:haskell
You have to provide the application/vnd.github.mercy-preview+json
while it's still in developer preview :
Note: The topics property for repositories on GitHub is currently available for developers to preview. To view the topics property in calls that return repository results, you must provide a custom media type in the Accept header:
application/vnd.github.mercy-preview+json
Upvotes: 5
Reputation: 148
The correct GitHub API endpoint for topics is: https://api.github.com/search/topics
and you need to provide the topic query in the q
query parameter. Here's an example query directly from the API documentation:
curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=ruby+is:featured'
And here's an example looking for your search topic 'haskell':
curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=haskell'
See: https://developer.github.com/v3/search/#search-topics
Upvotes: 2