Efficient statistics retrieval for all GitHub Commits

Is there a more efficient way to get the number of additions / deletions related to commit than a loop through each individual message and call:

GET /repos/:owner/:repo/commits/:sha

( https://developer.github.com/v3/repos/commits/ )

Just to get:

"stats": {
   "additions": 104,
   "deletions": 4,
   "total": 108
},

Data

Unfortunately, the commit endpoint is:

GET /repos/:owner/:repo/commits

It contains a lot of data about each commit, but not this detail, which means a huge number of additional API calls to receive it.

+4
source share
2 answers

, API GitHub, , GraphQL ( GitHub 2016 .) .

GitHub GraphQL , :

  • ( )
+3

commit stats (additions, deletions changedFiles count) GraphQL API:

100 :

{
  repository(owner: "google", name: "gson") {
    defaultBranchRef {
      name
      target {
        ... on Commit {
          id
          history(first: 100) {
            nodes {
              oid
              message
              additions
              deletions
              changedFiles
            }
          }
        }
      }
    }
  }
}

10 , 100 :

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

0

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


All Articles