Reputation: 643
I'm trying to query GitHub's GraphQL API (v4). What GraphQL query for this API can be used to get all of the commits I've contributed to a particular public repo?
Upvotes: 0
Views: 853
Reputation: 643
I figured out the solution. (The solution shown below is for getting relevant commits from master
, but can easily be adapted for other qualifiedName
values.)
First, perform an initial query to obtain user ID:
query {
viewer {
id
}
}
Then the following query can be used to get all contributed commits to a particular repository:
query($repository_owner:String!, $repository_name:String!, $user_id:ID!) {
repository(owner: $repository_owner, name: $repository_name) {
ref(qualifiedName: "master") {
target {
... on Commit {
history(author: {id: $user_id}) {
totalCount
nodes {
id
authoredDate
message
}
}
}
}
}
}
}
The query variables take the following form:
{
"repository_owner": "REPOSITORY_OWNER_STRING",
"repository_name": "REPOSITORY_NAME_STRING",
"user_id": "USER_ID_FROM_STEP_1"
}
Upvotes: 2