Compare commits

..

18 Commits

Author SHA1 Message Date
Kohsuke Kawaguchi
2b7c524908 [maven-release-plugin] prepare release github-api-1.90 2017-10-28 15:54:33 -07:00
Kohsuke Kawaguchi
0b069df9ce Pick up the version that fixes int->long adaption 2017-10-28 15:48:26 -07:00
Kohsuke Kawaguchi
60c9ba88ae Updated tests 2017-10-28 15:27:38 -07:00
Kohsuke Kawaguchi
cc2e60c84a Merge pull request #388 2017-10-28 09:01:01 -07:00
Kohsuke Kawaguchi
83c2c4e92e Fixed the broken design of how GHDeploymentStatus get exposed. 2017-10-28 08:59:41 -07:00
Kohsuke Kawaguchi
ab3d9e82ef A little better version of the bridge method 2017-10-28 08:43:48 -07:00
Kohsuke Kawaguchi
b6063dd534 Restored binary compatibility 2017-10-28 08:42:27 -07:00
Kohsuke Kawaguchi
e6754354e4 Merge pull request #389 2017-10-28 07:54:47 -07:00
Kohsuke Kawaguchi
4849619d67 None of the connectToEnterprise methods are preferrable so document accordingly 2017-10-28 07:54:41 -07:00
Kohsuke Kawaguchi
9b0ace242a Merge pull request #390 2017-10-28 07:45:14 -07:00
Kohsuke Kawaguchi
e94ba74058 Convention is to call these methods setXyz. Plus doc 2017-10-28 07:44:23 -07:00
Baptiste Mathus
569fa06d2d Labels: add method to update color 2017-10-25 14:06:28 +02:00
iraleigh
46dce17abc Fixed Typo 2017-10-24 14:53:23 -07:00
iraleigh
40d8f4a352 Fixed OAuth connection to enterprise API 2017-10-24 14:24:25 -07:00
Arne Burmeister
6415785220 boyscout: updated dependencies 2017-10-23 17:05:31 +02:00
Arne Burmeister
7735edeae8 extend id from int to long 2017-10-23 17:05:02 +02:00
Kohsuke Kawaguchi
b443e866f9 Added lock/unlock op and additional properties
Issue #355
2017-09-09 20:38:40 -07:00
Kohsuke Kawaguchi
d4404713a8 [maven-release-plugin] prepare for next development iteration 2017-09-09 13:28:40 -07:00
11 changed files with 145 additions and 40 deletions

22
pom.xml
View File

@@ -7,7 +7,7 @@
</parent> </parent>
<artifactId>github-api</artifactId> <artifactId>github-api</artifactId>
<version>1.89</version> <version>1.90</version>
<name>GitHub API for Java</name> <name>GitHub API for Java</name>
<url>http://github-api.kohsuke.org/</url> <url>http://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description> <description>GitHub API for Java</description>
@@ -16,7 +16,7 @@
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection> <connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection> <developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
<url>http://${project.artifactId}.kohsuke.org/</url> <url>http://${project.artifactId}.kohsuke.org/</url>
<tag>github-api-1.89</tag> <tag>github-api-1.90</tag>
</scm> </scm>
<distributionManagement> <distributionManagement>
@@ -64,7 +64,7 @@
<plugin> <plugin>
<groupId>com.infradna.tool</groupId> <groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId> <artifactId>bridge-method-injector</artifactId>
<version>1.14</version> <version>1.18</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@@ -108,7 +108,7 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.11</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -120,7 +120,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.2.3</version> <version>2.9.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
@@ -130,7 +130,7 @@
<dependency> <dependency>
<groupId>com.infradna.tool</groupId> <groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId> <artifactId>bridge-method-annotation</artifactId>
<version>1.14</version> <version>1.17</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.kohsuke.stapler</groupId> <groupId>org.kohsuke.stapler</groupId>
@@ -141,7 +141,7 @@
<dependency> <dependency>
<groupId>org.eclipse.jgit</groupId> <groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId> <artifactId>org.eclipse.jgit</artifactId>
<version>3.1.0.201310021548-r</version> <version>4.9.0.201710071750-r</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -153,25 +153,25 @@
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-urlconnection</artifactId> <artifactId>okhttp-urlconnection</artifactId>
<version>3.4.0</version> <version>3.9.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.kohsuke</groupId> <groupId>org.kohsuke</groupId>
<artifactId>wordnet-random-name</artifactId> <artifactId>wordnet-random-name</artifactId>
<version>1.2</version> <version>1.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>
<version>1.9.5</version> <version>1.10.19</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.findbugs</groupId> <groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
<version>3.0.0</version> <version>3.0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -3,6 +3,13 @@ package org.kohsuke.github;
import java.io.IOException; import java.io.IOException;
import java.net.URL; 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 { public class GHDeployment extends GHObject {
private GHRepository owner; private GHRepository owner;
private GitHub root; private GitHub root;
@@ -58,4 +65,23 @@ public class GHDeployment extends GHObject {
public URL getHtmlUrl() { public URL getHtmlUrl() {
return null; 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);
}
};
}
};
}
} }

