0

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?

1

2 Answers 2

0

Could you please use the call GET /repos/:owner/:repo/commits with parameter since and until which are used for the start date and end date in YYYY-MM-DDTHH:MM:SSZ format. Also, we can pass the author parameter for getting the commits done by that particular author.

Sign up to request clarification or add additional context in comments.

Comments

0

Update with GraphQL API v4

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

Test it out on the Github GraphQL Explorer

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.