Get a list of all repositories where I'm a collaborator/invited

Maybe someone can point me to where I’m going wrong here …

API v3 documentation https://developer.github.com/v3/repos/

I have a user with access to three (3) repositories:

R1 - NEW empty repo (testRepository)
R2 - Fork of a public repo (github-api)
R3 - private repository of another user which I have been invited to (and accepted).

However, the API only return R1 and R2?

curl -X GET https://api.github.com/users/<myuser>/repos\?type=all

How do I get a list of all repositories where I’m not the owner but just a collaborator/invited?

Hi @aram535,

Thank you for being here! I wonder if you are running into a pagination issue, could you try:

curl -X GET https://api.github.com/users/<myuser>/repos?per_page=100

Results are returned in pages of 30 results by default, so you can follow the Link header to get the next page of results, and you can also add the per_page parameter to get more results.

Hi Andrea, 

It’s a rather small request at this point, only 3 should return.  “type=all” should include any repositories that the user has been invited into, however only the 2 “owned” projects are returned.

Here is the odd part:

$ curl -s "https://api.github.com/user/repos?type=all" | jq '.'
3

but if you query the user itself:

Only 2 repos are returned.

I have verified it manually… and here it is programmatically:

$ curl -s "https://api.github.com/users/${USER}/repos?type=all&per_page=100" -H "Authorization: token ${AUTH}" | jq '. | length'
2

Just as a test using V4 of the API I do get 3 repositories.

{
  viewer {
    name
    repositories(first: 5) {
      edges {
        node {
          id
          name
        }
      }
    }
  }
}

I get 3 repositories listed. 

1 Like

Hi @aram535,

Are all the memberships public? If you don’t authenticate, that endpoint returns only organizations for which you publicized your membership, as explained in the documentation:

https://developer.github.com/v3/orgs/#list-user-organizations

Thought that doesn’t really explain how v4 is returning them all, let me look into this some more. I’ll reach out to that team and post any updates here. Thanks again for bringing this up to our attention.

Best,

Andrea

Hi Andrea, 

No, they’re not all public.  Yes, I am authenticating using a token (same token).  I don’t believe without authentication the 2nd endpoint would return anything at all correct?

Hi @aram535,

You are correct, the authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, and repositories that they can access through an organization membership. 

It would seem the simplest way in v3 is to use /user/repos: https://api.github.com/user/repos.

I hope this helps!

Best,

Andrea

Is a Github Admin (within Github Enterprise), able to pull up all the memberships (public/private) for specific members?

I’ve been banging my head against the V3 apis and can’t see to get all the repos returned, when I know a specific user (not me) has write access to it.

1 Like

Hi @jonathanhle, welcome to the community! Thanks for your question. Users can publicize or hide organization membership. Hidden organization memberships are not visible in the GitHub Enterprise web interface unless your user, too, is a member of the organization, and they never appear in responses from the Organizations API’s List user organizations endpoint.

In order to see someone’s hidden organization membership as a Site Administrator via the API, you’ll need to make a request to the Members API’s List your organization memberships endpoint and authenticate that request with an impersonation OAuth token. This will show all organization memberships, both public and hidden. When you’re done, we advise deleting the impersonation OAuth token.