From 32754ffcf57a0aa1de66ebb60acaaf1daef07b0e Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 27 Jan 2020 07:24:01 +0000 Subject: [PATCH] Cleanup based on review --- .../org/kohsuke/github/GHOrganization.java | 14 +++++++----- src/main/java/org/kohsuke/github/GHTeam.java | 4 ++-- ...ateTeamBuilder.java => GHTeamBuilder.java} | 22 ++++++++++--------- .../java/org/kohsuke/github/GHTeamTest.java | 6 ++--- 4 files changed, 26 insertions(+), 20 deletions(-) rename src/main/java/org/kohsuke/github/{GHCreateTeamBuilder.java => GHTeamBuilder.java} (73%) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index a81c13ee2..38abd0acd 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -386,7 +386,7 @@ public class GHOrganization extends GHPerson { * @throws IOException * the io exception * @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use - * {@link #createTeam(String, Collection)} + * {@link #createTeam(String)} */ @Deprecated public GHTeam createTeam(String name, Permission p, Collection repositories) throws IOException { @@ -412,7 +412,7 @@ public class GHOrganization extends GHPerson { * @throws IOException * the io exception * @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use - * {@link #createTeam(String, GHRepository...)} + * {@link #createTeam(String)} */ @Deprecated public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException { @@ -429,7 +429,9 @@ public class GHOrganization extends GHPerson { * @return the gh team * @throws IOException * the io exception + * @deprecated Use {@link #createTeam(String)} that uses a builder pattern to let you control every aspect. */ + @Deprecated public GHTeam createTeam(String name, Collection repositories) throws IOException { Requester post = root.createRequest().method("POST").with("name", name); List repo_names = new ArrayList(); @@ -450,7 +452,9 @@ public class GHOrganization extends GHPerson { * @return the gh team * @throws IOException * the io exception + * @deprecated Use {@link #createTeam(String)} that uses a builder pattern to let you control every aspect. */ + @Deprecated public GHTeam createTeam(String name, GHRepository... repositories) throws IOException { return createTeam(name, Arrays.asList(repositories)); } @@ -459,15 +463,15 @@ public class GHOrganization extends GHPerson { * Starts a builder that creates a new team. * *

- * You use the returned builder to set various properties, then call {@link GHCreateTeamBuilder#create()} to finally + * You use the returned builder to set various properties, then call {@link GHTeamBuilder#create()} to finally * create a team. * * @param name * the name * @return the gh create repository builder */ - public GHCreateTeamBuilder createTeam(String name) { - return new GHCreateTeamBuilder(root, "/orgs/" + login + "/teams", name); + public GHTeamBuilder createTeam(String name) { + return new GHTeamBuilder(root, login, name); } /** diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 4e062f5ac..d80e4410c 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -126,14 +126,14 @@ public class GHTeam implements Refreshable { } /** - * Sets privacy. + * Updates the team's privacy setting. * * @param privacy * the privacy * @throws IOException * the io exception */ - public void setPrivacy(Privacy privacy) throws IOException { + public void updatePrivacy(Privacy privacy) throws IOException { root.createRequest().method("PATCH").with("privacy", privacy).withUrlPath(api("")).send(); } diff --git a/src/main/java/org/kohsuke/github/GHCreateTeamBuilder.java b/src/main/java/org/kohsuke/github/GHTeamBuilder.java similarity index 73% rename from src/main/java/org/kohsuke/github/GHCreateTeamBuilder.java rename to src/main/java/org/kohsuke/github/GHTeamBuilder.java index 1611e4c71..f4eb7a8ff 100644 --- a/src/main/java/org/kohsuke/github/GHCreateTeamBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTeamBuilder.java @@ -5,16 +5,18 @@ import java.util.List; /** * Creates a team. + * + * https://developer.github.com/v3/teams/#parameters */ -public class GHCreateTeamBuilder { +public class GHTeamBuilder { private final GitHub root; protected final Requester builder; - private final String apiUrlTail; + private final String orgName; - public GHCreateTeamBuilder(GitHub root, String apiUrlTail, String name) { + public GHTeamBuilder(GitHub root, String orgName, String name) { this.root = root; - this.apiUrlTail = apiUrlTail; + this.orgName = orgName; this.builder = root.createRequest(); this.builder.with("name", name); } @@ -26,7 +28,7 @@ public class GHCreateTeamBuilder { * description of team * @return a builder to continue with building */ - public GHCreateTeamBuilder description(String description) { + public GHTeamBuilder description(String description) { this.builder.with("description", description); return this; } @@ -38,7 +40,7 @@ public class GHCreateTeamBuilder { * maintainers of team * @return a builder to continue with building */ - public GHCreateTeamBuilder maintainers(List maintainers) { + public GHTeamBuilder maintainers(List maintainers) { this.builder.with("maintainers", maintainers); return this; } @@ -50,7 +52,7 @@ public class GHCreateTeamBuilder { * repoNames to add team to * @return a builder to continue with building */ - public GHCreateTeamBuilder repoNames(List repoNames) { + public GHTeamBuilder repoNames(List repoNames) { this.builder.with("repo_names", repoNames); return this; } @@ -62,7 +64,7 @@ public class GHCreateTeamBuilder { * privacy of team * @return a builder to continue with building */ - public GHCreateTeamBuilder privacy(GHTeam.Privacy privacy) { + public GHTeamBuilder privacy(GHTeam.Privacy privacy) { this.builder.with("privacy", privacy); return this; } @@ -74,7 +76,7 @@ public class GHCreateTeamBuilder { * parentTeamId of team * @return a builder to continue with building */ - public GHCreateTeamBuilder parentTeamId(int parentTeamId) { + public GHTeamBuilder parentTeamId(int parentTeamId) { this.builder.with("parent_team_id", parentTeamId); return this; } @@ -87,6 +89,6 @@ public class GHCreateTeamBuilder { * if team cannot be created */ public GHTeam create() throws IOException { - return builder.method("POST").withUrlPath(apiUrlTail).fetch(GHTeam.class).wrapUp(root); + return builder.method("POST").withUrlPath("/orgs/" + orgName + "/teams").fetch(GHTeam.class).wrapUp(root); } } diff --git a/src/test/java/org/kohsuke/github/GHTeamTest.java b/src/test/java/org/kohsuke/github/GHTeamTest.java index 81628a6e3..0b0271a36 100644 --- a/src/test/java/org/kohsuke/github/GHTeamTest.java +++ b/src/test/java/org/kohsuke/github/GHTeamTest.java @@ -32,13 +32,13 @@ public class GHTeamTest extends AbstractGitHubWireMockTest { } @Test - public void testSetPrivacy() throws IOException { + public void testUpdatePrivacy() throws IOException { String teamSlug = "dummy-team"; Privacy privacy = Privacy.CLOSED; // Set the privacy. GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug); - team.setPrivacy(privacy); + team.updatePrivacy(privacy); // Check that it was set correctly. team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug); @@ -47,7 +47,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest { privacy = Privacy.SECRET; // Set the privacy. - team.setPrivacy(privacy); + team.updatePrivacy(privacy); // Check that it was set correctly. team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);