GitHub API How to check if user has write access to a repository

前端 未结 2 1286
别那么骄傲
别那么骄傲 2021-02-05 22:24

I currently have a bot which automates a few GitHub operations, like merging pull requests, notifying staff on Slack when a PR is opened, that kind of thing (it\'s a custom flav

相关标签:
2条回答
  • 2021-02-05 22:54

    My company uses Github enterprise.

    This API Docs link helped

    GET /repos/:owner/:repo/collaborators/:username

    If user has access you would get a response similar to

    Status: 204 No Content

    X-RateLimit-Limit: 5000

    X-RateLimit-Remaining: 4999

    0 讨论(0)
  • 2021-02-05 23:00

    UPDATE: there is now a GitHub API endpoint for this:

    https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level


    OLD ANSWER: There isn't a much simpler way to do this currently (but I agree that it would be great if there was a more elegant way to get this information). You could perhaps reduce the number of requests by fetching the user's teams and the list of teams which have access to the repository (and not all teams in the organizations). The intersection of these two lists should allow you to answer the question, I think.

    (Also, in your solution, note that you not only have to check that the user is a member of a push-access team -- you also need to check that this push-access team has access to the repository in question. The user could have been a member of a push-access team which doesn't have access to the repository in question, and a member of a pull-access team which does have access to the repository in question.)

    0 讨论(0)
提交回复
热议问题