Veronica
Veronica

Reputation: 290

Download GitHub repositories list matching a topic?

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

Answers (4)

vaughan
vaughan

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

die
die

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'

Source: https://help.github.com/en/enterprise/2.13/user/articles/searching-code#:~:text=You%20can%20search%20for%20code%20globally%20across%20all%20of%20GitHub,%22About%20searching%20on%20GitHub.%22

Upvotes: 0

Bertrand Martel
Bertrand Martel

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

metamattj
metamattj

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

Related Questions