Reputation: 23054
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
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
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