8

Based on my limited searching, it seems GraphQL can only support equal filtering. So,

Is it possible to do Github GraphQL searching with the filtering conditions of,

  • stars > 10
  • forks > 3
  • total commit >= 5
  • total issues >= 1
  • open issues <= 60
  • size > 2k
  • score > 5
  • last update is within a year

I.e., filtering will all above conditions. Is it possible?

xpt
  • 20,363
  • 37
  • 127
  • 216
  • This Q/A helped me find a [better Github search approach](https://medium.com/@suntong001/query-github-graphql-9a4547d33bad), FYI. – xpt Mar 31 '18 at 20:16

2 Answers2

9

When querying for repositories, you can apply a filter only for a certain number of the fields in your list:

  • number of stars
  • number of forks
  • size
  • last update

Although you cannot specify them in the query filter, you can include other fields in your query and verify the values in the client application:

  • total number of issues
  • number of open issues

While, in theory, you can also query for the number of commits, applying your specific parameter arguments, that query returns a server error, it most probably times out. For that reason, those lines are commented out.

Here's the GraphQL query:

query {
  search(
    type:REPOSITORY, 
    query: """
      stars:>10
      forks:>3
      size:>2000
      pushed:>=2018-08-08
    """,
    last: 100
  ) {
    repos: edges {
      repo: node {
        ... on Repository {
          url

          allIssues: issues {
            totalCount
          }
          openIssues: issues(states:OPEN) {
            totalCount
          }

          # commitsCount: object(expression: "master") {
          #   ... on Commit {
          #      history {
          #       totalCount
          #     }
          #   }
          # }
        }
      }
    }
  }
}

The specification for repository queries can be found here: https://help.github.com/en/articles/searching-for-repositories#search-by-repository-size

Igor Akkerman
  • 2,348
  • 1
  • 21
  • 24
1

This is not an answer but an update of what I've collected so far.

  • According to "Select * for Github GraphQL Search", not all above criteria might be available in the Repository edge. Namely, the "total commit", "open issues" and "score" might not be available.

  • The purpose of the question is obviously to find the valuable repositories and weed off the lower-quality ones. I've collected all the available fields that might be helpful for such assessment here.

A copy of it as of 2018-03-18:

query SearchMostTop10Star($queryString: String!, $number_of_repos:Int!) {
  search(query: $queryString, type: REPOSITORY, first: $number_of_repos) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          name
          url
          description
#         shortDescriptionHTML
          repositoryTopics(first: 12) {nodes {topic {name}}}
          primaryLanguage {name}
          languages(first: 3) { nodes {name} }
          releases {totalCount}
          forkCount
          pullRequests {totalCount}
          stargazers {totalCount}
          issues {totalCount}
          createdAt
          pushedAt
          updatedAt
        }
      }
    }
  }
}
variables {
  "queryString": "language:JavaScript stars:>10000", 
  "number_of_repos": 3 
}

Anyone can try it out as per here.

xpt
  • 20,363
  • 37
  • 127
  • 216
  • fwiw, there's a filter that you can apply to the issues field to fetch only open issues: `issues(states:[OPEN])` – Daniel Rearden Mar 19 '18 at 02:12
  • thanks @DanielRearden, I've [updated my gist](https://gist.github.com/suntong/97a919c21e6adc53447f5059a34d334a/revisions#diff-58f7ec41ac0f54fc487fc086d0651ffe) – xpt Mar 19 '18 at 02:56