How to get the total number of transactions using the GitHub API

I am trying to collect some statistics about our project repositories on GitHub. I can get the total number of commits for each contributor, but this is for the default branch.

curl https://api.github.com/repos/cms-sw/cmssw/stats/contributors

The problem is how can I get the same information for branches other than the default, where I can specify the name of the branch. Is such an operation possible using the GitHub API?

thanks.

+5
source share
1 answer

You can use the GitHub GraphQL API to get this data, although it will not be aggregated for you.

Try the following query in GraphQL Explorer :

 query($owner:String!, $name:String!) { repository(owner:$owner,name:$name) { refs(first:30, refPrefix:"refs/heads/") { edges { cursor node { name target { ... on Commit { history(first:30) { edges { cursor node { author { email } } } } } } } } } } } 

With these variables:

 { "owner": "rails", "name": "rails" } 

This will list each author email for each of the commits of each of the branches in this repository. You would need to break the pages into pieces (adding something like cursor: "b7aa251234357f7ddddccabcbce332af39dd95f6" after the first:30 arguments). You will also need to combine the counts from your end.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1259728/


All Articles