11

In a repos that belongs to an organization (as opposed to an individual), collaborators are members of "teams", and teams can have three different kinds of permissions:

  • Pull Only
  • Push & Pull
  • Push, Pull, & Administrative

I can see a list of collaborators on a repos like this:

GET /repos/:owner/:repo/collaborators

...but it does not tell me what type of permissions a collaborator has.

In this particular case, I am one of the collaborators; I do not own the repository.

Is there a way to programmatically determine the type of collaborator permission I have?

Dan Tenenbaum
  • 1,809
  • 3
  • 23
  • 35
  • In fact it _does_ return permissions [at least under some conditions](https://developer.github.com/v3/repos/collaborators/#list-collaborators). – Jesse Glick Mar 07 '16 at 20:42

2 Answers2

13

If you want to check whether you have push access to a GitHub repo, you can use the repo endpoint:

GET /repos/:owner/:repo

If your request includes your authorization information (either including your account credentials or an OAuth access token), the permissions field will give you the information you're looking for:

{ 'admin': False, 'push': False, 'pull': True }

Anders Rabo Thorbeck
  • 1,126
  • 3
  • 18
  • 28
jm.carp
  • 388
  • 2
  • 11
  • More focused on an individual for a particular repo, as opposed to my answer (reading admin right for an all team). Interesting. +1 – VonC Jan 09 '14 at 06:31
1

Update June 2017: You now have nested teams.
However, the orgs/teams API mentions:

The REST API v3 does not yet fully support nested teams.
For example, the endpoints for List team members and List team repositories do not return results inherited from a nested team's structure.

Warning: since January 2020, The Team APIs will be moving from a top-level path under /teams/:team_id to a scoped path under the organization that owns the team with a path like /organizations/:org_id/team/:team_id.
See "Moving the teams API" by Dirkjan Bussink


Original answer 2016

The one query which should include your permission is mentioned in "List User Teams"

GET /user/teams

List all of the teams across all of the organizations to which the authenticated user belongs. This method requires user or repo scope when authenticating via OAuth.

The answer looks like:

Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999

[
  {
    "url": "https://api.github.com/teams/1",
    "name": "Owners",
    "id": 1,
    "permission": "admin",                     <============
    "members_count": 3,
    "repos_count": 10,
    "organization": {
      "login": "github",
      "id": 1,
      "url": "https://api.github.com/orgs/github",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif"
    }
  }
]

You need to filter that result in order to match the team with the right repo, and you should get back the permission level associated to that repo that way.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note that `/user/teams` assumes that the user looking for this information is the same as the user being checked for permissions. – Jesse Glick Mar 07 '16 at 20:16