Skip to content

Commit

Permalink
Merge pull request #379
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Jan 13, 2018
2 parents 7f52031 + 6599605 commit 70bd4fa
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public class GHTeam {

protected /*final*/ GHOrganization org;

/** Member's role in a team */
public enum Role {
/**
* A normal member of the team
*/
MEMBER,
/**
* Able to add/remove other team members, promote other team members to team maintainer, and edit the team's name and description.
*/
MAINTAINER
}

/*package*/ GHTeam wrapUp(GHOrganization owner) {
this.org = owner;
return this;
Expand Down Expand Up @@ -116,6 +128,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.
*/
Expand All @@ -129,7 +157,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);
}

Expand All @@ -145,7 +173,7 @@ public void delete() throws IOException {
}

private String api(String tail) {
return "/teams/"+id+tail;
return "/teams/" + id + tail;
}

public GHOrganization getOrganization() {
Expand Down

0 comments on commit 70bd4fa

Please sign in to comment.