Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 10

GraphQL API: How to fetch all repositories that the current user has access to

I'm trying to find a GraphQL equivalent of the `/user/repos` resource: https://developer.github.com/v3/repos/#list-your-repositories

> List repositories that the authenticated user has explicit permission (:read, :write, or :admin) to access.

 

I've tried following query but that only returns repositories under my account, and not the other repositories I have access to (organizational repos - both public and private):

 

{
  viewer {
    repositories(first: 100, after: properCursorHereOrOmitIfFirstPage, orderBy: {field:NAME, direction:ASC}) {
      pageInfo {hasNextPage, endCursor}
      nodes {
        name
        url
        isPrivate
        owner {
          login
        }
        defaultBranchRef {
          name        
        }
      }
    }
  }
}

 

EDIT: 

I've also tried to use affiliations but without success  - still returns only repositories directly under my "jumarko" account:

{ 
  viewer {
    repositories(first: 100, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER]) {
      totalCount
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes{
        name
          owner {
            login
          }          
        }    
      }
   }
 }
9 Replies
Copilot Lvl 2
Message 2 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

try repositoriesContributedTo instead of repositories

Copilot Lvl 3
Message 3 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

Thanks for the suggestion but that doesn't sound right.

I want to get a list of all repositories I have access to, not only the ones I've contributed too.

 

As mentioned before, I want an equivalent of user/repos endpoint of v3 API, which for more returns 2300+ repositories while the "equivalent" GraphQL API query (see my previous post) returns only 207 repositories.

repositoriesContributedTo I contributed to returns only 85 repos (with includeUserRepositories set to true).

 

Community Manager
Message 4 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

Hey @jumarko,

 

Thanks for being here, have you tried? 

{
  viewer {
    repositories(first: 100) {
      totalCount
      nodes {
        nameWithOwner
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}
          
            
        
    


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 3
Message 5 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

@AndreaGriffiths11 thanks for the suggestion but that does the same thing as my first query.

 

Copilot Lvl 2
Message 6 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

Pilot Lvl 1
Message 7 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

@jumarko Did you find a way to get all the repos. I really don't wanna use v3 for this.

Copilot Lvl 3
Message 8 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

@krasimir No, I use V3 rest api to load list of repos.

 

Pilot Lvl 1
Message 9 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

Ok, fair enough. I'll do the same for the time being.

Copilot Lvl 3
Message 10 of 10

Re: GraphQL API: How to fetch all repositories that the current user has access to

I found the solution!

 

Add the following parameters to your `repositories` query: `affiliations:[OWNER, ORGANIZATION_MEMBER, COLLABORATOR], ownerAffiliations:[OWNER, ORGANIZATION_MEMBER, COLLABORATOR]`

 

Not sure why this is necessary to retrieve private organisation repos and not public organisation repos, but nevertheless it works.