get, via GitHub API, all public repos a GitHub user has made commit(s) to

community-help

#1

Hi,
Even though on the forum page there is the following:

… if you’re looking for support for the REST API v3, please contact support.

I was asked to post my question here by the Community Manager, nadiajoyce

For a GitHub user foo, is it possible, via the GitHub v[3|4] API, to get all the public repos user foo has made commit(s) to?

Thanks.


#2

Hey @hseuming

We’ll be shipping something to do this very soon to our GraphQL API. I’ll update this thread when it’s shipped :slight_smile:


#3

@hseuming,

We’ve just finished shipping the new User.repositoriesContributedTo endpoint. You can see why we’ve made this endpoint here: Deprecation and Replacement of User.contributedRepositories

To get the data you want, you could write a query like this:

query{
  user(login: "foo"){
    repositoriesContributedTo(first: 100, contributionTypes: [COMMIT]){
      ...
    }
  }
}

Let me know if this works :slight_smile:


#4

Hi @d12,
Thank you for your input. I was sidetracked by a few other tasks and had no previous exposure to GraphQL thus my late reply. After reading up on GraphQL and the Explorer, I was able to cook up some queries to get the results I was looking for.

One quick question: since “first” is limited to 100, how can one fetch all the results if there are more than 100 of them? The “offset” argument does not seem to get me anywhere as the error message below indicates.

In general, what is the proper way for pagination to fetch all the chunks?

Thanks

{
user(login: “foo”) {
repositoriesContributedTo(first: 100 offset: 100, contributionTypes: [COMMIT]) {
edges {
node {
nameWithOwner
}
}
}
}
}

========================================================

{
“data”: null,
“errors”: [
{
“message”: “Field ‘repositoriesContributedTo’ doesn’t accept argument ‘offset’”,
“locations”: [
{
“line”: 3,
“column”: 42
}
]
}
]
}


#5

Hi @hseuming,

Our GraphQL API uses cursor based pagination, as opposed to offset based pagination like you’re trying.

You can learn more about cursor based pagination here: http://graphql.org/learn/pagination/

Let me know if you have any questions!


#6

Hi @d12,
Thanks again for your input. I’ll switch to cursor-based pagination to see how it goes.

One more related question: earlier you mentioned that I can use

   ...
   repositoriesContributedTo(first: 100, contributionTypes: [COMMIT]){ ..
   ...

to get all the public repos that a user has made commit(s) to and that works pretty well.

If instead I have

repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE]){ …

does [COMMIT, ISSUE] indicate boolean AND or OR? I mean, does [COMMIT, ISSUE] denote all the public repos that a given user

  1. has made commit(s) to AND raised issue(s) in or
  2. has made commit(s) to OR raised issue(s) in

Could you please point me to pertinent docs or the code/implementation for the intended semantics?

Thanks.


#7

The endpoint documentation is here: https://developer.github.com/v4/object/user/

If non-null, include only the specified types of contributions.

So by specifying [COMMIT, ISSUE], you’re getting COMMIT contributions and ISSUE contributions.

Hope that helps!


#8

Hi @d12,
Thanks again for the prompt response.

One more quick question: it appears that we can NOT get all contributors
(not collaborators) of a public repo with the v4 GraphQL API, right? i
know that can be done with the v3 REST-ful API (with pagination, if
needed).

Thanks


#9

No worries @hseuming!

We’ve actually been discussions contributors lately, we’re working on designing the schema around the feature. I don’t know when it will be released, but it’s in the works! I’ll update you here when this ships.


#10

Hi @d12,
Thank you for all your timely assistance. Please kindly keep me posted.