hub4j/github-api

Add support for fetching a single organisation member by username

Closed this issue · 3 comments

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.

PR with tests welcome.

Could you give me access to hub4j-test-org? Unless the PR with my mock organisation is fine.

@fv316 Invite sent