What level of access do I have on that GitHub repository?

Featured image for sharing metadata for article

Earlier today, I was trying to work out if I had sufficient privileges to make some changes on a repository.

Without access to the Settings panel as a non-Admin on the repo made it a little difficult, so I went looking for API access, and it turns out there are some good APIs for checking collaborator access, such as Get repository permissions for a user as well as Check if a user is a repository collaborator.

We can use this to check i.e. if I personally have access to oapi-codegen repo:

$ gh api /repos/oapi-codegen/oapi-codegen/collaborators/jamietanna/permission
{
  "permission": "admin",
  "role_name": "admin",
  "user": {
    "login": "jamietanna",
    "permissions": {
      "admin": true,
      "maintain": true,
      "pull": true,
      "push": true,
      "triage": true
    },
    "role_name": "admin",
  }
}

(slightly omitted for brevity)

Alternatively, for a user that'll only have read-only access:

$ gh api /repos/oapi-codegen/oapi-codegen/collaborators/jamietanna-bot/permission
{
  "permission": "read",
  "role_name": "read",
  "user": {
    "login": "jamietanna-bot",
    "permissions": {
      "admin": false,
      "maintain": false,
      "pull": true,
      "push": false,
      "triage": false
    },
    "role_name": "read",
  }
}

This only works when you have at least push access to a repository:

% gh api /repos/wiremock/wiremock.org/collaborators/jamietanna/permission
gh: Must have push access to view collaborator permission. (HTTP 403)
{
  "message": "Must have push access to view collaborator permission.",
  "documentation_url": "https://docs.github.com/rest/collaborators/collaborators#get-repository-permissions-for-a-user",
  "status": "403"
}

This also only works for a GitHub User not an App.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #github.

This blog post is 100% human-written, and has nothing derived from LLMs (be it code, editorial support or prose).

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.