xpt
xpt

Reputation: 23054

Github GraphQL Repository Query, commits totalCount

How to search for Github Repositories using GraphQL, and get its total commits count as well in return?

It looks strange to me that all fields available describing Repositories contains total count of commit comments but not total count of commits.

Upvotes: 7

Views: 2955

Answers (2)

tiger
tiger

Reputation: 465

bswinnerton's answer works well, but not for repositories without a master branch. In this case you can use defaultBranchRef

Here's an example of how to get the total number of commits for the default branch in the rails/rails repository

query {
  repository(owner:"rails", name:"rails") {
    defaultBranchRef {
      target {
        ... on Commit {
          history {
            totalCount
          }
        }
      }
    }
  }
}

Upvotes: 5

bswinnerton
bswinnerton

Reputation: 4721

Here's an example of how to get the total number of commits for the master branch in the rails/rails repository:

query {
  repository(owner:"rails", name:"rails") {
    object(expression:"master") {
      ... on Commit {
        history {
          totalCount
        }
      }
    }
  }
}

Upvotes: 13

Related Questions