Skip to content

Add support for fetching a single organisation member by username #1849

@fv316

Description

@fv316

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions