mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-04 08:21:23 +00:00
That didn't quite work because v3 API has owner as an object, whereas v2 API has owner as string. So then I fixed all the other retrieval points for GHRepository to use v3.
67 lines
1.7 KiB
Java
67 lines
1.7 KiB
Java
package org.kohsuke.github;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* A team in GitHub organization.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
public class GHTeam {
|
|
private String name,permission;
|
|
private int id;
|
|
|
|
protected /*final*/ GHOrganization org;
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public String getPermission() {
|
|
return permission;
|
|
}
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the current members.
|
|
*/
|
|
public Set<GHUser> getMembers() throws IOException {
|
|
return org.root.retrieveWithAuth(api("/members"),JsonUsersWithDetails.class).toSet(org.root);
|
|
}
|
|
|
|
public Map<String,GHRepository> getRepositories() throws IOException {
|
|
return org.root.retrieveWithAuth3(api("/repos"),JsonRepositories.class).wrap(org.root);
|
|
}
|
|
|
|
/**
|
|
* Adds a member to the team.
|
|
*/
|
|
public void add(GHUser u) throws IOException {
|
|
org.root.retrieveWithAuth(api("/members?name="+u.getLogin()),null, "POST");
|
|
}
|
|
|
|
/**
|
|
* Removes a member to the team.
|
|
*/
|
|
public void remove(GHUser u) throws IOException {
|
|
org.root.retrieveWithAuth(api("/members?name="+u.getLogin()),null, "DELETE");
|
|
}
|
|
|
|
public void add(GHRepository r) throws IOException {
|
|
org.root.retrieveWithAuth(api("/repositories?name="+r.getOwnerName()+'/'+r.getName()),null, "POST");
|
|
}
|
|
|
|
public void remove(GHRepository r) throws IOException {
|
|
org.root.retrieveWithAuth(api("/repositories?name="+r.getOwnerName()+'/'+r.getName()),null, "DELETE");
|
|
}
|
|
|
|
private String api(String tail) {
|
|
return "/teams/"+id+tail;
|
|
}
|
|
}
|