Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

Commit total additions/deletions empty from GraphQL

Hi,

 

I am working on a school project where I am creating a dashboard for Github projects to show some statistics. I noticed that when querying for commit totals (additions/deletions) it comes up empy. The only difference i notice is the age of the repository.

 

For example :

 

repository(owner: "nivvyart", name: "gitghost") {
    object(expression: "master") { #what is this object
      repository {
        commitComments(last: 10) {
          totalCount
          edges {
            node {
              id
              commit {
                id
                additions
                deletions
              }
            }
          }
        }
      }
    }
  }

 

Result =>

  "data": {
    "repository": {
      "object": {
        "repository": {
          "commitComments": {
            "totalCount": 0,
            "edges": []
          }
        }
      }
    }
  }

This will not show any commit details ( dont think i need object there but it doesnt hurt) althought the repository does have commits againts it link

 

vs this user:

 

  repository(owner: "nickvanw", name: "ircx") {
    object(expression: "master") { #what is this object
      repository {
        commitComments(last: 10) {
          totalCount
          edges {
            node {
              id
              commit {
                id
                additions
                deletions
              }
            }
          }
        }
      }
    }
  }

 

Result =>

 

"data": {
    "repository": {
      "object": {
        "repository": {
          "commitComments": {
            "totalCount": 2,
            "edges": [
              {
                "node": {
                  "id": "MDEzOkNvbW1pdENvbW1lbnQxMjI4NTM3Ng==",
                  "commit": {
                    "id": "MDY6Q29tbWl0MjMwMjQ5NTc6ZGMxYzY2ZjBjNzhhY2U0MjUwMzBiYTk4NzBiZGRmYTQ0ZWI1ZWE4NA==",
                    "additions": 104,
                    "deletions": 107
                  }
                }
              },
              {
                "node": {
                  "id": "MDEzOkNvbW1pdENvbW1lbnQxMjcyNjA5Ng==",
                  "commit": {
                    "id": "MDY6Q29tbWl0MjMwMjQ5NTc6ZTdhOWQxOTQ5MmQ5MTk0NzVhMDk5YTIxYWE2ODc3MDE3NDE2Zjg1NA==",
                    "additions": 97,
                    "deletions": 102
                  }
                }
              }
            ]
          }
        }
      }
    }
  }

Which shows commits and details i am after.

 

 

Interstingly if you are doing a similar call againts pull requests you do get additions and deletions back:

 

user(login: "Yiannimoustakas") {
    repository(name: "sei31-homework") {
      pullRequests(last: 30) {
        edges {
          node {
            id
            author {
              login
            }
            title
            createdAt
            closed
            url
            additions
            deletions
          }
        }
      }
    }
  }

Result =>

"user": {
      "repository": {
        "pullRequests": {
          "edges": [
            {
              "node": {
                "id": "MDExOlB1bGxSZXF1ZXN0MjcwMzM2MjYw",
                "author": {
                  "login": "AnthonyGDoueihi"
                },
                "title": "Bare bones Association Database",
                "createdAt": "2019-04-14T23:31:28Z",
                "closed": true,
                "url": "https://github.com/Yiannimoustakas/sei31-homework/pull/112",
                "additions": 436,
                "deletions": 0
              }
            },
            {
              "node": {
                "id": "MDExOlB1bGxSZXF1ZXN0MjcwMzM3NDA5",
                "author": {
                  "login": "FireMugen"
                },
                "title": "Homework",
                "createdAt": "2019-04-14T23:50:43Z",
                "closed": true,
                "url": "https://github.com/Yiannimoustakas/sei31-homework/pull/113",
                "additions": 615,
                "deletions": 0
              }
            },

 

 

Any idea what is going on here and why this query returns empty??? For now i have done an axios based call to the github api v3 which does give the information i need but ideally i would like everything via GraphQL.

 

Cheers!

2 Replies
Community Manager
Message 2 of 3

Re: Commit total additions/deletions empty from GraphQL

In your query you go through the following connections:

 

 

The thing to keep in mind is that a CommitComment is a comment by a GitHub user on an individual GitHub Commit object, not the commit message that git ties to every commit. The git commit message is represented by the `message` field on the Commit object.

 

Not every git commit has a GitHub CommitComment, so it isn't surprising that a repository may have zero commit comments and therefore return an empty result.

 

More likely what you want is this query:

 

{
  repository(owner: "nivvyart", name: "gitghost") {
    defaultBranchRef {
      target {
        ... on Commit {
          history(first: 10) {
            nodes {
              oid
              committedDate
              additions
              deletions
            }
          }
        }        
      }
    }
  }
}

I'm using:

 

  • `defaultBranchRef` because not all repository's default branch is named `master`
  • From which I get `target` and cast it to a Commit object to get the `history` connection
  • And then retrieve the first 10 Commit objects (because the history is stored in reverse chronological order and I assume you want the newest commits)
  • To get their `oid` (the git hash ID for the commit), `additions`, and `deletions`

 

I hope that helps!

Highlighted
Copilot Lvl 2
Message 3 of 3

Re: Commit total additions/deletions empty from GraphQL

Thanks! That is a really helpful response :)