Commit stats for commits in repository


#1

Hello! Is where a way to retrieve stats like from v3 api?
I want to reveive info about all commits in repository since specific date.
I come to:

query {
  viewer {
    
  repository(name: "CRM_system") {
    ref(qualifiedName: "master") {
      target {
        ... on Commit {
          id
          history(since: my_date_time) {
            edges {
              node {
                messageHeadline
                oid
                message
                author {
                  name
                  email
                  date
                }
              }
            }
          }
        }
      }
    }
  }
}
  }

But i cant figure out how to receive stats of commits?
Like
{
stats
total 27
additions 27
deletions 0}

Also i cant figure out in which format should i put date in since: - i try “2016-01-01” but its not working.

Also it will be great if someone advise me how to receive commits from all branches not only from master.


#2

Hi @Smosker,

Is where a way to retrieve stats like from v3 api?

Not yet, but I think what you’re looking for has been requested in the past in Get contribution Statistics.

Also it will be great if someone advise me how to receive commits from all branches not only from master.

Here’s an example of a query that gets data about commits in a branch outside of master (the branch name is batch-import):

query {
  repository(owner:"bswinnerton",name:"nyc-restaurant-grades") {
  	ref(qualifiedName:"refs/heads/batch-import") {
	  name
      target {
        ... on Commit {
          history(first:30) {
            edges {
              node {
                oid
                message
              }
            }
          }
        }
      }
    }
  }
}

#3

Thanks for answer, is it possible to get commits stats also in such a query?


#4

@Smosker This has recently been added to the schema! You can now access change stats on both pull requests and commits:

query{
  repository(owner:"education",name:"classroom"){
    defaultBranchRef{
      target{
        ... on Commit{
          changedFiles
          additions
          deletions
        }
      }
    }
    
    pullRequests(last: 1){
      nodes{
        additions
        deletions
        changedFiles
      }
    }
  }
}

Does this do what you need?


#5

Yes, this is huge impovement, thanks.

Is it possible to see all commits in branch with such a query from specific datetime?
Or maybe even commits in all branches?


#6

No worries, @Smosker

This query will fetch all commits on the default branch since January 16’th, 2017:

{
  repository(owner:"your-name", name:"your-repo"){
    defaultBranchRef{
      target{
        ... on Commit {
          history(first: 100, since: "2017-01-16T11:22:09Z"){
            totalCount
            nodes{
              commitUrl
            }
          }
        }
      }
    }
  }
}

Showing commits in all branches isn’t available right now as far as I know. For now, perhaps you can use the git CLI?


#7

Thanks, tell me please, is where are a way to retrive also changedfiles with their additions/deletions?
like

"files": [
        {
          "filename": "file1.txt",
          "additions": 10,
          "deletions": 2,
          "changes": 12,
          "status": "modified",
          "raw_url": "https://github.com/octocat/Hello-World/raw/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
          "blob_url": "https://github.com/octocat/Hello-World/blob/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
          "patch": "@@ -29,7 +29,7 @@\n....."
        }
]

#8

Not at this time, but more data like this is being made available soon.

Check the changelog for info on when it’s released.


#9

Is it possible to get the commits count per day on default branch of a repository using graphql?