Make getTeambySlug fast enought

This commit is contained in:
Karol Lassak
2020-03-09 16:04:01 +01:00
parent a6eff7fbfb
commit fbf6c73226
2 changed files with 27 additions and 6 deletions

View File

@@ -128,6 +128,24 @@ public class GHOrganization extends GHPerson {
.toIterable(GHTeam[].class, item -> item.wrapUp(this));
}
/**
* Gets a single team by ID.
*
* @param id
* the id
* @return the team
* @throws IOException
* the io exception
*
* @see <a href=
* "https://developer.github.com/v3/teams/#get-team-by-name">documentation</a>
*/
public GHTeam getTeam(int id) throws IOException {
return root.createRequest()
.withUrlPath(String.format("/orgs/%s/teams/%d", login, id))
.fetch(GHTeam.class).wrapUp(this);
}
/**
* Finds a team that has the given name in its {@link GHTeam#getName()}
*
@@ -147,19 +165,19 @@ public class GHOrganization extends GHPerson {
/**
* Finds a team that has the given slug in its {@link GHTeam#getSlug()}
*
*
* @param slug
* the slug
* @return the team by slug
* @throws IOException
* the io exception
* @see <a href=
* "https://developer.github.com/v3/teams/#get-team-by-name">documentation</a>
*/
public GHTeam getTeamBySlug(String slug) throws IOException {
for (GHTeam t : listTeams()) {
if (t.getSlug().equals(slug))
return t;
}
return null;
return root.createRequest()
.withUrlPath(String.format("/orgs/%s/teams/%s", login, slug))
.fetch(GHTeam.class).wrapUp(this);
}
/**

View File

@@ -724,7 +724,10 @@ public class GitHub {
* @return the team
* @throws IOException
* the io exception
*
* @deprecated Use {@link GHOrganization#getTeam(int)}
*/
@Deprecated
public GHTeam getTeam(int id) throws IOException {
return createRequest().withUrlPath("/teams/" + id).fetch(GHTeam.class).wrapUp(this);
}