I want to get a year's commit count for the user. I checked the github-api v3 reference, but only the repository commit count could be known.
How can I know the number of commit to all repositories in a year for a user?
I want to get a year's commit count for the user. I checked the github-api v3 reference, but only the repository commit count could be known.
How can I know the number of commit to all repositories in a year for a user?
You can get total commit count per branch with CommitHistoryConnection.totalCount:
{
repository(owner: "freeCodeCamp", name: "freeCodeCamp") {
defaultBranchRef {
target {
... on Commit {
history(first: 0) {
totalCount
}
}
}
}
}
}
If you want to filter by time / author, you can pass in arguments to history like after, until, and author like this:
{
repository(owner: "freeCodeCamp", name: "freeCodeCamp") {
defaultBranchRef {
target {
... on Commit {
history(first: 0,
since: "2022-01-01T00:00:00Z",
until: "2022-12-31T23:59:59Z",
author: {emails: "[email protected]"}) {
totalCount
}
}
}
}
}
}
And if you want to call via powershell and gh cli, you can get the totalCount from the output like this
$query = @"
{
repository(owner: "freeCodeCamp", name: "freeCodeCamp") {
name
defaultBranchRef {
name
target {
... on Commit {
history(first: 0) {
totalCount
}
}
}
}
}
}
"@
$response = gh api graphql -f query="$query" | ConvertFrom-Json
$totalCount = $response.data.repository.defaultBranchRef.target.history.totalCount
$totalCount
Related Questions