View File

@@ -2,12 +2,26 @@ package org.kohsuke.github;
import java.io.IOException; import java.io.IOException;
/**
* Creates a new deployment status.
*
* @see
* GHDeployment#createStatus(GHDeploymentState)
*/
public class GHDeploymentStatusBuilder { public class GHDeploymentStatusBuilder {
private final Requester builder; private final Requester builder;
private GHRepository repo; private GHRepository repo;
private int deploymentId; private long deploymentId;
/**
* @deprecated
* Use {@link GHDeployment#createStatus(GHDeploymentState)}
*/
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) { 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.repo = repo;
this.deploymentId = deploymentId; this.deploymentId = deploymentId;
this.builder = new Requester(repo.root); this.builder = new Requester(repo.root);
@@ -25,6 +39,6 @@ public class GHDeploymentStatusBuilder {
} }
public GHDeploymentStatus create() throws IOException { 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);
} }
} }

View File

@@ -68,6 +68,7 @@ public class GHIssue extends GHObject implements Reactable{
protected GHIssue.PullRequest pull_request; protected GHIssue.PullRequest pull_request;
protected GHMilestone milestone; protected GHMilestone milestone;
protected GHUser closed_by; protected GHUser closed_by;
protected boolean locked;
/** /**
* @deprecated use {@link GHLabel} * @deprecated use {@link GHLabel}
@@ -129,6 +130,10 @@ public class GHIssue extends GHObject implements Reactable{
return title; return title;
} }
public boolean isLocked() {
return locked;
}
public GHIssueState getState() { public GHIssueState getState() {
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH)); return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
} }
@@ -148,6 +153,14 @@ public class GHIssue extends GHObject implements Reactable{
return GitHub.parseURL(url); return GitHub.parseURL(url);
} }
public void lock() throws IOException {
new Requester(root).method("PUT").to(getApiRoute()+"/lock");
}
public void unlock() throws IOException {
new Requester(root).method("PUT").to(getApiRoute()+"/lock");
}
/** /**
* Updates the issue by adding a comment. * Updates the issue by adding a comment.
* *

View File

@@ -34,4 +34,12 @@ public class GHLabel {
public void delete() throws IOException { public void delete() throws IOException {
repo.root.retrieve().method("DELETE").to(url); repo.root.retrieve().method("DELETE").to(url);
} }
/**
* @param newColor
* 6-letter hex color code, like "f29513"
*/
public void setColor(String newColor) throws IOException {
repo.root.retrieve().method("PATCH").with("name", name).with("color", newColor).to(url);
}
} }

View File

