【问题标题】:In Github's GraphQL API how to get repositories that do not have a particular repositoryTopic?在 Github 的 GraphQL API 中如何获取没有特定存储库主题的存储库?
【发布时间】:2022-07-30 21:48:24
【问题描述】:

通过 Github 的 GraphQL API,我最近发现了“Github API: Getting topics of a Github repository”,它提到您可以获得主题计数:

{
  repository(owner: "twbs", name: "bootstrap") {
    repositoryTopics(first: 10) {
      edges {
        node {
          topic {
            name
          }
        }
      }
    }
  }
}

但在文档和搜索中,我没有找到如何查询不包含主题 template 的存储库,例如:

query ($github_org: String!, $repo_count: Int!) {
  organization(login: $github_org) {
    repositories(first: $repo_count, privacy: PUBLIC, isFork: false) {
      nodes {
        id
        name
        openGraphImageUrl
        createdAt
        stargazerCount
        url
        description
        repositoryTopics(first: 10, after: "template") {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

使用after 是否正确?在 Github 的 GraphQL API 中,如果存储库包含某个主题,如何排除它?

【问题讨论】:

  • 嘿。这不是after 的正确用法。 after 参数用于传递要在“之后”获得结果的游标。您可以在页面对象中获取节点的光标。

标签: github graphql github-api github-graphql


【解决方案1】:

我的理解是,使用 organization 查询您无法进行那种存储库过滤。

相反,您可以使用 search 查询,如下所示:

query ($repo_count: Int!) {
  search (first: $repo_count,
          type: REPOSITORY,
          query: "org:my-organization topic:my-topic") {
    nodes {
      ... on Repository {
        name
      }
    }
  }
}

上述查询搜索给定组织内具有给定主题的所有存储库。

但是您正在寻找没有主题的存储库,理论上根据to the documentation,您应该能够使用-topic:my-topic 做到这一点。不幸的是,对主题的否定不起作用,似乎有a bug。 :-(

【讨论】:

    猜你喜欢
    • 2019-12-18
    • 2017-09-01
    • 2020-03-16
    • 2021-10-11
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 2019-07-12
    相关资源
    最近更新 更多