I'm trying to use the new Github GraphQL api (v4) and I don't seem to be able to figure out how to get the last x commits for master. I've used repository and ref but they still don't give me what I need.
The query below almost gives me what I need:
query{
repository(owner: "typelevel", name: "cats") {
refs(refPrefix:"refs/heads/", last: 5) {
edges{
node {
associatedPullRequests(states: MERGED, last: 5) {
edges{
node {
title
baseRef {
name
prefix
}
baseRefName
commits(last: 10) {
edges {
node {
commit {
abbreviatedOid
message
}
}
}
}
}
}
}
}
}
}
}
}
but:
I also tried using defaultBranchRef but that didn't work either:
query{
repository(owner: "typelevel", name: "cats") {
defaultBranchRef {
name
prefix
associatedPullRequests(states: [MERGED], last: 5) {
edges {
node {
title
}
}
}
}
}
}
I've been testing the queries using the explorer app on the Github api page.
Any ideas?
I was able to get this working with:
query {
repository(owner: "typelevel", name: "cats") {
ref(qualifiedName: "master") {
target {
... on Commit {
history(first: 10) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
oid
messageHeadline
}
}
}
}
}
}
}
}
by modifying this query linked to on the Github Platform Community.
Would using history
be better in this case?
See this thread
A "
ref
" (short for reference) is anything that points to a git commit. This could be a local branch, a tag, a remote branch, etc. Somaster
, for example, would be considered a ref.In that vein, you can use the
ref
field on theRepository
type to get a reference that targets a commit.
From that commit, you can get all of the commit's parents. If you targetmaster
, you can get the mainhistory
of the git repository.
query {
node(id: "MDEwOlJlcG9zaXRvcnk4NDM5MTQ3") {
... on Repository {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(first: 30) {
totalCount
pageInfo {
hasNextPage
}
edges {
node {
oid
message
author {
name
email
date
}
}
}
}
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With