下载 GitHub 个与主题匹配的存储库列表?

Download GitHub repositories list matching a topic?

有没有办法下载与 GitHub 主题匹配的项目列表? 例如,如果我写:

https://github.com/topics/haskell

在网络浏览器中,returns 一个页面包含 GitHub 个与 Haskell 相关的项目。我读了他们的 GitHub API 但他们似乎没有实现该功能:https://developer.github.com/v3/

端点 https://api.github.com/ does not seem to contain any option. All I get for my attempts like https://api.github.com/topics/haskell 也是:

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

主题的正确 GitHub API 端点是:https://api.github.com/search/topics 并且您需要在 q 查询参数中提供主题查询。这是直接来自 API documentation:

的示例查询
curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=ruby+is:featured'

下面是一个查找您的搜索主题的示例 'haskell':

curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=haskell'

见: https://developer.github.com/v3/search/#search-topics

如果要搜索与主题匹配的存储库,请使用 /search/repositoriestopic 属性:

curl -H "Accept: application/vnd.github.mercy-preview+json" \
    https://api.github.com/search/repositories?q=topic:haskell

您必须在开发人员预览版中提供 application/vnd.github.mercy-preview+json

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

“您可以在所有 GitHub 企业中全局搜索代码,或在特定存储库或组织中搜索代码。要在所有 public 存储库中搜索代码,您必须已签名进入 GitHub 企业帐户。"

此 curl 只会 return 个标签或主题 curl -H 'Accept: application/vnd.github.mercy-preview+json' 'https://api.github.com/search/topics?q=haskell'

来源: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

您可以使用 GraphQL API 获取主题中的存储库。

试用: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": ".../..."
        },
...

警告:您不能使用 GraphQL api 获取主题列表。

主题查询受限

Query.topic搜索单个主题和Repository.repositoryTopicsTopic.relatedTopics 存在为“相关主题列表,包括该主题的别名,最相关的排在最前面。Returns 最多 10 个主题。”。