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

前端 未结 2 1315
别那么骄傲
别那么骄傲 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 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.)

提交回复
热议问题