Skip to content

Commit

Permalink
Merge pull request #142 from suryagaddipati/master
Browse files Browse the repository at this point in the history
Add code for creating deployments for a repo
  • Loading branch information
kohsuke committed Dec 19, 2014
2 parents a6cacd4 + a2fa526 commit 425ae2d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 29 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHDeployment.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/kohsuke/github/GHDeploymentBuilder.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
25 changes: 8 additions & 17 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
31 changes: 19 additions & 12 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<GHIssue> closedIssues = gitHub.getUser("kohsuke").getRepository("github-api").getIssues(GHIssueState.CLOSED);
Expand Down

0 comments on commit 425ae2d

Please sign in to comment.