Github GraphQL - Getting a repository's list of commits
Just realized that what I was looking for is a field which exists in the Repository
object called defaultBranchRef
. Using this field I was able to retrieve the data I was looking for.
My query now looks like this:
... on Repository{
defaultBranchRef{
target{
... on Commit{
history(first:10){
edges{
node{
... on Commit{
committedDate
}
}
}
}
}
}
}
}
If you are also interested in getting the latest commits for all branches (not just the default branch), you can request reference with prefix refs/heads/
:
{
repository(owner: "bertrandmartel", name: "callflow-workshop") {
refs(refPrefix: "refs/heads/", orderBy: {direction: DESC, field: TAG_COMMIT_DATE}, first: 100) {
edges {
node {
... on Ref {
name
target {
... on Commit {
history(first: 2) {
edges {
node {
... on Commit {
committedDate
}
}
}
}
}
}
}
}
}
}
}
}
In your case using refs/
also gave you tag ref.
Try it in the explorer