Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83c2c4e

Browse filesBrowse files
committed
Fixed the broken design of how GHDeploymentStatus get exposed.
1 parent ab3d9e8 commit 83c2c4e
Copy full SHA for 83c2c4e

File tree

Expand file treeCollapse file tree

3 files changed

+47
-27
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+47
-27
lines changed

‎src/main/java/org/kohsuke/github/GHDeployment.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHDeployment.java
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
import java.io.IOException;
44
import java.net.URL;
55

6+
/**
7+
* Represents a deployment
8+
*
9+
* @see <a href="https://developer.github.com/v3/repos/deployments/">documentation</a>
10+
* @see GHRepository#listDeployments(String, String, String, String)
11+
* @see GHRepository#getDeployment(long)
12+
*/
613
public class GHDeployment extends GHObject {
714
private GHRepository owner;
815
private GitHub root;
@@ -58,4 +65,23 @@ public String getSha(){
5865
public URL getHtmlUrl() {
5966
return null;
6067
}
68+
69+
public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) {
70+
return new GHDeploymentStatusBuilder(owner,id,state);
71+
}
72+
73+
public PagedIterable<GHDeploymentStatus> listStatuses() {
74+
return new PagedIterable<GHDeploymentStatus>() {
75+
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
76+
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(statuses_url, GHDeploymentStatus[].class, pageSize)) {
77+
@Override
78+
protected void wrapUp(GHDeploymentStatus[] page) {
79+
for (GHDeploymentStatus c : page)
80+
c.wrap(owner);
81+
}
82+
};
83+
}
84+
};
85+
}
86+
6187
}

‎src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
import java.io.IOException;
44

5+
/**
6+
* Creates a new deployment status.
7+
*
8+
* @see
9+
* GHDeployment#createStatus(GHDeploymentState)
10+
*/
511
public class GHDeploymentStatusBuilder {
612
private final Requester builder;
713
private GHRepository repo;
814
private long deploymentId;
915

1016
/**
1117
* @deprecated
12-
* ID is long now.
18+
* Use {@link GHDeployment#createStatus(GHDeploymentState)}
1319
*/
1420
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
1521
this(repo,(long)deploymentId,state);
1622
}
1723

18-
public GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
24+
/*package*/ GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
1925
this.repo = repo;
2026
this.deploymentId = deploymentId;
2127
this.builder = new Requester(repo.root);
@@ -33,6 +39,6 @@ public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
3339
}
3440

3541
public GHDeploymentStatus create() throws IOException {
36-
return builder.to(repo.getApiTailUrl("deployments")+"/"+deploymentId+"/statuses",GHDeploymentStatus.class).wrap(repo);
42+
return builder.to(repo.getApiTailUrl("deployments/"+deploymentId+"/statuses"),GHDeploymentStatus.class).wrap(repo);
3743
}
3844
}

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+12-24Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,10 @@ public GHDeploymentBuilder createDeployment(String ref) {
9797

9898
/**
9999
* @deprecated
100-
* Use {@link #getDeploymentStatuses(long)}
100+
* Use {@code getDeployment(id).listStatuses()}
101101
*/
102-
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) {
103-
return getDeploymentStatuses((long)id);
104-
}
105-
106-
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final long id) {
107-
return new PagedIterable<GHDeploymentStatus>() {
108-
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
109-
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class, pageSize)) {
110-
@Override
111-
protected void wrapUp(GHDeploymentStatus[] page) {
112-
for (GHDeploymentStatus c : page)
113-
c.wrap(GHRepository.this);
114-
}
115-
};
116-
}
117-
};
102+
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) throws IOException {
103+
return getDeployment(id).listStatuses();
118104
}
119105

120106
public PagedIterable<GHDeployment> listDeployments(String sha,String ref,String task,String environment){
@@ -131,7 +117,13 @@ protected void wrapUp(GHDeployment[] page) {
131117
};
132118
}
133119
};
120+
}
134121

122+
/**
123+
* Obtains a single {@link GHDeployment} by its ID.
124+
*/
125+
public GHDeployment getDeployment(long id) throws IOException {
126+
return root.retrieve().to("deployments/" + id, GHDeployment.class).wrap(this);
135127
}
136128

137129
private String join(List<String> params, String joinStr) {
@@ -150,14 +142,10 @@ private String getParam(String name, String value) {
150142

151143
/**
152144
* @deprecated
153-
* Use {@link #createDeployStatus(long, GHDeploymentState)}
145+
* Use {@code getDeployment(deploymentId).createStatus(ghDeploymentState)}
154146
*/
155-
public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState) {
156-
return createDeployStatus((long)deploymentId,ghDeploymentState);
157-
}
158-
159-
public GHDeploymentStatusBuilder createDeployStatus(long deploymentId, GHDeploymentState ghDeploymentState) {
160-
return new GHDeploymentStatusBuilder(this,deploymentId,ghDeploymentState);
147+
public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState) throws IOException {
148+
return getDeployment(deploymentId).createStatus(ghDeploymentState);
161149
}
162150

163151
private static class GHRepoPermission {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.