@@ -25,7 +25,7 @@ public abstract class GHObject {
protected Map<String, List<String>> responseHeaderFields; protected Map<String, List<String>> responseHeaderFields;
protected String url; protected String url;
protected int id; protected long id;
protected String created_at; protected String created_at;
protected String updated_at; protected String updated_at;
@@ -84,14 +84,18 @@ public abstract class GHObject {
/** /**
* Unique ID number of this resource. * Unique ID number of this resource.
*/ */
@WithBridgeMethods(value=String.class, adapterMethod="intToString") @WithBridgeMethods(value={String.class,int.class}, adapterMethod="longToStringOrInt")
public int getId() { public long getId() {
return id; return id;
} }
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId") @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
private Object intToString(int id, Class type) { private Object longToStringOrInt(long id, Class type) {
return String.valueOf(id); 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") @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")

View File

@@ -50,8 +50,8 @@ public class GHPullRequest extends GHIssue {
// details that are only available when obtained from ID // details that are only available when obtained from ID
private GHUser merged_by; private GHUser merged_by;
private int review_comments, additions; private int review_comments, additions, commits;
private boolean merged; private boolean merged, maintainer_can_modify;
private Boolean mergeable; private Boolean mergeable;
private int deletions; private int deletions;
private String mergeable_state; private String mergeable_state;
@@ -167,11 +167,21 @@ public class GHPullRequest extends GHIssue {
return additions; return additions;
} }
public int getCommits() throws IOException {
populate();
return commits;
}
public boolean isMerged() throws IOException { public boolean isMerged() throws IOException {
populate(); populate();
return merged; return merged;
} }
public boolean canMaintainerModify() throws IOException {
populate();
return maintainer_can_modify;
}
public Boolean getMergeable() throws IOException { public Boolean getMergeable() throws IOException {
populate(); populate();
return mergeable; return mergeable;

View File

@@ -95,18 +95,12 @@ public class GHRepository extends GHObject {
return new GHDeploymentBuilder(this,ref); return new GHDeploymentBuilder(this,ref);
} }
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) { /**
return new PagedIterable<GHDeploymentStatus>() { * @deprecated
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) { * Use {@code getDeployment(id).listStatuses()}
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class, pageSize)) { */
@Override public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) throws IOException {
protected void wrapUp(GHDeploymentStatus[] page) { return getDeployment(id).listStatuses();
for (GHDeploymentStatus c : page)
c.wrap(GHRepository.this);
}
};
}
};
} }
public PagedIterable<GHDeployment> listDeployments(String sha,String ref,String task,String environment){ public PagedIterable<GHDeployment> listDeployments(String sha,String ref,String task,String environment){
@@ -123,7 +117,13 @@ public class GHRepository extends GHObject {
}; };
} }
}; };
}
/**
* 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) { private String join(List<String> params, String joinStr) {
@@ -140,8 +140,12 @@ public class GHRepository extends GHObject {
return StringUtils.trimToNull(value)== null? null: name+"="+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 { private static class GHRepoPermission {

View File

@@ -166,6 +166,16 @@ public class GitHub {
return GitHubBuilder.fromCredentials().build(); return GitHubBuilder.fromCredentials().build();
} }
/**
* Version that connects to GitHub Enterprise.
*
* @deprecated
* Use {@link #connectToEnterpriseWithOAuth(String, String, String)}
*/
public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) throws IOException {
return connectToEnterpriseWithOAuth(apiUrl,null,oauthAccessToken);
}
/** /**
* Version that connects to GitHub Enterprise. * Version that connects to GitHub Enterprise.
* *
@@ -174,10 +184,16 @@ public class GitHub {
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL. * "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated. * For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
*/ */
public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) throws IOException { public static GitHub connectToEnterpriseWithOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException {
return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken).build(); return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken, login).build();
} }
/**
* Version that connects to GitHub Enterprise.
*
* @deprecated
* Use with caution. Login with password is not a preferred method.
*/
public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException { public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException {
return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build(); return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build();
} }
@@ -793,7 +809,7 @@ public class GitHub {
* This provides a dump of every public repository, in the order that they were created. * This provides a dump of every public repository, in the order that they were created.
* *
* @param since * @param since
* The integer ID of the last Repository that youve seen. See {@link GHRepository#getId()} * The numeric ID of the last Repository that youve seen. See {@link GHRepository#getId()}
* @see <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">documentation</a> * @see <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">documentation</a>
*/ */
public PagedIterable<GHRepository> listAllPublicRepositories(final String since) { public PagedIterable<GHRepository> listAllPublicRepositories(final String since) {

View File

@@ -154,6 +154,12 @@ public class GitHubBuilder {
return self; return self;
} }
/**
* @param endpoint
* The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
*/
public GitHubBuilder withEndpoint(String endpoint) { public GitHubBuilder withEndpoint(String endpoint) {
this.endpoint = endpoint; this.endpoint = endpoint;
return this; return this;

View File

@@ -134,10 +134,10 @@ public class AppTest extends AbstractGitHubApiTestBase {
.description("question") .description("question")
.payload("{\"user\":\"atmos\",\"room_id\":123456}") .payload("{\"user\":\"atmos\",\"room_id\":123456}")
.create(); .create();
GHDeploymentStatus ghDeploymentStatus = repository.createDeployStatus(deployment.getId(), GHDeploymentState.SUCCESS) GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.SUCCESS)
.description("success") .description("success")
.targetUrl("http://www.github.com").create(); .targetUrl("http://www.github.com").create();
Iterable<GHDeploymentStatus> deploymentStatuses = repository.getDeploymentStatuses(deployment.getId()); Iterable<GHDeploymentStatus> deploymentStatuses = deployment.listStatuses();
assertNotNull(deploymentStatuses); assertNotNull(deploymentStatuses);
assertEquals(1,Iterables.size(deploymentStatuses)); assertEquals(1,Iterables.size(deploymentStatuses));
assertEquals(ghDeploymentStatus.getId(), Iterables.get(deploymentStatuses, 0).getId()); assertEquals(ghDeploymentStatus.getId(), Iterables.get(deploymentStatuses, 0).getId());
@@ -753,6 +753,10 @@ public class AppTest extends AbstractGitHubApiTestBase {
assertEquals(t.getColor(), "123456"); assertEquals(t.getColor(), "123456");
assertEquals(t.getColor(), t2.getColor()); assertEquals(t.getColor(), t2.getColor());
assertEquals(t.getUrl(), t2.getUrl()); assertEquals(t.getUrl(), t2.getUrl());
t.setColor("000000");
GHLabel t3 = r.getLabel("test");
assertEquals(t3.getColor(), "000000");
t.delete(); t.delete();
} }
} }
@@ -784,7 +788,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
GHRepository r = itr.next(); GHRepository r = itr.next();
System.out.println(r.getFullName()); System.out.println(r.getFullName());
assertNotNull(r.getUrl()); assertNotNull(r.getUrl());
assertNotEquals(0,r.getId()); assertNotEquals(0L,r.getId());
} }
} }