Github API questions for management of access

Hi we are currently in the middle of a shift in github management for our organization and so we are trying to cleanup some of the things we have done before this transition. Is there a way to do the following via the Github API (or some other way). We did a lot of research online and trial and error and there doesn’t seem to be a solution for this:

We are trying to pull all public/private repos for our organization as well as all the members of each repo.

So for example if we have 5 repos (a, b, c, d, e) we would like to have a way to pull that list of repos with all the team members who have access (Read or Write) to the specific Repo

Repo a – person X, person Y
Repo b – person X, person Z

Etc

If we could get any help it would be greatly appreciated. Thanks in advance.

Hi @aahanchi - thanks for posting your query. I’ve recategorized your post to the GitHub Ecosystem which should give you visibility with folks who may be better suited to assist you.

Hi @aahanchi welcome to the community

I know what you mean as the solution does not really jump out at you when looking at the reference documents.
The answer i derived when I need to get this information was to use GraphQL API and get the list of collaborators on each repository. The example I have shared below includes the permission each collaborator (user) has on the repository.

simplified example below

query ($org: String!, $first: Int!, $endCursor: String) {
organization(login: $org) {
repositories (first: $first, after: $endCursor) {
totalCount
edges{
node {
name
collaborators ( first: 100 ) {
totalCount
edges {
node { login }
permission
}
}
}
}
pageInfo { endCursor, hasNextPage }
}
}
}

If more than 100 members on some repos and more than 100 repos in the organization you will hit a nested cursor issues.
The simplest solution for me was to first get all repos in org then iterate over each repo to get all its contributors and only having to handle pagination of the collaborators on a repository
You can even get the permission sources by adding the following

                     permissionSources {
                        permission
                        source {
                            ... on Organization {
                                ORG: login
                            }
                            ... on Repository {
                                REPO: name
                            }
                            ... on Team {
                                TEAM: name
                            }
                        }
                    }

Good luck

1 Like