Skip to content

Commit 70bd4fa

Browse files
committed
Merge pull request hub4j#379
2 parents 7f52031 + 6599605 commit 70bd4fa

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/main/java/org/kohsuke/github/GHTeam.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ public class GHTeam {
1818

1919
protected /*final*/ GHOrganization org;
2020

21+
/** Member's role in a team */
22+
public enum Role {
23+
/**
24+
* A normal member of the team
25+
*/
26+
MEMBER,
27+
/**
28+
* Able to add/remove other team members, promote other team members to team maintainer, and edit the team's name and description.
29+
*/
30+
MAINTAINER
31+
}
32+
2133
/*package*/ GHTeam wrapUp(GHOrganization owner) {
2234
this.org = owner;
2335
return this;
@@ -116,6 +128,22 @@ public void add(GHUser u) throws IOException {
116128
org.root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null);
117129
}
118130

131+
/**
132+
* Adds a member to the team
133+
*
134+
* The user will be invited to the organization if required.
135+
*
136+
* @param user github user
137+
* @param role role for the new member
138+
*
139+
* @throws IOException
140+
*/
141+
public void add(GHUser user, Role role) throws IOException {
142+
org.root.retrieve().method("PUT")
143+
.with("role", role.name())
144+
.to(api("/memberships/" + user.getLogin()), null);
145+
}
146+
119147
/**
120148
* Removes a member to the team.
121149
*/
@@ -129,7 +157,7 @@ public void add(GHRepository r) throws IOException {
129157

130158
public void add(GHRepository r, GHOrganization.Permission permission) throws IOException {
131159
org.root.retrieve().method("PUT")
132-
.with("permission",permission)
160+
.with("permission", permission)
133161
.to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
134162
}
135163

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

147175
private String api(String tail) {
148-
return "/teams/"+id+tail;
176+
return "/teams/" + id + tail;
149177
}
150178

151179
public GHOrganization getOrganization() {

0 commit comments

Comments
 (0)