I have Github Organization with the owners Owner1 and Owner2 and members Member1 and Member2. Now I created a new repository in this Organization and added two users as collaborators (user1 and user2) of this repo.
Now the result of postman
with the below GET request will result in the following:
Owner1
Owner2
user1
user2
POSTMAN request : https://<github-host>/api/v3/repos/<my-gihub-org>/<my-github-repo>/collaborators?per_page=100
But I am interested in listing only the collaborators i.e., user1 and user2; Not the owners.
Could someone please help me here..!
You can pass the affiliation
parameter, in order to filter out any collaborators that directly work on a certain project.
curl -H "Authorization: <bearer KEY>" \
-H "Accept: application/vnd.github.v3+json" \
-XGET https://api.github.com/repos/:org/:repo/collaborators\?affiliation\=direct
This should return just the people who work on a project, and not both collaborators and owners.
GitHub states that:
affiliation | string | query
Filter collaborators returned by their affiliation. Can be one of:
- outside: All outside collaborators of an organization-owned repository.
- direct: All collaborators with permissions to an organization-owned repository, regardless of organization membership status.
- all: All collaborators the authenticated user can see.
If it so happens that an owner is also a direct collaborator to this repo, then you have to do another request, where you check which person is the owner, and then filter them out from the collaborators request.
curl -H "Authorization: <bearer KEY>" \
-H "Accept: application/vnd.github.v3+json" \
-XGET https://api.github.com/orgs/:org/members\?role\=admin
With this request, you can check which are the owners of an organization.
If you fancy using the new graphql feature, then you can query for
{
organization(login: "org_name") {
id
name
repository(name: "repo_name") {
collaborators(affiliation: DIRECT, first: N) {
edges {
permission
node {
name
}
}
}
}
}
}