Skip to content

Commit cc2e60c

Browse files
committed
Merge pull request hub4j#388
2 parents e675435 + 83c2c4e commit cc2e60c

7 files changed

Lines changed: 80 additions & 32 deletions

File tree

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<plugin>
6565
<groupId>com.infradna.tool</groupId>
6666
<artifactId>bridge-method-injector</artifactId>
67-
<version>1.14</version>
67+
<version>1.17</version>
6868
<executions>
6969
<execution>
7070
<goals>
@@ -108,7 +108,7 @@
108108
<dependency>
109109
<groupId>junit</groupId>
110110
<artifactId>junit</artifactId>
111-
<version>4.11</version>
111+
<version>4.12</version>
112112
<scope>test</scope>
113113
</dependency>
114114
<dependency>
@@ -120,7 +120,7 @@
120120
<dependency>
121121
<groupId>com.fasterxml.jackson.core</groupId>
122122
<artifactId>jackson-databind</artifactId>
123-
<version>2.2.3</version>
123+
<version>2.9.2</version>
124124
</dependency>
125125
<dependency>
126126
<groupId>commons-io</groupId>
@@ -130,7 +130,7 @@
130130
<dependency>
131131
<groupId>com.infradna.tool</groupId>
132132
<artifactId>bridge-method-annotation</artifactId>
133-
<version>1.14</version>
133+
<version>1.17</version>
134134
</dependency>
135135
<dependency>
136136
<groupId>org.kohsuke.stapler</groupId>
@@ -141,7 +141,7 @@
141141
<dependency>
142142
<groupId>org.eclipse.jgit</groupId>
143143
<artifactId>org.eclipse.jgit</artifactId>
144-
<version>3.1.0.201310021548-r</version>
144+
<version>4.9.0.201710071750-r</version>
145145
<scope>test</scope>
146146
</dependency>
147147
<dependency>
@@ -153,25 +153,25 @@
153153
<dependency>
154154
<groupId>com.squareup.okhttp3</groupId>
155155
<artifactId>okhttp-urlconnection</artifactId>
156-
<version>3.4.0</version>
156+
<version>3.9.0</version>
157157
<optional>true</optional>
158158
</dependency>
159159
<dependency>
160160
<groupId>org.kohsuke</groupId>
161161
<artifactId>wordnet-random-name</artifactId>
162-
<version>1.2</version>
162+
<version>1.3</version>
163163
<scope>test</scope>
164164
</dependency>
165165
<dependency>
166166
<groupId>org.mockito</groupId>
167167
<artifactId>mockito-all</artifactId>
168-
<version>1.9.5</version>
168+
<version>1.10.19</version>
169169
<scope>test</scope>
170170
</dependency>
171171
<dependency>
172172
<groupId>com.google.code.findbugs</groupId>
173173
<artifactId>annotations</artifactId>
174-
<version>3.0.0</version>
174+
<version>3.0.1</version>
175175
<scope>provided</scope>
176176
</dependency>
177177
</dependencies>

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

Lines 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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +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;
8-
private int deploymentId;
14+
private long deploymentId;
915

16+
/**
17+
* @deprecated
18+
* Use {@link GHDeployment#createStatus(GHDeploymentState)}
19+
*/
1020
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
21+
this(repo,(long)deploymentId,state);
22+
}
23+
24+
/*package*/ GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
1125
this.repo = repo;
1226
this.deploymentId = deploymentId;
1327
this.builder = new Requester(repo.root);
@@ -25,6 +39,6 @@ public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
2539
}
2640

2741
public GHDeploymentStatus create() throws IOException {
28-
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);
2943
}
3044
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public abstract class GHObject {
2525
protected Map<String, List<String>> responseHeaderFields;
2626

2727
protected String url;
28-
protected int id;
28+
protected long id;
2929
protected String created_at;
3030
protected String updated_at;
3131

@@ -84,14 +84,18 @@ public Date getUpdatedAt() throws IOException {
8484
/**
8585
* Unique ID number of this resource.
8686
*/
87-
@WithBridgeMethods(value=String.class, adapterMethod="intToString")
88-
public int getId() {
87+
@WithBridgeMethods(value={String.class,int.class}, adapterMethod="longToStringOrInt")
88+
public long getId() {
8989
return id;
9090
}
9191

9292
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
93-
private Object intToString(int id, Class type) {
94-
return String.valueOf(id);
93+
private Object longToStringOrInt(long id, Class type) {
94+
if (type==String.class)
95+
return String.valueOf(id);
96+
if (type==int.class)
97+
return (int)id;
98+
throw new AssertionError("Unexpected type: "+type);
9599
}
96100

97101
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,12 @@ public GHDeploymentBuilder createDeployment(String ref) {
9595
return new GHDeploymentBuilder(this,ref);
9696
}
9797

98-
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) {
99-
return new PagedIterable<GHDeploymentStatus>() {
100-
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
101-
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class, pageSize)) {
102-
@Override
103-
protected void wrapUp(GHDeploymentStatus[] page) {
104-
for (GHDeploymentStatus c : page)
105-
c.wrap(GHRepository.this);
106-
}
107-
};
108-
}
109-
};
98+
/**
99+
* @deprecated
100+
* Use {@code getDeployment(id).listStatuses()}
101+
*/
102+
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) throws IOException {
103+
return getDeployment(id).listStatuses();
110104
}
111105

112106
public PagedIterable<GHDeployment> listDeployments(String sha,String ref,String task,String environment){
@@ -123,7 +117,13 @@ protected void wrapUp(GHDeployment[] page) {
123117
};
124118
}
125119
};
120+
}
126121

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);
127127
}
128128

129129
private String join(List<String> params, String joinStr) {
@@ -140,8 +140,12 @@ private String getParam(String name, String value) {
140140
return StringUtils.trimToNull(value)== null? null: name+"="+value;
141141
}
142142

143-
public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState) {
144-
return new GHDeploymentStatusBuilder(this,deploymentId,ghDeploymentState);
143+
/**
144+
* @deprecated
145+
* Use {@code getDeployment(deploymentId).createStatus(ghDeploymentState)}
146+
*/
147+
public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState) throws IOException {
148+
return getDeployment(deploymentId).createStatus(ghDeploymentState);
145149
}
146150

147151
private static class GHRepoPermission {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public PagedIterable<GHRepository> listAllPublicRepositories() {
809809
* This provides a dump of every public repository, in the order that they were created.
810810
*
811811
* @param since
812-
* The integer ID of the last Repository that you’ve seen. See {@link GHRepository#getId()}
812+
* The numeric ID of the last Repository that you’ve seen. See {@link GHRepository#getId()}
813813
* @see <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">documentation</a>
814814
*/
815815
public PagedIterable<GHRepository> listAllPublicRepositories(final String since) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ public void testListAllRepositories() throws Exception {
788788
GHRepository r = itr.next();
789789
System.out.println(r.getFullName());
790790
assertNotNull(r.getUrl());
791-
assertNotEquals(0,r.getId());
791+
assertNotEquals(0L,r.getId());
792792
}
793793
}
794794

0 commit comments

Comments
 (0)