Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 GitHub Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Kevin Sawicki (GitHub Inc.) - initial API and implementation /
 
 package org.eclipse.egit.github.core.service;
 
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_MEMBERS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_ORGS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_TEAMS;
 
 
 import java.util.List;
 import java.util.Map;
 
Service class for working with organization teams

See also:
GitHub team API documentation
 
 public class TeamService extends GitHubService {

Create team service
 
 	public TeamService() {
 		super();
 	}

Create team service

Parameters:
client
 
 	public TeamService(GitHubClient client) {
 		super(client);
 	}

Get team with given id

Parameters:
id
Returns:
team
Throws:
java.io.IOException
 
 	public Team getTeam(int idthrows IOException {
 		uri.append('/').append(id);
 		GitHubRequest request = createRequest();
 		request.setUri(uri);
 		request.setType(Team.class);
 		return (Team.get(request).getBody();
 	}

Get all teams in the given organization

Parameters:
organization
Returns:
list of teams
Throws:
java.io.IOException
 
 	public List<TeamgetTeams(String organizationthrows IOException {
 		if (organization == null)
 			throw new IllegalArgumentException("Organization cannot be null"); //$NON-NLS-1$
 		if (organization.length() == 0)
 			throw new IllegalArgumentException("Organization cannot be empty"); //$NON-NLS-1$
 
 		uri.append('/').append(organization);
 		request.setUri(uri);
 		request.setType(new TypeToken<List<Team>>() {
 		}.getType());
 		return getAll(request);
 	}

Create the given team

Parameters:
organization
team
Returns:
created team
Throws:
java.io.IOException
	public Team createTeam(String organizationTeam teamthrows IOException {
		return createTeam(organizationteamnull);
	}

Create the given team

Parameters:
organization
team
repoNames
Returns:
created team
Throws:
java.io.IOException
	public Team createTeam(String organizationTeam team,
			List<StringrepoNamesthrows IOException {
		if (organization == null)
			throw new IllegalArgumentException("Organization cannot be null"); //$NON-NLS-1$
		if (organization.length() == 0)
			throw new IllegalArgumentException("Organization cannot be null"); //$NON-NLS-1$
		if (team == null)
			throw new IllegalArgumentException("Team cannot be null"); //$NON-NLS-1$
		uri.append('/').append(organization);
		Map<StringObjectparams = new HashMap<StringObject>();
		params.put("name"team.getName()); //$NON-NLS-1$
		params.put("permission"team.getPermission()); //$NON-NLS-1$
		if (repoNames != null)
			params.put("repo_names"repoNames); //$NON-NLS-1$
		return .post(uri.toString(), paramsTeam.class);
	}

Edit the given team

Parameters:
team
Returns:
edited team
Throws:
java.io.IOException
	public Team editTeam(Team teamthrows IOException {
		if (team == null)
			throw new IllegalArgumentException("Team cannot be null"); //$NON-NLS-1$
		uri.append('/').append(team.getId());
		return .post(uri.toString(), teamTeam.class);
	}

Delete the team with the given id

Parameters:
id
Throws:
java.io.IOException
	public void deleteTeam(int idthrows IOException {
		uri.append('/').append(id);
	}

Get members of team with given id

Parameters:
id
Returns:
team members
Throws:
java.io.IOException
	public List<UsergetMembers(int idthrows IOException {
		uri.append('/').append(id);
		request.setUri(uri);
		request.setType(new TypeToken<List<User>>() {
		}.getType());
		return getAll(request);
	}

Is the given user a member of the team with the given id

Parameters:
id
user
Returns:
true if member, false if not member
Throws:
java.io.IOException
	public boolean isMember(int idString userthrows IOException {
		if (user == null)
			throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
		if (user.length() == 0)
			throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(id);
		uri.append('/').append(user);
		return check(uri.toString());
	}

Add given user to team with given id

Parameters:
id
user
Throws:
java.io.IOException
	public void addMember(int idString userthrows IOException {
		if (user == null)
			throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
		if (user.length() == 0)
			throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(id);
		uri.append('/').append(user);
	}

Remove given user from team with given id

Parameters:
id
user
Throws:
java.io.IOException
	public void removeMember(int idString userthrows IOException {
		if (user == null)
			throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
		if (user.length() == 0)
			throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(id);
		uri.append('/').append(user);
	}

Get all repositories for given team

Parameters:
id
Returns:
non-null list of repositories
Throws:
java.io.IOException
	public List<RepositorygetRepositories(int idthrows IOException {
		uri.append('/').append(id);
		request.setUri(uri);
		request.setType(new TypeToken<List<Repository>>() {
		}.getType());
		return getAll(request);
	}

Is given repository managed by given team

Parameters:
id
repository
Returns:
true if managed by team, false otherwise
Throws:
java.io.IOException
	public boolean isTeamRepository(int idIRepositoryIdProvider repository)
			throws IOException {
		String repoId = getId(repository);
		uri.append('/').append(id);
		uri.append('/').append(repoId);
		return check(uri.toString());
	}

Add repository to team

Parameters:
id
repository
Throws:
java.io.IOException
	public void addRepository(int idIRepositoryIdProvider repository)
			throws IOException {
		String repoId = getId(repository);
		uri.append('/').append(id);
		uri.append('/').append(repoId);
	}

Remove repository from team

Parameters:
id
repository
Throws:
java.io.IOException
	public void removeRepository(int idIRepositoryIdProvider repository)
			throws IOException {
		String repoId = getId(repository);
		uri.append('/').append(id);
		uri.append('/').append(repoId);
	}

Get teams associated with given repository

Parameters:
repository
Returns:
list of teams
Throws:
java.io.IOException
	public List<TeamgetTeams(IRepositoryIdProvider repository)
			throws IOException {
		String id = getId(repository);
		uri.append('/').append(id);
		request.setUri(uri);
		request.setType(new TypeToken<List<Team>>() {
		}.getType());
		return getAll(request);
	}
New to GrepCode? Check out our FAQ X