query git notes with Github GraphQL

git notes is an interesting feature, you can use it like

git notes add -m "hello test git notes"
git push origin 'refs/notes/*'

Github supported them back in 2010 then gave up LMAO.

If you need to retrive them with Github API, try GraphQL like this

  {
    repository(owner: "est", name: "snippets") {
      refs(refPrefix:"refs/notes/",first:1) {
        nodes{
          ... on Ref{
            target {
              oid
              ... on Commit{
                changedFilesIfAvailable
                message
                tree{
                  oid
                  entries{
                    oid
                    path
                    size
                    lineCount
                    mode
                    object{
                      ... on Blob{
                        byteSize
                        text
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

It will return something like:

  {
    "data": {
      "repository": {
        "refs": {
          "nodes": [
            {
              "target": {
                "oid": "bfdfda121f3d8a2d6aa399e3e8f0d58b3db0a543",
                "changedFilesIfAvailable": 1,
                "message": "Notes added by 'git notes add'",
                "tree": {
                  "oid": "2ab3e6a8b0dff6596fa60ecfb3c61bf91e5b4e1f",
                  "entries": [
                    {
                      "oid": "404d353a254ffbc97b2e16d17b8c100461aef586",
                      "path": "4fb1272f1e235580f87e3ec071984658de050dc9",
                      "size": 21,
                      "lineCount": 1,
                      "mode": 33188,
                      "object": {
                        "byteSize": 21,
                        "text": "hello test git notes\n"
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  }

Here "path": "4fb1272f1e235580f87e3ec071984658de050dc9" is the commit SHA.

If you add more filter parameters in refs() you can fetch all the notes.

Comments