GraphQL: Repo collaborators organized by team?

In the graphql API, Repostory has a collaborators connection; however, it always seems to return bare users. We generally grant repo permissions only to teams, not to users directly. Is there a way to retrieve the access grants in the form they were made (i.e. by team)?

Thanks!

The collaborators connection is for outside collaborators, in other words people that have access to that repository that  are not members of your organization. You can easily find out the permissions that a team was granted to each repository by going from the organization, to the team, then use the edges of the repositories connection from the team to get the permissions granted for each repository.

I hope that helps!

Hm, that is a partial answer, but maybe I wasn’t clear on what I was looking to do; for a specific subset of repos, I want to identify which teams have access, what that access is (so far so good), but the access class I’m specifically trying to identify is users that have been granted individual user permissions on a repo, either as internal or external collaborators.

Actually, I think this gives me what I was looking for:

organization(login: $org) {
    repository(name: $repo) {
      collaborators(first: 100, after: $endCursor) {
        edges {
          node {
            login
          }
          permissionSources {
            permission
            source {
              ... on Organization {
                ORG: login
              }
              ... on Repository {
                REPO: name
              }
              ... on Team {
                TEAM: name
              }
            }
          }
        }
      }
    }
  }

Not sure this is the best / most efficient way, but it looks like the data I was looking for.

1 Like

organization(login: $org) {
repository(name: $repo) {
collaborators(first: 100, after: $endCursor) {
edges {
node {
login
}
permissionSources {
permission
source {
… on Organization {
ORG: login
}
… on Repository {
REPO: name
}
… on Team {
TEAM: name
}
}
}
}
}
}
}