Retrieving recent commits from a specific committer within a specific repo


#1

I’m looking for a GraphQL query which gives me all commits from a specific committer in a specific repo ordered by commit date (most recent first). I tried the following, but run into several problems:

{
  repository(owner: "maraoz", name: "7cerebros") {
    defaultBranchRef {
      target {
        ... on Commit {
          history(first: 100, since: "2010-01-16T11:22:09Z") {
            totalCount
            edges {
              node {
                committedDate
                commitUrl
                id
                committer {
                  user {
                    login
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
  "message": "Field 'history' doesn't accept argument 'orderBy'",

Then I tried to use “last” but ran into the following error:

  "message": "Backwards pagination requires a `before` cursor",

before requires a global ID which I don’t have…

Also, can’t seem to filter by committer:

  "message": "Field 'history' doesn't accept argument 'CommitAuthor'",

But according to the doc it is supported: https://developer.github.com/v4/reference/object/commit/


#2

The history connection takes an argument called author, which filters commits by user ID or email address.

First, let’s get the ID:

{
  user(login:"maraoz") {
    id
  }
}

Then, we’ll use that ID (MDQ6VXNlcjI4NzE4OQ==) to filter the commits:

{
  repository(owner: "maraoz", name: "7cerebros") {
    defaultBranchRef {
      target {
        ... on Commit {
          history(first: 100, author: {id: "MDQ6VXNlcjI4NzE4OQ=="}, since: "2010-01-16T11:22:09Z") {
            totalCount
            edges {
              node {
                committedDate
                commitUrl
                id
                committer {
                  user {
                    login
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Does that help?


#3

Yes, that definitely helps, thanks! Quick questions, is the == part of the ID? Looks a little funny.


#4

Additionally, I assume this does not work with login instead of ID or email? I tested it, and it seems not to work.


#5

Yes, that’s part of the Base64 spec, which is how these IDs are designed: https://en.wikipedia.org/wiki/Base64#Output_padding

Right. User accounts can have usernames renamed, but the ID is guaranteed to remain stable.


#6

Awesome, thanks! Lastly, do you know a way to sort by most recent commits? orderBy does not seem to be supported. When I use before I need a cursor…


#7

Struggling with pagination, I get the following error:

Field 'history' doesn't accept argument 'offset'

I understand I can use pageInfo and endCursor, but that is a cumbersome process.

When executing the following:

{
  repository(owner: "maraoz", name: "7cerebros") {
    defaultBranchRef {
      target {
        ... on Commit {
          history(first: 100, offset:100, author: {id: "MDQ6VXNlcjI4NzE4OQ=="}, since: "2010-01-16T11:22:09Z") {
            totalCount
            edges {
              node {
                committedDate
                commitUrl
                id
                committer {
                  user {
                    login
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}