17

I am able to get the list of commits (with fields like commit messages, oid, commit url etc) along with the number of changedFiles, made in a repository on the master branch.
However I am not able to figure out how to get any information about the changes themselves and the files that were changed.

In v3 of the REST API, the information about the changes were contained in files->patch, and files -> raw_url or blob_url gave info about the original file itself at that stage.

Q) In v4 of GitHub's API using GraphQL how do I get the corresponding information?

Query I am stuck with right now (showing only 1 commit for brevity)-

query {
  rateLimit{
    cost
    remaining
  }
  repository(owner: "elastic", name: "elasticsearch") {
    name
    defaultBranchRef {
      name
      target {
        ... on Commit {
          history(first:1){
            nodes{
              message
              changedFiles
              id
              oid
              treeUrl
              url
              tree{
                oid
              }
            }
            pageInfo{
              hasNextPage
              startCursor
              endCursor
            }
          }
        }
      }
    }
  }
}

Output:

{
  "data": {
    "rateLimit": {
      "cost": 1,
      "remaining": 4999
    },
    "repository": {
      "name": "elasticsearch",
      "defaultBranchRef": {
        "name": "master",
        "target": {
          "history": {
            "nodes": [
              {
                "message": "Small corrections to HLRC doc for _termvectors (#35221)\n\nRelates to #33447",
                "changedFiles": 2,
                "id": "MDY6Q29tbWl0NTA3Nzc1OmEyYzIyYWQ3YWViMGY4ZDUxNDg2NzdkZDcyMjJhZDQzYWZlZTlhMTc=",
                "oid": "a2c22ad7aeb0f8d5148677dd7222ad43afee9a17",
                "treeUrl": "https://github.com/elastic/elasticsearch/tree/a2c22ad7aeb0f8d5148677dd7222ad43afee9a17",
                "url": "https://github.com/elastic/elasticsearch/commit/a2c22ad7aeb0f8d5148677dd7222ad43afee9a17",
                "tree": {
                  "oid": "4f5f11e0e55aeafc4677800959232726a2cd787c"
                }
              }
            ],
            "pageInfo": {
              "hasNextPage": true,
              "startCursor": "a2c22ad7aeb0f8d5148677dd7222ad43afee9a17 0",
              "endCursor": "a2c22ad7aeb0f8d5148677dd7222ad43afee9a17 0"
            }
          }
        }
      }
    }
  }
}
jthill
  • 55,082
  • 5
  • 77
  • 137
jar
  • 2,646
  • 1
  • 22
  • 47
  • 2
    FYI, OP posted this same question on the GitHub community forum in Nov 2018 and the rep said it was not possible as of that time: https://github.community/t5/GitHub-API-Development-and/Get-a-repository-s-commits-along-with-changed-patches-and-the/td-p/14436 – cody Feb 19 '19 at 00:12
  • Plus, git itself is explicitly excluded, so I took git out of the tags. – jthill Feb 21 '19 at 18:25
  • Maybe I'm missing something obvious but if the GIthub API cannot give you the diffs, why not just build your own server that maintains its own copy of the repo? I just realised how old this question is. I hope there's no law against necromancy in these lands. – Peaceful James Jun 14 '20 at 14:16

0 Answers0