From a2fa526aa072756871a503ff2c57c8f01ff23d3d Mon Sep 17 00:00:00 2001 From: Surya Gaddipati Date: Fri, 19 Dec 2014 12:47:00 -0600 Subject: [PATCH] Add code for creating deployments for a repo --- .../java/org/kohsuke/github/GHDeployment.java | 12 +++++++ .../kohsuke/github/GHDeploymentBuilder.java | 32 +++++++++++++++++++ .../java/org/kohsuke/github/GHRepository.java | 25 +++++---------- src/test/java/org/kohsuke/github/AppTest.java | 31 +++++++++++------- 4 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHDeployment.java create mode 100644 src/main/java/org/kohsuke/github/GHDeploymentBuilder.java diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java new file mode 100644 index 0000000000..a6045a32fe --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -0,0 +1,12 @@ +package org.kohsuke.github; + +public class GHDeployment { + private GHRepository owner; + private GitHub root; + + GHDeployment wrap(GHRepository owner) { + this.owner = owner; + this.root = owner.root; + return this; + } +} diff --git a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java new file mode 100644 index 0000000000..3a2830befa --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java @@ -0,0 +1,32 @@ +package org.kohsuke.github; + +import java.io.IOException; + +public class GHDeploymentBuilder { + private final GHRepository repo; + private final Requester builder; + + public GHDeploymentBuilder(GHRepository repo) { + this.repo = repo; + this.builder = new Requester(repo.root); + } + + public GHDeploymentBuilder ref(String branch) { + builder.with("ref",branch); + return this; + } + + public GHDeploymentBuilder payload(String payload) { + builder.with("payload",payload); + return this; + } + + public GHDeploymentBuilder description(String description) { + builder.with("description",description); + return this; + } + + public GHDeployment create() throws IOException { + return builder.to(repo.getApiTailUrl("deployments"),GHDeployment.class).wrap(repo); + } +} diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 4e3441166c..204a8004c0 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -25,28 +25,15 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.infradna.tool.bridge_method_injector.WithBridgeMethods; -import java.io.FileNotFoundException; import javax.xml.bind.DatatypeConverter; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InterruptedIOException; import java.net.URL; -import java.util.AbstractSet; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -import static java.util.Arrays.*; +import java.util.*; + +import static java.util.Arrays.asList; /** * A repository on GitHub. @@ -74,6 +61,10 @@ public class GHRepository { private GHRepoPermission permissions; + public GHDeploymentBuilder createDeployment() { + return new GHDeploymentBuilder(this); + } + private static class GHRepoPermission { boolean pull,push,admin; } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 07b386314b..a92b40242f 100644 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -1,22 +1,16 @@ package org.kohsuke.github; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; - +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import org.junit.Assume; import org.junit.Test; import org.kohsuke.github.GHCommit.File; import org.kohsuke.github.GHOrganization.Permission; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; +import java.io.IOException; +import java.net.URL; +import java.util.*; +import java.util.Map.Entry; /** * Unit test for simple App. @@ -82,6 +76,19 @@ public void testCreateIssue() throws IOException { o.close(); } + @Test + public void testCreateDeployment() throws IOException { + GHUser u = getUser(); + GHRepository repository = getTestRepository(); + //GHMilestone milestone = repository.createMilestone(System.currentTimeMillis() + "", "Test Milestone"); + GHDeployment o = repository.createDeployment() + .ref("master") + .payload("{\"user\":\"atmos\",\"room_id\":123456}") + .description("question") + .create(); + assertNotNull(o); + } + @Test public void testGetIssues() throws Exception { List closedIssues = gitHub.getUser("kohsuke").getRepository("github-api").getIssues(GHIssueState.CLOSED);