Skip to content

Commit

Permalink
Complete implementation of create deployment api
Browse files Browse the repository at this point in the history
  • Loading branch information
suryagaddipati committed Dec 20, 2014
1 parent 425ae2d commit bc518a9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
44 changes: 44 additions & 0 deletions src/main/java/org/kohsuke/github/GHDeployment.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
package org.kohsuke.github;

import java.net.URL;
import java.util.Date;

public class GHDeployment {
private GHRepository owner;
private GitHub root;
protected String url;
protected String sha;
protected int id;
protected String task;
protected String payload;
protected String environment;
protected String description;
protected String statuses_url;
protected String repository_url;
protected String created_at;
protected String updated_at;
protected GHUser creator;


GHDeployment wrap(GHRepository owner) {
this.owner = owner;
this.root = owner.root;
if(creator != null) creator.wrapUp(root);
return this;
}
public Date getCreatedAt() {
return GitHub.parseDate(created_at);
}

public URL getUrl() {
return GitHub.parseURL(url);
}

public URL getStatusesUrl() {
return GitHub.parseURL(statuses_url);
}

public URL getRepositoryUrl() {
return GitHub.parseURL(repository_url);
}

public GHUser getCreator() {
return creator;
}

public Date getUpdatedAt() {
return GitHub.parseDate(updated_at);
}

public int getId() {
return id;
}
}
21 changes: 20 additions & 1 deletion src/main/java/org/kohsuke/github/GHDeploymentBuilder.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
package org.kohsuke.github;

import java.io.IOException;
import java.util.List;

//Based on https://developer.github.com/v3/repos/deployments/#create-a-deployment
public class GHDeploymentBuilder {
private final GHRepository repo;
private final Requester builder;

public GHDeploymentBuilder(GHRepository repo) {
public GHDeploymentBuilder(GHRepository repo, String ref) {
this.repo = repo;
this.builder = new Requester(repo.root);
ref(ref);
}

public GHDeploymentBuilder ref(String branch) {
builder.with("ref",branch);
return this;
}
public GHDeploymentBuilder task(String task) {
builder.with("task",task);
return this;
}
public GHDeploymentBuilder autoMerge(boolean autoMerge) {
builder.with("auto_merge",autoMerge);
return this;
}

public GHDeploymentBuilder requiredContexts(List<String> requiredContexts) {
builder.with("required_contexts",requiredContexts);
return this;
}
public GHDeploymentBuilder payload(String payload) {
builder.with("payload",payload);
return this;
}

public GHDeploymentBuilder environment(String environment) {
builder.with("environment",environment);
return this;
}
public GHDeploymentBuilder description(String description) {
builder.with("description",description);
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHRepository.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class GHRepository {

private GHRepoPermission permissions;

public GHDeploymentBuilder createDeployment() {
return new GHDeploymentBuilder(this);
public GHDeploymentBuilder createDeployment(String ref) {
return new GHDeploymentBuilder(this,ref);
}

private static class GHRepoPermission {
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/org/kohsuke/github/AppTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ public void testCreateIssue() throws IOException {

@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")
GHDeployment deployment = repository.createDeployment("master")
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
.description("question")
.create();
assertNotNull(o);
assertNotNull(deployment.getCreator());
assertNotNull(deployment.getId());
}

@Test
Expand Down

0 comments on commit bc518a9

Please sign in to comment.