I’m trying to use the GitHub GraphQL API to get all the additions made by a user (additions can be found from their commits). I’ve been able to get the additions from pull requests, but I haven’t found a way to do the same for commits. How can I get all the commits from a user?
This is my query (I am new to GraphQL):
query AllAdditions($username: String!, $from: DateTime, $to: DateTime) {
user(login: $username) {
name
contributionsCollection(from: $from, to: $to) {
commitContributionsByRepository(maxRepositories: 100) {
repository {
nameWithOwner
}
contributions(first: 30) {
totalCount
# I'm trying to get additions like this, but there is no 'commit' field
# nodes {
# commit {
# additions
# }
# }
}
}
pullRequestContributionsByRepository(maxRepositories: 100) {
repository {
nameWithOwner
}
contributions(first: 30) {
nodes {
pullRequest {
additions
}
}
}
}
}
}
}
1 Answer
As mentioned by lee-dhom in GraphQL – Get all commits by all users:
{ search(query: "org:test", type: REPOSITORY, last: 100) { nodes { ... on Repository { name defaultBranchRef { name target { ... on Commit { history(first: 100, since: "2013-07-11T00:00:00") { totalCount nodes { ... on Commit { committedDate additions author { name email } } } } } } } } } } }
As for getting all orgs, there isn’t currently a way to do that via
the GraphQL API because the search connection requires something in
the search query. There’s also no top-level connection that allows you
to list all users, orgs, or repositories.I hope that helps!