Is there a more efficient way of getting the count of additions/deletions related to a commit than looping through every single commit and calling the:
GET /repos/:owner/:repo/commits/:sha
(https://developer.github.com/v3/repos/commits/)
Just to get the:
"stats": {
"additions": 104,
"deletions": 4,
"total": 108
},
Data?
Unfortunately the commits endpoint:
GET /repos/:owner/:repo/commits
Contains a lot of data about each commit but not this detail which means a huge number of additional API calls to get it.
Whenever you need multiple GitHub API query, check if GraphQL (introduced by GitHub last Sept. 2016) could allow you to get all those commits in one query.
You can see examples here and apply to GitHub GraphQL early access, but that sees to be the only way to get:
It is now possible to get commit stats (additions
, deletions
& changedFiles
count) using the GraphQL API :
To get commit stats for the 100 first commit on the default branch :
{
repository(owner: "google", name: "gson") {
defaultBranchRef {
name
target {
... on Commit {
id
history(first: 100) {
nodes {
oid
message
additions
deletions
changedFiles
}
}
}
}
}
}
}
Try it in the explorer
To get commit stats for the first 10 branches, for the 100 first commits of each one of these branches:
{
repository(owner: "google", name: "gson") {
refs(first: 10, refPrefix: "refs/heads/") {
edges {
node {
name
target {
... on Commit {
id
history(first: 100) {
nodes {
oid
message
additions
deletions
changedFiles
}
}
}
}
}
}
}
}
}
Try it in the explorer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With