Skip to content

Commit

Permalink
Merge pull request #388
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Oct 28, 2017
2 parents e675435 + 83c2c4e commit cc2e60c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 32 deletions.
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.14</version>
<version>1.17</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -120,7 +120,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand All @@ -130,7 +130,7 @@
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
<version>1.14</version>
<version>1.17</version>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
Expand All @@ -141,7 +141,7 @@
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>3.1.0.201310021548-r</version>
<version>4.9.0.201710071750-r</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -153,25 +153,25 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-urlconnection</artifactId>
<version>3.4.0</version>
<version>3.9.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>wordnet-random-name</artifactId>
<version>1.2</version>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/kohsuke/github/GHDeployment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import java.io.IOException;
import java.net.URL;

/**
* Represents a deployment
*
* @see <a href="https://developer.github.com/v3/repos/deployments/">documentation</a>
* @see GHRepository#listDeployments(String, String, String, String)
* @see GHRepository#getDeployment(long)
*/
public class GHDeployment extends GHObject {
private GHRepository owner;
private GitHub root;
Expand Down Expand Up @@ -58,4 +65,23 @@ public String getSha(){
public URL getHtmlUrl() {
return null;
}

public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) {
return new GHDeploymentStatusBuilder(owner,id,state);
}

public PagedIterable<GHDeploymentStatus> listStatuses() {
return new PagedIterable<GHDeploymentStatus>() {
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(statuses_url, GHDeploymentStatus[].class, pageSize)) {
@Override
protected void wrapUp(GHDeploymentStatus[] page) {
for (GHDeploymentStatus c : page)
c.wrap(owner);
}
};
}
};
}

}
18 changes: 16 additions & 2 deletions src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@

import java.io.IOException;

/**
* Creates a new deployment status.
*
* @see
* GHDeployment#createStatus(GHDeploymentState)
*/
public class GHDeploymentStatusBuilder {
private final Requester builder;
private GHRepository repo;
private int deploymentId;
private long deploymentId;

/**
* @deprecated
* Use {@link GHDeployment#createStatus(GHDeploymentState)}
*/
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
this(repo,(long)deploymentId,state);
}

/*package*/ GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
this.repo = repo;
this.deploymentId = deploymentId;
this.builder = new Requester(repo.root);
Expand All @@ -25,6 +39,6 @@ public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
}

public GHDeploymentStatus create() throws IOException {
return builder.to(repo.getApiTailUrl("deployments")+"/"+deploymentId+"/statuses",GHDeploymentStatus.class).wrap(repo);
return builder.to(repo.getApiTailUrl("deployments/"+deploymentId+"/statuses"),GHDeploymentStatus.class).wrap(repo);
}
}
14 changes: 9 additions & 5 deletions src/main/java/org/kohsuke/github/GHObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class GHObject {
protected Map<String, List<String>> responseHeaderFields;

protected String url;
protected int id;
protected long id;
protected String created_at;
protected String updated_at;

Expand Down Expand Up @@ -84,14 +84,18 @@ public Date getUpdatedAt() throws IOException {
/**
* Unique ID number of this resource.
*/
@WithBridgeMethods(value=String.class, adapterMethod="intToString")
public int getId() {
@WithBridgeMethods(value={String.class,int.class}, adapterMethod="longToStringOrInt")
public long getId() {
return id;
}

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
private Object intToString(int id, Class type) {
return String.valueOf(id);
private Object longToStringOrInt(long id, Class type) {
if (type==String.class)
return String.valueOf(id);
if (type==int.class)
return (int)id;
throw new AssertionError("Unexpected type: "+type);
}

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,12 @@ public GHDeploymentBuilder createDeployment(String ref) {
return new GHDeploymentBuilder(this,ref);
}

public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) {
return new PagedIterable<GHDeploymentStatus>() {
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class, pageSize)) {
@Override
protected void wrapUp(GHDeploymentStatus[] page) {
for (GHDeploymentStatus c : page)
c.wrap(GHRepository.this);
}
};
}
};
/**
* @deprecated
* Use {@code getDeployment(id).listStatuses()}
*/
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) throws IOException {
return getDeployment(id).listStatuses();
}

public PagedIterable<GHDeployment> listDeployments(String sha,String ref,String task,String environment){
Expand All @@ -123,7 +117,13 @@ protected void wrapUp(GHDeployment[] page) {
};
}
};
}

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

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

public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState) {
return new GHDeploymentStatusBuilder(this,deploymentId,ghDeploymentState);
/**
* @deprecated
* Use {@code getDeployment(deploymentId).createStatus(ghDeploymentState)}
*/
public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeploymentState ghDeploymentState) throws IOException {
return getDeployment(deploymentId).createStatus(ghDeploymentState);
}

private static class GHRepoPermission {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ public PagedIterable<GHRepository> listAllPublicRepositories() {
* This provides a dump of every public repository, in the order that they were created.
*
* @param since
* The integer ID of the last Repository that you’ve seen. See {@link GHRepository#getId()}
* The numeric ID of the last Repository that you’ve seen. See {@link GHRepository#getId()}
* @see <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">documentation</a>
*/
public PagedIterable<GHRepository> listAllPublicRepositories(final String since) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public void testListAllRepositories() throws Exception {
GHRepository r = itr.next();
System.out.println(r.getFullName());
assertNotNull(r.getUrl());
assertNotEquals(0,r.getId());
assertNotEquals(0L,r.getId());
}
}

Expand Down

0 comments on commit cc2e60c

Please sign in to comment.