Roh*_*ith 1 git github github-api postman github-api-v3
我有 Github 组织,其所有者为 Owner1 和 Owner2,以及成员 Member1 和 Member2。现在,我在此组织中创建了一个新存储库,并添加了两个用户作为该存储库的协作者(user1 和 user2)。
现在,以下 GET 请求的结果postman将如下:
Owner1
Owner2
user1
user2
Run Code Online (Sandbox Code Playgroud)
邮递员请求:https://<github-host>/api/v3/repos/<my-gihub-org>/<my-github-repo>/collaborators?per_page=100
但我有兴趣只列出合作者,即user1和user2;不是业主。
有人可以在这里帮助我吗..!
您可以传递该affiliation参数,以过滤掉直接参与某个项目的任何协作者。
curl -H "Authorization: <bearer KEY>" \
-H "Accept: application/vnd.github.v3+json" \
-XGET https://api.github.com/repos/:org/:repo/collaborators\?affiliation\=direct
Run Code Online (Sandbox Code Playgroud)
这应该只返回参与项目的人员,而不是合作者和所有者。
GitHub 声明:
隶属关系 | 字符串| 查询
按隶属关系过滤返回的协作者。可以是以下之一:
- 外部:组织拥有的存储库的所有外部协作者。
- 直接:有权访问组织拥有的存储库的所有协作者,无论组织成员身份如何。
- all:经过身份验证的用户可以看到的所有协作者。
如果所有者也是此存储库的直接协作者,那么您必须执行另一个请求,在其中检查哪个人是所有者,然后从协作者请求中过滤掉他们。
curl -H "Authorization: <bearer KEY>" \
-H "Accept: application/vnd.github.v3+json" \
-XGET https://api.github.com/orgs/:org/members\?role\=admin
Run Code Online (Sandbox Code Playgroud)
通过此请求,您可以检查哪些是组织的所有者。
如果您喜欢使用新的 graphql 功能,那么您可以查询
{
organization(login: "org_name") {
id
name
repository(name: "repo_name") {
collaborators(affiliation: DIRECT, first: N) {
edges {
permission
node {
name
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)