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

Add Slug to GHTeam per v3 API: https://developer.github.com/v3/orgs/t… #281

Merged
merged 1 commit into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ public GHTeam getTeamByName(String name) throws IOException {
return null;
}

/**
* Finds a team that has the given slug in its {@link GHTeam#getSlug()}
*/
public GHTeam getTeamBySlug(String slug) throws IOException {
for (GHTeam t : listTeams()) {
if(t.getSlug().equals(slug))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irritating that the single-team API seems to require a numeric ID rather than the “slug”.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just opened a feature request with GitHub support to allow selecting teams via :slug key in addition to the :id key within the API.

Copy link

@samrocketman samrocketman May 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They accepted the enhancement for selecting teams via :slug but with the usual "we make no guarantees" line. So we may or may not see it as a feature of the API in the future.

return t;
}
return null;
}

/**
* Checks if this organization has the specified user as a member.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author Kohsuke Kawaguchi
*/
public class GHTeam {
private String name,permission;
private String name,permission,slug;
private int id;
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together

Expand Down Expand Up @@ -43,6 +43,10 @@ public String getPermission() {
return permission;
}

public String getSlug() {
return slug;
}

public int getId() {
return id;
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ public void testOrgTeamByName() throws Exception {
assertNotNull(e);
}

@Test
public void testOrgTeamBySlug() throws Exception {
kohsuke();
GHTeam e = gitHub.getOrganization("github-api-test-org").getTeamBySlug("core-developers");
assertNotNull(e);
}

@Test
public void testCommit() throws Exception {
GHCommit commit = gitHub.getUser("jenkinsci").getRepository("jenkins").getCommit("08c1c9970af4d609ae754fbe803e06186e3206f7");
Expand Down