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

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!

3 Replies
Community Manager
Message 2 of 4

Re: GraphQL: Repo collaborators organized by team?

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!

Copilot Lvl 2
Message 3 of 4

Re: GraphQL: Repo collaborators organized by team?

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.

Ground Controller Lvl 1
Message 4 of 4

Re: GraphQL: Repo collaborators organized by team?

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
}
}
}
}
}
}
}