且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GitHub API如何检查用户是否具有对存储库的写访问权

更新时间:2023-11-30 11:50:34

更新:现在有一个GitHub API端点:

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.)