Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit a2fa526

Browse files
author
Surya Gaddipati
committed
Add code for creating deployments for a repo
1 parent af3099c commit a2fa526

4 files changed

Lines changed: 71 additions & 29 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.kohsuke.github;
2+
3+
public class GHDeployment {
4+
private GHRepository owner;
5+
private GitHub root;
6+
7+
GHDeployment wrap(GHRepository owner) {
8+
this.owner = owner;
9+
this.root = owner.root;
10+
return this;
11+
}
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
5+
public class GHDeploymentBuilder {
6+
private final GHRepository repo;
7+
private final Requester builder;
8+
9+
public GHDeploymentBuilder(GHRepository repo) {
10+
this.repo = repo;
11+
this.builder = new Requester(repo.root);
12+
}
13+
14+
public GHDeploymentBuilder ref(String branch) {
15+
builder.with("ref",branch);
16+
return this;
17+
}
18+
19+
public GHDeploymentBuilder payload(String payload) {
20+
builder.with("payload",payload);
21+
return this;
22+
}
23+
24+
public GHDeploymentBuilder description(String description) {
25+
builder.with("description",description);
26+
return this;
27+
}
28+
29+
public GHDeployment create() throws IOException {
30+
return builder.to(repo.getApiTailUrl("deployments"),GHDeployment.class).wrap(repo);
31+
}
32+
}

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,15 @@
2525

2626
import com.fasterxml.jackson.annotation.JsonProperty;
2727
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
28-
import java.io.FileNotFoundException;
2928

3029
import javax.xml.bind.DatatypeConverter;
30+
import java.io.FileNotFoundException;
3131
import java.io.IOException;
3232
import java.io.InterruptedIOException;
3333
import java.net.URL;
34-
import java.util.AbstractSet;
35-
import java.util.ArrayList;
36-
import java.util.Arrays;
37-
import java.util.Collection;
38-
import java.util.Collections;
39-
import java.util.Date;
40-
import java.util.HashMap;
41-
import java.util.HashSet;
42-
import java.util.Iterator;
43-
import java.util.List;
44-
import java.util.Locale;
45-
import java.util.Map;
46-
import java.util.Set;
47-
import java.util.TreeMap;
48-
49-
import static java.util.Arrays.*;
34+
import java.util.*;
35+
36+
import static java.util.Arrays.asList;
5037

5138
/**
5239
* A repository on GitHub.
@@ -74,6 +61,10 @@ public class GHRepository {
7461

7562
private GHRepoPermission permissions;
7663

64+
public GHDeploymentBuilder createDeployment() {
65+
return new GHDeploymentBuilder(this);
66+
}
67+
7768
private static class GHRepoPermission {
7869
boolean pull,push,admin;
7970
}

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package org.kohsuke.github;
22

3-
import java.io.IOException;
4-
import java.net.URL;
5-
import java.util.ArrayList;
6-
import java.util.Date;
7-
import java.util.List;
8-
import java.util.Map;
9-
import java.util.Map.Entry;
10-
import java.util.Set;
11-
import java.util.UUID;
12-
3+
import com.google.common.base.Predicate;
4+
import com.google.common.collect.Iterables;
135
import org.junit.Assume;
146
import org.junit.Test;
157
import org.kohsuke.github.GHCommit.File;
168
import org.kohsuke.github.GHOrganization.Permission;
179

18-
import com.google.common.base.Predicate;
19-
import com.google.common.collect.Iterables;
10+
import java.io.IOException;
11+
import java.net.URL;
12+
import java.util.*;
13+
import java.util.Map.Entry;
2014

2115
/**
2216
* Unit test for simple App.
@@ -82,6 +76,19 @@ public void testCreateIssue() throws IOException {
8276
o.close();
8377
}
8478

79+
@Test
80+
public void testCreateDeployment() throws IOException {
81+
GHUser u = getUser();
82+
GHRepository repository = getTestRepository();
83+
//GHMilestone milestone = repository.createMilestone(System.currentTimeMillis() + "", "Test Milestone");
84+
GHDeployment o = repository.createDeployment()
85+
.ref("master")
86+
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
87+
.description("question")
88+
.create();
89+
assertNotNull(o);
90+
}
91+
8592
@Test
8693
public void testGetIssues() throws Exception {
8794
List<GHIssue> closedIssues = gitHub.getUser("kohsuke").getRepository("github-api").getIssues(GHIssueState.CLOSED);

0 commit comments

Comments
 (0)