简体   繁体   中英

In Github's GraphQL API how to get repositories that do not have a particular repositoryTopic?

With Github's GraphQL API I recently found " Github API: Getting topics of a Github repository " that mentions you can get a count of topics:

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

but in the docs and in my search I'm not finding how I can query repositories that do not contain the topic template , example:

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
            }
          }
        }
      }
    }
  }
}

is the correct implementation to use after ? In Github's GraphQL API how to exclude a repository if it contains a certain topic?

My understanding is that with the organization query you cannot do that kind of repository filtering.

Instead, you can use the search query with something like this:

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

The above query searches for all repositories within a given organization that have a given topic.

But you were looking for the repositories without a topic, in theory according to the documentation you should be able to do that with -topic:my-topic . Unfortunately the negation on topic doesn't work, there seems to be a bug . :-(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM