Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roles for team members #379

Merged
merged 1 commit into from
Jan 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 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,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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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);
}

Expand All @@ -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() {
Expand Down