Skip to content

Commit

Permalink
Merge pull request #75 from rtyley/check-team-membership
Browse files Browse the repository at this point in the history
Support the check-user-team-membership API call
  • Loading branch information
kohsuke committed Mar 28, 2014
2 parents 2941c44 + b1d37e4 commit 5278ae3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public Set<GHUser> getMembers() throws IOException {
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().to(api("/members"), GHUser[].class), org.root)));
}

/**
* Checks if this team has the specified user as a member.
*/
public boolean hasMember(GHUser user) {
try {
org.root.retrieve().to("/teams/" + id + "/members/" + user.getLogin());
return true;
} catch (IOException ignore) {
return false;
}
}

public Map<String,GHRepository> getRepositories() throws IOException {
GHRepository[] repos = org.root.retrieve().to(api("/repos"), GHRepository[].class);
Map<String,GHRepository> m = new TreeMap<String, GHRepository>();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/kohsuke/github/GHUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public boolean isMemberOf(GHOrganization org) {
return org.hasMember(this);
}

/**
* Returns true if this user belongs to the specified team.
*/
public boolean isMemberOf(GHTeam team) {
return team.hasMember(this);
}

/**
* Returns true if this user belongs to the specified organization as a public member.
*/
Expand Down

0 comments on commit 5278ae3

Please sign in to comment.