diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index ae950aed70..a2f9a87ae4 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -18,6 +18,12 @@ public class GHTeam { protected /*final*/ GHOrganization org; + /** Member's role in a team */ + public enum ROLE { + MEMBER, // A normal member of the team + MAINTAINER // Able to add/remove other team members, promote other team members to team maintainer, and edit the team's name and description. + }; + /*package*/ GHTeam wrapUp(GHOrganization owner) { this.org = owner; return this; @@ -116,6 +122,22 @@ public void add(GHUser u) throws IOException { org.root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null); } + /** + * Adds a member to the team + * + * The user will be invited to the organization if required. + * + * @param user github user + * @param role role for the new member + * + * @throws IOException + */ + public void add(GHUser user, ROLE role) throws IOException { + org.root.retrieve().method("PUT") + .with("role", role.name()) + .to(api("/memberships/" + user.getLogin()), null); + } + /** * Removes a member to the team. */ @@ -129,7 +151,7 @@ public void add(GHRepository r) throws IOException { public void add(GHRepository r, GHOrganization.Permission permission) throws IOException { org.root.retrieve().method("PUT") - .with("permission",permission) + .with("permission", permission) .to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null); } @@ -145,7 +167,7 @@ public void delete() throws IOException { } private String api(String tail) { - return "/teams/"+id+tail; + return "/teams/" + id + tail; } public GHOrganization getOrganization() {