Right now, fetching a single GitHub organisation member by username requires listing all members in that organisation using the listMembers method and filtering the response by the username. A similar approach is already encoded in the library for the getTeamByName which lists all teams and then filters by the team name. However, there exists a Get Organisation Memberships For A User endpoint on the GitHub API that could be used to fetch the user and other useful attributes.
This new method would be very similar to the hasMember method in the GHOrganisation.class (copied below) but calls /orgs/{org}/memberships/{username} and needs to map the response to the appropriate GHUser object.
/**
* Checks if this organization has the specified user as a member.
*
* @param user
* the user
* @return the boolean
*/
public boolean hasMember(GHUser user) {
try {
root().createRequest().withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send();
return true;
} catch (IOException ignore) {
return false;
}
}
I'm happy to create a PR if you think this would be valuable.
Right now, fetching a single GitHub organisation member by username requires listing all members in that organisation using the
listMembers
method and filtering the response by the username. A similar approach is already encoded in the library for thegetTeamByName
which lists all teams and then filters by the team name. However, there exists a Get Organisation Memberships For A User endpoint on the GitHub API that could be used to fetch the user and other useful attributes.This new method would be very similar to the
hasMember
method in theGHOrganisation.class
(copied below) but calls/orgs/{org}/memberships/{username}
and needs to map the response to the appropriate GHUser object.I'm happy to create a PR if you think this would be valuable.