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

GraphQL API get list of files related to commit

I'm trying to get the list of files that were changed in a commit, I can see that the only connection that the commit node has with the files is the commitResourcePath.

 

Is there any way to get the list of files from that commitResourcePath?

 

This is my GraphQL query:

 

{
  repository(owner: "bialikover", name: "taco-or-not") {
    ref(qualifiedName: "master") {
      target {
        ... on Commit {
          id
          history(first: 5) {
            pageInfo {
              hasNextPage
            }
            edges {
              node {
                changedFiles
                messageHeadline
                oid
                message
                author {
                  name
                  email
                  date
                }
                commitResourcePath 
              }
            }
          }
        }
      }
    }
  }
}

and this is the output:

 

{
  "data": {
    "repository": {
      "ref": {
        "target": {
          "id": "MDY6Q29tbWl0MTg0OTkwMzEyOjUxODVlYzVlMTBjYWY3N2U0NmU3YjRkMGRlOWM1ZjI4NGI5ZTFjZjg=",
          "history": {
            "pageInfo": {
              "hasNextPage": false
            },
            "edges": [
              {
                "node": {
                  "changedFiles": 1,
                  "messageHeadline": "update readme with demo url",
                  "oid": "5185ec5e10caf77e46e7b4d0de9c5f284b9e1cf8",
                  "message": "update readme with demo url",
                  "author": {
                    "name": "Adán G. Galván González",
                    "email": "bialikoer@gmail.com",
                    "date": "2019-05-09T11:56:56.000-07:00"
                  },
                  "commitResourcePath": "/bialikover/taco-or-not/commit/5185ec5e10caf77e46e7b4d0de9c5f284b9e1cf8"
                }
              },
              {
                "node": {
                  "changedFiles": 1,
                  "messageHeadline": "update dockerfile",
                  "oid": "5b1e1bbd5d39578816be7a05f93e32d8cb09e756",
                  "message": "update dockerfile",
                  "author": {
                    "name": "Adán G. Galván González",
                    "email": "bialikoer@gmail.com",
                    "date": "2019-05-08T18:12:24.000-07:00"
                  },
                  "commitResourcePath": "/bialikover/taco-or-not/commit/5b1e1bbd5d39578816be7a05f93e32d8cb09e756"
                }
              },
              {
                "node": {
                  "changedFiles": 18,
                  "messageHeadline": "init project with taco",
                  "oid": "451bab389b290a0e166cc6b01e887c075f2c8084",
                  "message": "init project with taco",
                  "author": {
                    "name": "Adan G Galvan Gonzalez",
                    "email": "bialikoer@gmail.com",
                    "date": "2019-05-05T01:25:59.000-07:00"
                  },
                  "commitResourcePath": "/bialikover/taco-or-not/commit/451bab389b290a0e166cc6b01e887c075f2c8084"
                }
              }
            ]
          }
        }
      }
    }
  }
}

Ideally I'd like to get the filenames that were changed, it doesn't matter if I do a second

request and agregate these to the current output object.

 

One solution is using api v3 to get the list of files changed with the commit id but want to double check if there is an easier way with GraphQL API

 

Any ideas? 

 

 

 

2 Replies
Community Manager
Message 2 of 3

Re: GraphQL API get list of files related to commit

Unfortunately, the information you're looking for isn't currently available via the GraphQL API. You'd have to grab that information via the REST API at this time.

Copilot Lvl 2
Message 3 of 3

Re: GraphQL API get list of files related to commit

My response is a bit too late, I had the same issue and I have seen this post when I was looking for a solution. So, I created a solution to this problem by using both REST API and GraphQL API. I wrote a blog post about it (https://mohamedsahbi.com/2019/12/24/fix-a-gap-in-github-api-v4/). I hope it will help anyone that is having the same issue.