mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 08:21:20 +00:00
Compare commits
59 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6722266f5 | ||
|
|
11566891dc | ||
|
|
9aaf69cc9a | ||
|
|
aa43e265b7 | ||
|
|
67280951ff | ||
|
|
c3a9f6f9f5 | ||
|
|
e631e46dd1 | ||
|
|
15163ffde0 | ||
|
|
b898284821 | ||
|
|
3bb7eb2e03 | ||
|
|
11fcb9d456 | ||
|
|
29f826448a | ||
|
|
a8cf4a7120 | ||
|
|
60dce94a47 | ||
|
|
c965b9cc24 | ||
|
|
762a32eb6d | ||
|
|
541dac1aee | ||
|
|
e2e2329301 | ||
|
|
9afad71b0f | ||
|
|
7bbe0f7e8a | ||
|
|
d90adfa98e | ||
|
|
1dbcc4b776 | ||
|
|
18696fca2d | ||
|
|
c40100b6da | ||
|
|
6396818740 | ||
|
|
6df5a0d47b | ||
|
|
15c18c5547 | ||
|
|
4b6981c2e7 | ||
|
|
1b4025300c | ||
|
|
983c871bff | ||
|
|
609f532f8c | ||
|
|
c6fc03c73a | ||
|
|
b6e48cc4f9 | ||
|
|
50f43cc178 | ||
|
|
f421067a0d | ||
|
|
edd9a2d5b6 | ||
|
|
41e0329f55 | ||
|
|
21ea916e0d | ||
|
|
3b6ca3020e | ||
|
|
3737845b78 | ||
|
|
a30c78cd12 | ||
|
|
f8fba41a30 | ||
|
|
052902fb49 | ||
|
|
58143c26bc | ||
|
|
5d83894056 | ||
|
|
e35667525f | ||
|
|
2f318152d8 | ||
|
|
bc518a9ae8 | ||
|
|
425ae2d536 | ||
|
|
a6cacd4aba | ||
|
|
5a7083537c | ||
|
|
e15f7a59fd | ||
|
|
a2fa526aa0 | ||
|
|
7e959d6a87 | ||
|
|
5121fe1cbf | ||
|
|
3c3d4fc151 | ||
|
|
a7f75c9a6c | ||
|
|
e7262b8fbe | ||
|
|
af3099c526 |
19
pom.xml
19
pom.xml
@@ -3,11 +3,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>pom</artifactId>
|
<artifactId>pom</artifactId>
|
||||||
<version>10</version>
|
<version>12</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.59</version>
|
<version>1.63</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>HEAD</tag>
|
<tag>github-api-1.63</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
@@ -35,7 +35,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.12</version>
|
<version>1.14</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@@ -77,7 +77,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.12</version>
|
<version>1.14</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kohsuke.stapler</groupId>
|
<groupId>org.kohsuke.stapler</groupId>
|
||||||
@@ -107,6 +107,7 @@
|
|||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
<version>1.9.5</version>
|
<version>1.9.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
@@ -138,4 +139,12 @@
|
|||||||
<distribution>repo</distribution>
|
<distribution>repo</distribution>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
|
<mailingLists>
|
||||||
|
<mailingList>
|
||||||
|
<name>User List</name>
|
||||||
|
<post>github-api@googlegroups.com</post>
|
||||||
|
<archive>https://groups.google.com/forum/#!forum/github-api</archive>
|
||||||
|
</mailingList>
|
||||||
|
</mailingLists>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,26 +1,21 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset in a release.
|
* Asset in a release.
|
||||||
*
|
*
|
||||||
* @see GHRelease#getAssets()
|
* @see GHRelease#getAssets()
|
||||||
*/
|
*/
|
||||||
public class GHAsset {
|
public class GHAsset extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
private String url;
|
|
||||||
private String id;
|
|
||||||
private String name;
|
private String name;
|
||||||
private String label;
|
private String label;
|
||||||
private String state;
|
private String state;
|
||||||
private String content_type;
|
private String content_type;
|
||||||
private long size;
|
private long size;
|
||||||
private long download_count;
|
private long download_count;
|
||||||
private Date created_at;
|
|
||||||
private Date updated_at;
|
|
||||||
private String browser_download_url;
|
private String browser_download_url;
|
||||||
|
|
||||||
public String getContentType() {
|
public String getContentType() {
|
||||||
@@ -32,18 +27,10 @@ public class GHAsset {
|
|||||||
this.content_type = contentType;
|
this.content_type = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return created_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDownloadCount() {
|
public long getDownloadCount() {
|
||||||
return download_count;
|
return download_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
@@ -73,14 +60,6 @@ public class GHAsset {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return updated_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBrowserDownloadUrl() {
|
public String getBrowserDownloadUrl() {
|
||||||
return browser_download_url;
|
return browser_download_url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
* @see GitHub#createToken(Collection, String, String)
|
* @see GitHub#createToken(Collection, String, String)
|
||||||
* @see http://developer.github.com/v3/oauth/#create-a-new-authorization
|
* @see http://developer.github.com/v3/oauth/#create-a-new-authorization
|
||||||
*/
|
*/
|
||||||
public class GHAuthorization {
|
public class GHAuthorization extends GHObject {
|
||||||
public static final String USER = "user";
|
public static final String USER = "user";
|
||||||
public static final String USER_EMAIL = "user:email";
|
public static final String USER_EMAIL = "user:email";
|
||||||
public static final String USER_FOLLOW = "user:follow";
|
public static final String USER_FOLLOW = "user:follow";
|
||||||
@@ -33,24 +33,16 @@ public class GHAuthorization {
|
|||||||
public static final String ADMIN_KEY = "admin:public_key";
|
public static final String ADMIN_KEY = "admin:public_key";
|
||||||
|
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
private int id;
|
|
||||||
private String url;
|
|
||||||
private List<String> scopes;
|
private List<String> scopes;
|
||||||
private String token;
|
private String token;
|
||||||
private App app;
|
private App app;
|
||||||
private String note;
|
private String note;
|
||||||
private String note_url;
|
private String note_url;
|
||||||
private String updated_at;
|
|
||||||
private String created_at;
|
|
||||||
|
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getScopes() {
|
public List<String> getScopes() {
|
||||||
return scopes;
|
return scopes;
|
||||||
}
|
}
|
||||||
@@ -78,14 +70,6 @@ public class GHAuthorization {
|
|||||||
public URL getNoteUrl(){
|
public URL getNoteUrl(){
|
||||||
return GitHub.parseURL(note_url);
|
return GitHub.parseURL(note_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return GitHub.parseDate(updated_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*package*/ GHAuthorization wrap(GitHub root) {
|
/*package*/ GHAuthorization wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ import java.util.Date;
|
|||||||
* @see GHCommit#listComments()
|
* @see GHCommit#listComments()
|
||||||
* @see GHCommit#createComment(String, String, Integer, Integer)
|
* @see GHCommit#createComment(String, String, Integer, Integer)
|
||||||
*/
|
*/
|
||||||
public class GHCommitComment {
|
public class GHCommitComment extends GHObject {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
String updated_at, created_at;
|
String body, html_url, commit_id;
|
||||||
String body, url, html_url, commit_id;
|
|
||||||
Integer line;
|
Integer line;
|
||||||
int id;
|
|
||||||
String path;
|
String path;
|
||||||
User user;
|
User user;
|
||||||
|
|
||||||
@@ -32,14 +30,6 @@ public class GHCommitComment {
|
|||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return GitHub.parseDate(updated_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL like 'https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000#commitcomment-1252827' to
|
* URL like 'https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000#commitcomment-1252827' to
|
||||||
* show this commit comment in a browser.
|
* show this commit comment in a browser.
|
||||||
@@ -75,10 +65,6 @@ public class GHCommitComment {
|
|||||||
return line!=null ? line : -1;
|
return line!=null ? line : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user who put this comment.
|
* Gets the user who put this comment.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,12 +10,9 @@ import java.util.Date;
|
|||||||
* @see GHRepository#getCommitStatus(String)
|
* @see GHRepository#getCommitStatus(String)
|
||||||
* @see GHCommit#getStatus()
|
* @see GHCommit#getStatus()
|
||||||
*/
|
*/
|
||||||
public class GHCommitStatus {
|
public class GHCommitStatus extends GHObject {
|
||||||
String created_at, updated_at;
|
|
||||||
String state;
|
String state;
|
||||||
String target_url,description;
|
String target_url,description;
|
||||||
int id;
|
|
||||||
String url;
|
|
||||||
String context;
|
String context;
|
||||||
GHUser creator;
|
GHUser creator;
|
||||||
|
|
||||||
@@ -27,14 +24,6 @@ public class GHCommitStatus {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return GitHub.parseDate(updated_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GHCommitState getState() {
|
public GHCommitState getState() {
|
||||||
for (GHCommitState s : GHCommitState.values()) {
|
for (GHCommitState s : GHCommitState.values()) {
|
||||||
if (s.name().equalsIgnoreCase(state))
|
if (s.name().equalsIgnoreCase(state))
|
||||||
@@ -56,17 +45,6 @@ public class GHCommitStatus {
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API URL of this commit status.
|
|
||||||
*/
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GHUser getCreator() {
|
public GHUser getCreator() {
|
||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,6 @@ public class GHCompare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum Status {
|
public static enum Status {
|
||||||
behind, ahead, identical
|
behind, ahead, identical, diverged
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,11 +129,19 @@ public class GHContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
|
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
|
||||||
return update(newContent, commitMessage, null);
|
return update(newContent.getBytes(), commitMessage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException {
|
public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException {
|
||||||
String encodedContent = DatatypeConverter.printBase64Binary(newContent.getBytes());
|
return update(newContent.getBytes(), commitMessage, branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) throws IOException {
|
||||||
|
return update(newContentBytes, commitMessage, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage, String branch) throws IOException {
|
||||||
|
String encodedContent = DatatypeConverter.printBase64Binary(newContentBytes);
|
||||||
|
|
||||||
Requester requester = new Requester(owner.root)
|
Requester requester = new Requester(owner.root)
|
||||||
.with("path", path)
|
.with("path", path)
|
||||||
|
|||||||
53
src/main/java/org/kohsuke/github/GHDeployment.java
Normal file
53
src/main/java/org/kohsuke/github/GHDeployment.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class GHDeployment extends GHObject {
|
||||||
|
private GHRepository owner;
|
||||||
|
private GitHub root;
|
||||||
|
protected String sha;
|
||||||
|
protected String ref;
|
||||||
|
protected String task;
|
||||||
|
protected Object payload;
|
||||||
|
protected String environment;
|
||||||
|
protected String description;
|
||||||
|
protected String statuses_url;
|
||||||
|
protected String repository_url;
|
||||||
|
protected GHUser creator;
|
||||||
|
|
||||||
|
|
||||||
|
GHDeployment wrap(GHRepository owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.root = owner.root;
|
||||||
|
if(creator != null) creator.wrapUp(root);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getStatusesUrl() {
|
||||||
|
return GitHub.parseURL(statuses_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getRepositoryUrl() {
|
||||||
|
return GitHub.parseURL(repository_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTask() {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
public String getPayload() {
|
||||||
|
return (String) payload;
|
||||||
|
}
|
||||||
|
public String getEnvironment() {
|
||||||
|
return environment;
|
||||||
|
}
|
||||||
|
public GHUser getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
public String getRef() {
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
public String getSha(){
|
||||||
|
return sha;
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/main/java/org/kohsuke/github/GHDeploymentBuilder.java
Normal file
55
src/main/java/org/kohsuke/github/GHDeploymentBuilder.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//Based on https://developer.github.com/v3/repos/deployments/#create-a-deployment
|
||||||
|
public class GHDeploymentBuilder {
|
||||||
|
private final GHRepository repo;
|
||||||
|
private final Requester builder;
|
||||||
|
|
||||||
|
public GHDeploymentBuilder(GHRepository repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
this.builder = new Requester(repo.root);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentBuilder(GHRepository repo, String ref) {
|
||||||
|
this(repo);
|
||||||
|
ref(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentBuilder ref(String branch) {
|
||||||
|
builder.with("ref",branch);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public GHDeploymentBuilder task(String task) {
|
||||||
|
builder.with("task",task);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public GHDeploymentBuilder autoMerge(boolean autoMerge) {
|
||||||
|
builder.with("auto_merge",autoMerge);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentBuilder requiredContexts(List<String> requiredContexts) {
|
||||||
|
builder.with("required_contexts",requiredContexts);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public GHDeploymentBuilder payload(String payload) {
|
||||||
|
builder.with("payload",payload);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentBuilder environment(String environment) {
|
||||||
|
builder.with("environment",environment);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public GHDeploymentBuilder description(String description) {
|
||||||
|
builder.with("description",description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeployment create() throws IOException {
|
||||||
|
return builder.to(repo.getApiTailUrl("deployments"),GHDeployment.class).wrap(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/main/java/org/kohsuke/github/GHDeploymentState.java
Normal file
8
src/main/java/org/kohsuke/github/GHDeploymentState.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the state of deployment
|
||||||
|
*/
|
||||||
|
public enum GHDeploymentState {
|
||||||
|
PENDING, SUCCESS, ERROR, FAILURE
|
||||||
|
}
|
||||||
36
src/main/java/org/kohsuke/github/GHDeploymentStatus.java
Normal file
36
src/main/java/org/kohsuke/github/GHDeploymentStatus.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class GHDeploymentStatus extends GHObject {
|
||||||
|
private GHRepository owner;
|
||||||
|
private GitHub root;
|
||||||
|
protected GHUser creator;
|
||||||
|
protected String state;
|
||||||
|
protected String description;
|
||||||
|
protected String target_url;
|
||||||
|
protected String deployment_url;
|
||||||
|
protected String repository_url;
|
||||||
|
public GHDeploymentStatus wrap(GHRepository owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.root = owner.root;
|
||||||
|
if(creator != null) creator.wrapUp(root);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public URL getTargetUrl() {
|
||||||
|
return GitHub.parseURL(target_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getDeploymentUrl() {
|
||||||
|
return GitHub.parseURL(deployment_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getRepositoryUrl() {
|
||||||
|
return GitHub.parseURL(repository_url);
|
||||||
|
}
|
||||||
|
public GHDeploymentState getState() {
|
||||||
|
return GHDeploymentState.valueOf(state.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class GHDeploymentStatusBuilder {
|
||||||
|
private final Requester builder;
|
||||||
|
private GHRepository repo;
|
||||||
|
private int deploymentId;
|
||||||
|
|
||||||
|
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
|
||||||
|
this.repo = repo;
|
||||||
|
this.deploymentId = deploymentId;
|
||||||
|
this.builder = new Requester(repo.root);
|
||||||
|
this.builder.with("state",state.toString().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentStatusBuilder description(String description) {
|
||||||
|
this.builder.with("description",description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
|
||||||
|
this.builder.with("target_url",targetUrl);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeploymentStatus create() throws IOException {
|
||||||
|
return builder.to(repo.getApiTailUrl("deployments")+"/"+deploymentId+"/statuses",GHDeploymentStatus.class).wrap(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -120,6 +120,7 @@ public abstract class GHEventPayload {
|
|||||||
private String ref;
|
private String ref;
|
||||||
private int size;
|
private int size;
|
||||||
private List<PushCommit> commits;
|
private List<PushCommit> commits;
|
||||||
|
private GHRepository repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SHA of the HEAD commit on the repository
|
* The SHA of the HEAD commit on the repository
|
||||||
@@ -158,6 +159,16 @@ public abstract class GHEventPayload {
|
|||||||
return commits;
|
return commits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHRepository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void wrapUp(GitHub root) {
|
||||||
|
if (repository!=null)
|
||||||
|
repository.wrap(root);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit in a push
|
* Commit in a push
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -16,17 +15,18 @@ import java.util.Map.Entry;
|
|||||||
* @see GHUser#listGists()
|
* @see GHUser#listGists()
|
||||||
* @see GitHub#getGist(String)
|
* @see GitHub#getGist(String)
|
||||||
* @see GitHub#createGist()
|
* @see GitHub#createGist()
|
||||||
|
* @see <a href="https://developer.github.com/v3/gists/">documentation</a>
|
||||||
*/
|
*/
|
||||||
public class GHGist {
|
public class GHGist extends GHObject {
|
||||||
/*package almost final*/ GHUser owner;
|
/*package almost final*/ GHUser owner;
|
||||||
/*package almost final*/ GitHub root;
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
private String url, forks_url, commits_url, id, git_pull_url, git_push_url, html_url;
|
private String forks_url, commits_url, id, git_pull_url, git_push_url, html_url;
|
||||||
|
|
||||||
@JsonProperty("public")
|
@JsonProperty("public")
|
||||||
private boolean _public;
|
private boolean _public;
|
||||||
|
|
||||||
private String created_at, updated_at, description;
|
private String description;
|
||||||
|
|
||||||
private int comments;
|
private int comments;
|
||||||
|
|
||||||
@@ -41,13 +41,6 @@ public class GHGist {
|
|||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API URL of this gist, such as 'https://api.github.com/gists/12345'
|
|
||||||
*/
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getForksUrl() {
|
public String getForksUrl() {
|
||||||
return forks_url;
|
return forks_url;
|
||||||
}
|
}
|
||||||
@@ -56,13 +49,6 @@ public class GHGist {
|
|||||||
return commits_url;
|
return commits_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ID of this gist, such as '12345'
|
|
||||||
*/
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL like https://gist.github.com/gists/12345.git
|
* URL like https://gist.github.com/gists/12345.git
|
||||||
*/
|
*/
|
||||||
@@ -82,14 +68,6 @@ public class GHGist {
|
|||||||
return _public;
|
return _public;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return GitHub.parseDate(updated_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,18 +10,17 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHHook {
|
public class GHHook extends GHObject {
|
||||||
/**
|
/**
|
||||||
* Repository that the hook belongs to.
|
* Repository that the hook belongs to.
|
||||||
*/
|
*/
|
||||||
/*package*/ transient GHRepository repository;
|
/*package*/ transient GHRepository repository;
|
||||||
|
|
||||||
String created_at, updated_at, name;
|
String name;
|
||||||
List<String> events;
|
List<String> events;
|
||||||
boolean active;
|
boolean active;
|
||||||
Map<String,String> config;
|
Map<String,String> config;
|
||||||
int id;
|
|
||||||
|
|
||||||
/*package*/ GHHook wrap(GHRepository owner) {
|
/*package*/ GHHook wrap(GHRepository owner) {
|
||||||
this.repository = owner;
|
this.repository = owner;
|
||||||
return this;
|
return this;
|
||||||
@@ -46,10 +45,6 @@ public class GHHook {
|
|||||||
return Collections.unmodifiableMap(config);
|
return Collections.unmodifiableMap(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this hook.
|
* Deletes this hook.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,8 +37,11 @@ import java.util.Locale;
|
|||||||
*
|
*
|
||||||
* @author Eric Maupin
|
* @author Eric Maupin
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHRepository#getIssue(int)
|
||||||
|
* @see GitHub#searchIssues()
|
||||||
|
* @see GHIssueSearchBuilder
|
||||||
*/
|
*/
|
||||||
public class GHIssue {
|
public class GHIssue extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
@@ -49,37 +52,28 @@ public class GHIssue {
|
|||||||
protected String closed_at;
|
protected String closed_at;
|
||||||
protected int comments;
|
protected int comments;
|
||||||
protected String body;
|
protected String body;
|
||||||
|
// for backward compatibility with < 1.63, this collection needs to hold instances of Label, not GHLabel
|
||||||
protected List<Label> labels;
|
protected List<Label> labels;
|
||||||
protected GHUser user;
|
protected GHUser user;
|
||||||
protected String title, created_at, html_url;
|
protected String title, html_url;
|
||||||
protected GHIssue.PullRequest pull_request;
|
protected GHIssue.PullRequest pull_request;
|
||||||
protected GHMilestone milestone;
|
protected GHMilestone milestone;
|
||||||
protected String url, updated_at;
|
|
||||||
protected int id;
|
|
||||||
protected GHUser closed_by;
|
protected GHUser closed_by;
|
||||||
|
|
||||||
public static class Label {
|
/**
|
||||||
private String url;
|
* @deprecated use {@link GHLabel}
|
||||||
private String name;
|
*/
|
||||||
private String color;
|
public static class Label extends GHLabel {
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHIssue wrap(GHRepository owner) {
|
/*package*/ GHIssue wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
if(milestone != null) milestone.wrap(owner);
|
||||||
if(milestone != null) milestone.wrap(owner);
|
return wrap(owner.root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ GHIssue wrap(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
if(assignee != null) assignee.wrapUp(root);
|
if(assignee != null) assignee.wrapUp(root);
|
||||||
if(user != null) user.wrapUp(root);
|
if(user != null) user.wrapUp(root);
|
||||||
if(closed_by != null) closed_by.wrapUp(root);
|
if(closed_by != null) closed_by.wrapUp(root);
|
||||||
@@ -117,7 +111,7 @@ public class GHIssue {
|
|||||||
* The HTML page of this issue,
|
* The HTML page of this issue,
|
||||||
* like https://github.com/jenkinsci/jenkins/issues/100
|
* like https://github.com/jenkinsci/jenkins/issues/100
|
||||||
*/
|
*/
|
||||||
public URL getUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,19 +123,11 @@ public class GHIssue {
|
|||||||
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Label> getLabels() throws IOException {
|
public Collection<GHLabel> getLabels() throws IOException {
|
||||||
if(labels == null){
|
if(labels == null){
|
||||||
return Collections.EMPTY_LIST;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(labels);
|
return Collections.<GHLabel>unmodifiableList(labels);
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return GitHub.parseDate(updated_at);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getClosedAt() {
|
public Date getClosedAt() {
|
||||||
@@ -240,7 +226,15 @@ public class GHIssue {
|
|||||||
public GHUser getUser() {
|
public GHUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports who has closed the issue.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Note that GitHub doesn't always seem to report this information
|
||||||
|
* even for an issue that's already closed. See
|
||||||
|
* https://github.com/kohsuke/github-api/issues/60.
|
||||||
|
*/
|
||||||
public GHUser getClosedBy() {
|
public GHUser getClosedBy() {
|
||||||
if(!"closed".equals(state)) return null;
|
if(!"closed".equals(state)) return null;
|
||||||
if(closed_by != null) return closed_by;
|
if(closed_by != null) return closed_by;
|
||||||
@@ -253,10 +247,17 @@ public class GHIssue {
|
|||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns non-null if this issue is a shadow of a pull request.
|
||||||
|
*/
|
||||||
public PullRequest getPullRequest() {
|
public PullRequest getPullRequest() {
|
||||||
return pull_request;
|
return pull_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPullRequest() {
|
||||||
|
return pull_request!=null;
|
||||||
|
}
|
||||||
|
|
||||||
public GHMilestone getMilestone() {
|
public GHMilestone getMilestone() {
|
||||||
return milestone;
|
return milestone;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ import java.util.Date;
|
|||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHIssueComment {
|
public class GHIssueComment extends GHObject {
|
||||||
GHIssue owner;
|
GHIssue owner;
|
||||||
|
|
||||||
private String body, gravatar_id, created_at, updated_at;
|
private String body, gravatar_id;
|
||||||
private URL url;
|
|
||||||
private int id;
|
|
||||||
private GHUser user;
|
private GHUser user;
|
||||||
|
|
||||||
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
||||||
@@ -59,22 +57,6 @@ public class GHIssueComment {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getUpdatedAt() {
|
|
||||||
return GitHub.parseDate(updated_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ID of the user who posted this comment.
|
* Gets the ID of the user who posted this comment.
|
||||||
*/
|
*/
|
||||||
|
|||||||
85
src/main/java/org/kohsuke/github/GHIssueSearchBuilder.java
Normal file
85
src/main/java/org/kohsuke/github/GHIssueSearchBuilder.java
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search issues.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GitHub#searchIssues()
|
||||||
|
*/
|
||||||
|
public class GHIssueSearchBuilder {
|
||||||
|
private final GitHub root;
|
||||||
|
private final Requester req;
|
||||||
|
private final List<String> terms = new ArrayList<String>();
|
||||||
|
|
||||||
|
/*package*/ GHIssueSearchBuilder(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
req = root.retrieve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search terms.
|
||||||
|
*/
|
||||||
|
public GHIssueSearchBuilder q(String term) {
|
||||||
|
terms.add(term);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueSearchBuilder mentions(GHUser u) {
|
||||||
|
return mentions(u.getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueSearchBuilder mentions(String login) {
|
||||||
|
return q("mentions:"+login);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueSearchBuilder isOpen() {
|
||||||
|
return q("is:open");
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueSearchBuilder isClosed() {
|
||||||
|
return q("is:closed");
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueSearchBuilder isMerged() {
|
||||||
|
return q("is:merged");
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueSearchBuilder sort(Sort sort) {
|
||||||
|
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Sort { COMMENTS, CREATED, UPDATED }
|
||||||
|
|
||||||
|
private static class IssueSearchResult extends SearchResult<GHIssue> {
|
||||||
|
private GHIssue[] items;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GHIssue[] getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up the issues with the criteria built so far.
|
||||||
|
*/
|
||||||
|
public PagedSearchIterable<GHIssue> list() {
|
||||||
|
return new PagedSearchIterable<GHIssue>() {
|
||||||
|
public PagedIterator<GHIssue> iterator() {
|
||||||
|
req.set("q", StringUtils.join(terms," "));
|
||||||
|
return new PagedIterator<GHIssue>(adapt(req.asIterator("/search/issues", IssueSearchResult.class))) {
|
||||||
|
protected void wrapUp(GHIssue[] page) {
|
||||||
|
for (GHIssue c : page)
|
||||||
|
c.wrap(root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/main/java/org/kohsuke/github/GHLabel.java
Normal file
37
src/main/java/org/kohsuke/github/GHLabel.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHIssue#getLabels()
|
||||||
|
* @see GHRepository#listLabels()
|
||||||
|
*/
|
||||||
|
public class GHLabel {
|
||||||
|
private String url, name, color;
|
||||||
|
private GHRepository repo;
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color code without leading '#', such as 'f29513'
|
||||||
|
*/
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ GHLabel wrapUp(GHRepository repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() throws IOException {
|
||||||
|
repo.root.retrieve().method("DELETE").to(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,12 +9,12 @@ import java.util.Locale;
|
|||||||
* @author Yusuke Kokubo
|
* @author Yusuke Kokubo
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GHMilestone {
|
public class GHMilestone extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
GHUser creator;
|
GHUser creator;
|
||||||
private String state, due_on, title, url, created_at, description;
|
private String state, due_on, title, description;
|
||||||
private int closed_issues, open_issues, number;
|
private int closed_issues, open_issues, number;
|
||||||
|
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
@@ -38,14 +38,6 @@ public class GHMilestone {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/main/java/org/kohsuke/github/GHObject.java
Normal file
63
src/main/java/org/kohsuke/github/GHObject.java
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Most (all?) domain objects in GitHub seems to have these 4 properties.
|
||||||
|
*/
|
||||||
|
public abstract class GHObject {
|
||||||
|
protected String url;
|
||||||
|
protected int id;
|
||||||
|
protected String created_at;
|
||||||
|
protected String updated_at;
|
||||||
|
|
||||||
|
/*package*/ GHObject() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When was this resource created?
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value=String.class, adapterMethod="createdAtStr")
|
||||||
|
public Date getCreatedAt() throws IOException {
|
||||||
|
return GitHub.parseDate(created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object createdAtStr(Date id, Class type) {
|
||||||
|
return created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API URL of this object.
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value=String.class, adapterMethod="urlToString")
|
||||||
|
public URL getUrl() {
|
||||||
|
return GitHub.parseURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When was this resource last updated?
|
||||||
|
*/
|
||||||
|
public Date getUpdatedAt() throws IOException {
|
||||||
|
return GitHub.parseDate(updated_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique ID number of this resource.
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value=String.class, adapterMethod="intToString")
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object intToString(int id, Class type) {
|
||||||
|
return String.valueOf(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object urlToString(URL url, Class type) {
|
||||||
|
return url==null ? null : url.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -14,15 +15,14 @@ import java.util.TreeMap;
|
|||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public abstract class GHPerson {
|
public abstract class GHPerson extends GHObject {
|
||||||
/*package almost final*/ GitHub root;
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
// core data fields that exist even for "small" user data (such as the user info in pull request)
|
// core data fields that exist even for "small" user data (such as the user info in pull request)
|
||||||
protected String login, avatar_url, url, gravatar_id;
|
protected String login, avatar_url, gravatar_id;
|
||||||
protected int id;
|
|
||||||
|
|
||||||
// other fields (that only show up in full data)
|
// other fields (that only show up in full data)
|
||||||
protected String location,blog,email,name,created_at,company;
|
protected String location,blog,email,name,company;
|
||||||
protected String html_url;
|
protected String html_url;
|
||||||
protected int followers,following,public_repos,public_gists;
|
protected int followers,following,public_repos,public_gists;
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ public abstract class GHPerson {
|
|||||||
*
|
*
|
||||||
* Depending on the original API call where this object is created, it may not contain everything.
|
* Depending on the original API call where this object is created, it may not contain everything.
|
||||||
*/
|
*/
|
||||||
protected void populate() throws IOException {
|
protected synchronized void populate() throws IOException {
|
||||||
if (created_at!=null) return; // already populated
|
if (created_at!=null) return; // already populated
|
||||||
|
|
||||||
root.retrieve().to(url, this);
|
root.retrieve().to(url, this);
|
||||||
@@ -196,9 +196,14 @@ public abstract class GHPerson {
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatedAt() throws IOException {
|
public Date getCreatedAt() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return created_at;
|
return super.getCreatedAt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedAt() throws IOException {
|
||||||
|
populate();
|
||||||
|
return super.getCreatedAt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,13 +241,6 @@ public abstract class GHPerson {
|
|||||||
return following;
|
return following;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* What appears to be a GitHub internal unique number that identifies this user.
|
|
||||||
*/
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFollowersCount() throws IOException {
|
public int getFollowersCount() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return followers;
|
return followers;
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Date getIssueUpdatedAt() {
|
public Date getIssueUpdatedAt() throws IOException {
|
||||||
return super.getUpdatedAt();
|
return super.getUpdatedAt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Label> getLabels() throws IOException {
|
public Collection<GHLabel> getLabels() throws IOException {
|
||||||
fetchIssue();
|
fetchIssue();
|
||||||
return super.getLabels();
|
return super.getLabels();
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
private void populate() throws IOException {
|
private void populate() throws IOException {
|
||||||
if (merged_by!=null) return; // already populated
|
if (merged_by!=null) return; // already populated
|
||||||
|
|
||||||
root.retrieve().to(url, this);
|
root.retrieve().to(url, this).wrapUp(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,22 +15,19 @@ import static java.lang.String.format;
|
|||||||
* @see GHRepository#getReleases()
|
* @see GHRepository#getReleases()
|
||||||
* @see GHRepository#createRelease(String)
|
* @see GHRepository#createRelease(String)
|
||||||
*/
|
*/
|
||||||
public class GHRelease {
|
public class GHRelease extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
private String url;
|
|
||||||
private String html_url;
|
private String html_url;
|
||||||
private String assets_url;
|
private String assets_url;
|
||||||
private String upload_url;
|
private String upload_url;
|
||||||
private long id;
|
|
||||||
private String tag_name;
|
private String tag_name;
|
||||||
private String target_commitish;
|
private String target_commitish;
|
||||||
private String name;
|
private String name;
|
||||||
private String body;
|
private String body;
|
||||||
private boolean draft;
|
private boolean draft;
|
||||||
private boolean prerelease;
|
private boolean prerelease;
|
||||||
private Date created_at;
|
|
||||||
private Date published_at;
|
private Date published_at;
|
||||||
private String tarball_url;
|
private String tarball_url;
|
||||||
private String zipball_url;
|
private String zipball_url;
|
||||||
@@ -39,50 +36,18 @@ public class GHRelease {
|
|||||||
return assets_url;
|
return assets_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAssetsUrl(String assets_url) {
|
|
||||||
this.assets_url = assets_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBody(String body) {
|
|
||||||
this.body = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return created_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedAt(Date created_at) {
|
|
||||||
this.created_at = created_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDraft() {
|
public boolean isDraft() {
|
||||||
return draft;
|
return draft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDraft(boolean draft) {
|
|
||||||
this.draft = draft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHtmlUrl() {
|
public String getHtmlUrl() {
|
||||||
return html_url;
|
return html_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHtmlUrl(String html_url) {
|
|
||||||
this.html_url = html_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -103,74 +68,34 @@ public class GHRelease {
|
|||||||
return prerelease;
|
return prerelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrerelease(boolean prerelease) {
|
|
||||||
this.prerelease = prerelease;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getPublished_at() {
|
public Date getPublished_at() {
|
||||||
return published_at;
|
return published_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublished_at(Date published_at) {
|
|
||||||
this.published_at = published_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoot(GitHub root) {
|
|
||||||
this.root = root;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTagName() {
|
public String getTagName() {
|
||||||
return tag_name;
|
return tag_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTagName(String tag_name) {
|
|
||||||
this.tag_name = tag_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTargetCommitish() {
|
public String getTargetCommitish() {
|
||||||
return target_commitish;
|
return target_commitish;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetCommitish(String target_commitish) {
|
|
||||||
this.target_commitish = target_commitish;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUploadUrl() {
|
public String getUploadUrl() {
|
||||||
return upload_url;
|
return upload_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUploadUrl(String upload_url) {
|
|
||||||
this.upload_url = upload_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZipballUrl() {
|
public String getZipballUrl() {
|
||||||
return zipball_url;
|
return zipball_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZipballUrl(String zipballUrl) {
|
|
||||||
this.zipball_url = zipballUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTarballUrl() {
|
public String getTarballUrl() {
|
||||||
return tarball_url;
|
return tarball_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTarballUrl(String tarballUrl) {
|
|
||||||
this.tarball_url = tarballUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
GHRelease wrap(GHRepository owner) {
|
GHRelease wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
@@ -195,7 +120,7 @@ public class GHRelease {
|
|||||||
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
||||||
Requester builder = new Requester(owner.root);
|
Requester builder = new Requester(owner.root);
|
||||||
|
|
||||||
String url = format("https://uploads.github.com%sreleases/%d/assets?name=%s",
|
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
|
||||||
owner.getApiTailUrl(""), getId(), file.getName());
|
owner.getApiTailUrl(""), getId(), file.getName());
|
||||||
return builder.contentType(contentType)
|
return builder.contentType(contentType)
|
||||||
.with(new FileInputStream(file))
|
.with(new FileInputStream(file))
|
||||||
|
|||||||
@@ -25,28 +25,16 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
import java.io.FileNotFoundException;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.AbstractSet;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A repository on GitHub.
|
* A repository on GitHub.
|
||||||
@@ -54,11 +42,10 @@ import static java.util.Arrays.*;
|
|||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public class GHRepository {
|
public class GHRepository extends GHObject {
|
||||||
/*package almost final*/ GitHub root;
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
private String description, homepage, name, full_name;
|
private String description, homepage, name, full_name;
|
||||||
private String url; // this is the API url
|
|
||||||
private String html_url; // this is the UI
|
private String html_url; // this is the UI
|
||||||
private String git_url, ssh_url, clone_url, svn_url;
|
private String git_url, ssh_url, clone_url, svn_url;
|
||||||
private GHUser owner; // not fully populated. beware.
|
private GHUser owner; // not fully populated. beware.
|
||||||
@@ -66,7 +53,7 @@ public class GHRepository {
|
|||||||
@JsonProperty("private")
|
@JsonProperty("private")
|
||||||
private boolean _private;
|
private boolean _private;
|
||||||
private int watchers,forks,open_issues,size,network_count,subscribers_count;
|
private int watchers,forks,open_issues,size,network_count,subscribers_count;
|
||||||
private String created_at, pushed_at;
|
private String pushed_at;
|
||||||
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
||||||
|
|
||||||
private String default_branch,language;
|
private String default_branch,language;
|
||||||
@@ -74,6 +61,59 @@ public class GHRepository {
|
|||||||
|
|
||||||
private GHRepoPermission permissions;
|
private GHRepoPermission permissions;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHDeploymentStatus[] page) {
|
||||||
|
for (GHDeploymentStatus c : page)
|
||||||
|
c.wrap(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedIterable<GHDeployment> listDeployments(String sha,String ref,String task,String environment){
|
||||||
|
List<String> params = Arrays.asList(getParam("sha", sha), getParam("ref", ref), getParam("task", task), getParam("environment", environment));
|
||||||
|
final String deploymentsUrl = getApiTailUrl("deployments") + "?"+ join(params,"&");
|
||||||
|
return new PagedIterable<GHDeployment>() {
|
||||||
|
public PagedIterator<GHDeployment> iterator() {
|
||||||
|
return new PagedIterator<GHDeployment>(root.retrieve().asIterator(deploymentsUrl, GHDeployment[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHDeployment[] page) {
|
||||||
|
for (GHDeployment c : page)
|
||||||
|
c.wrap(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String join(List<String> params, String joinStr) {
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
for(String param: params){
|
||||||
|
if(param != null){
|
||||||
|
output.append(param+joinStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
private static class GHRepoPermission {
|
private static class GHRepoPermission {
|
||||||
boolean pull,push,admin;
|
boolean pull,push,admin;
|
||||||
}
|
}
|
||||||
@@ -87,13 +127,6 @@ public class GHRepository {
|
|||||||
return homepage;
|
return homepage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* URL of this repository, like 'http://github.com/kohsuke/jenkins'
|
|
||||||
*/
|
|
||||||
public String getUrl() {
|
|
||||||
return html_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the git:// URL to this repository, such as "git://github.com/kohsuke/jenkins.git"
|
* Gets the git:// URL to this repository, such as "git://github.com/kohsuke/jenkins.git"
|
||||||
* This URL is read-only.
|
* This URL is read-only.
|
||||||
@@ -162,7 +195,7 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHIssue getIssue(int id) throws IOException {
|
public GHIssue getIssue(int id) throws IOException {
|
||||||
return root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues/" + id, GHIssue.class).wrap(this);
|
return root.retrieve().to(getApiTailUrl("issues/" + id), GHIssue.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHIssueBuilder createIssue(String title) {
|
public GHIssueBuilder createIssue(String title) {
|
||||||
@@ -175,8 +208,8 @@ public class GHRepository {
|
|||||||
|
|
||||||
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
|
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
|
||||||
return Arrays.asList(GHIssue.wrap(root.retrieve()
|
return Arrays.asList(GHIssue.wrap(root.retrieve()
|
||||||
.to(String.format("/repos/%s/%s/issues?state=%s&milestone=%s", owner.login, name,
|
.to(getApiTailUrl(String.format("issues?state=%s&milestone=%s",
|
||||||
state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber()),
|
state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber())),
|
||||||
GHIssue[].class
|
GHIssue[].class
|
||||||
), this));
|
), this));
|
||||||
}
|
}
|
||||||
@@ -252,7 +285,7 @@ public class GHRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getOwnerName() {
|
public String getOwnerName() {
|
||||||
return owner.login;
|
return owner.login;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,10 +338,6 @@ public class GHRepository {
|
|||||||
return GitHub.parseDate(pushed_at);
|
return GitHub.parseDate(pushed_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return GitHub.parseDate(created_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the primary branch you'll configure in the "Admin > Options" config page.
|
* Returns the primary branch you'll configure in the "Admin > Options" config page.
|
||||||
*
|
*
|
||||||
@@ -342,7 +371,7 @@ public class GHRepository {
|
|||||||
return new PagedIterable<GHUser>() {
|
return new PagedIterable<GHUser>() {
|
||||||
public PagedIterator<GHUser> iterator() {
|
public PagedIterator<GHUser> iterator() {
|
||||||
|
|
||||||
return new PagedIterator<GHUser>(root.retrieve().asIterator("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class)) {
|
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("collaborators"), GHUser[].class)) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHUser[] users) {
|
protected void wrapUp(GHUser[] users) {
|
||||||
@@ -363,7 +392,7 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public Set<String> getCollaboratorNames() throws IOException {
|
public Set<String> getCollaboratorNames() throws IOException {
|
||||||
Set<String> r = new HashSet<String>();
|
Set<String> r = new HashSet<String>();
|
||||||
for (GHUser u : GHUser.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class),root))
|
for (GHUser u : GHUser.wrap(root.retrieve().to(getApiTailUrl("collaborators"), GHUser[].class),root))
|
||||||
r.add(u.login);
|
r.add(u.login);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -372,7 +401,7 @@ public class GHRepository {
|
|||||||
* If this repository belongs to an organization, return a set of teams.
|
* If this repository belongs to an organization, return a set of teams.
|
||||||
*/
|
*/
|
||||||
public Set<GHTeam> getTeams() throws IOException {
|
public Set<GHTeam> getTeams() throws IOException {
|
||||||
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(root.retrieve().to("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login)))));
|
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(root.retrieve().to(getApiTailUrl("teams"), GHTeam[].class), root.getOrganization(owner.login)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCollaborators(GHUser... users) throws IOException {
|
public void addCollaborators(GHUser... users) throws IOException {
|
||||||
@@ -394,7 +423,7 @@ public class GHRepository {
|
|||||||
private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
|
private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
|
||||||
verifyMine();
|
verifyMine();
|
||||||
for (GHUser user : users) {
|
for (GHUser user : users) {
|
||||||
new Requester(root).method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
|
new Requester(root).method(method).to(getApiTailUrl("collaborators/" + user.getLogin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,14 +431,14 @@ public class GHRepository {
|
|||||||
Map<String, String> config = new HashMap<String, String>();
|
Map<String, String> config = new HashMap<String, String>();
|
||||||
config.put("address", address);
|
config.put("address", address);
|
||||||
new Requester(root).method("POST").with("name", "email").with("config", config).with("active", "true")
|
new Requester(root).method("POST").with("name", "email").with("config", config).with("active", "true")
|
||||||
.to(String.format("/repos/%s/%s/hooks", owner.login, name));
|
.to(getApiTailUrl("hooks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, String value) throws IOException {
|
private void edit(String key, String value) throws IOException {
|
||||||
Requester requester = new Requester(root);
|
Requester requester = new Requester(root);
|
||||||
if (!key.equals("name"))
|
if (!key.equals("name"))
|
||||||
requester.with("name", name); // even when we don't change the name, we need to send it in
|
requester.with("name", name); // even when we don't change the name, we need to send it in
|
||||||
requester.with(key, value).method("PATCH").to("/repos/" + owner.login + "/" + name);
|
requester.with(key, value).method("PATCH").to(getApiTailUrl(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -450,7 +479,7 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
try {
|
try {
|
||||||
new Requester(root).method("DELETE").to("/repos/" + owner.login + "/" + name);
|
new Requester(root).method("DELETE").to(getApiTailUrl(""));
|
||||||
} catch (FileNotFoundException x) {
|
} catch (FileNotFoundException x) {
|
||||||
throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + owner.login + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x);
|
throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + owner.login + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x);
|
||||||
}
|
}
|
||||||
@@ -463,7 +492,7 @@ public class GHRepository {
|
|||||||
* Newly forked repository that belong to you.
|
* Newly forked repository that belong to you.
|
||||||
*/
|
*/
|
||||||
public GHRepository fork() throws IOException {
|
public GHRepository fork() throws IOException {
|
||||||
return new Requester(root).method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
|
return new Requester(root).method("POST").to(getApiTailUrl("forks"), GHRepository.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -473,7 +502,7 @@ public class GHRepository {
|
|||||||
* Newly forked repository that belong to you.
|
* Newly forked repository that belong to you.
|
||||||
*/
|
*/
|
||||||
public GHRepository forkTo(GHOrganization org) throws IOException {
|
public GHRepository forkTo(GHOrganization org) throws IOException {
|
||||||
new Requester(root).to(String.format("/repos/%s/%s/forks?org=%s", owner.login, name, org.getLogin()));
|
new Requester(root).to(getApiTailUrl("forks?org="+org.getLogin()));
|
||||||
|
|
||||||
// this API is asynchronous. we need to wait for a bit
|
// this API is asynchronous. we need to wait for a bit
|
||||||
for (int i=0; i<10; i++) {
|
for (int i=0; i<10; i++) {
|
||||||
@@ -492,7 +521,7 @@ public class GHRepository {
|
|||||||
* Retrieves a specified pull request.
|
* Retrieves a specified pull request.
|
||||||
*/
|
*/
|
||||||
public GHPullRequest getPullRequest(int i) throws IOException {
|
public GHPullRequest getPullRequest(int i) throws IOException {
|
||||||
return root.retrieve().to("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this);
|
return root.retrieve().to(getApiTailUrl("pulls/" + i), GHPullRequest.class).wrapUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -510,7 +539,7 @@ public class GHRepository {
|
|||||||
public PagedIterable<GHPullRequest> listPullRequests(final GHIssueState state) {
|
public PagedIterable<GHPullRequest> listPullRequests(final GHIssueState state) {
|
||||||
return new PagedIterable<GHPullRequest>() {
|
return new PagedIterable<GHPullRequest>() {
|
||||||
public PagedIterator<GHPullRequest> iterator() {
|
public PagedIterator<GHPullRequest> iterator() {
|
||||||
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(String.format("/repos/%s/%s/pulls?state=%s", owner.login, name, state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
|
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(getApiTailUrl("pulls?state="+state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHPullRequest[] page) {
|
protected void wrapUp(GHPullRequest[] page) {
|
||||||
for (GHPullRequest pr : page)
|
for (GHPullRequest pr : page)
|
||||||
@@ -549,14 +578,14 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public List<GHHook> getHooks() throws IOException {
|
public List<GHHook> getHooks() throws IOException {
|
||||||
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(
|
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(
|
||||||
root.retrieve().to(String.format("/repos/%s/%s/hooks", owner.login, name), GHHook[].class)));
|
root.retrieve().to(getApiTailUrl("hooks"), GHHook[].class)));
|
||||||
for (GHHook h : list)
|
for (GHHook h : list)
|
||||||
h.wrap(this);
|
h.wrap(this);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHHook getHook(int id) throws IOException {
|
public GHHook getHook(int id) throws IOException {
|
||||||
return root.retrieve().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
|
return root.retrieve().to(getApiTailUrl("hooks/" + id), GHHook.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -568,7 +597,7 @@ public class GHRepository {
|
|||||||
* @throws IOException on failure communicating with GitHub
|
* @throws IOException on failure communicating with GitHub
|
||||||
*/
|
*/
|
||||||
public GHCompare getCompare(String id1, String id2) throws IOException {
|
public GHCompare getCompare(String id1, String id2) throws IOException {
|
||||||
GHCompare compare = root.retrieve().to(String.format("/repos/%s/%s/compare/%s...%s", owner.login, name, id1, id2), GHCompare.class);
|
GHCompare compare = root.retrieve().to(getApiTailUrl(String.format("compare/%s...%s", id1, id2)), GHCompare.class);
|
||||||
return compare.wrap(this);
|
return compare.wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,6 +760,54 @@ public class GHRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists labels in this repository.
|
||||||
|
*
|
||||||
|
* https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHLabel> listLabels() throws IOException {
|
||||||
|
return new PagedIterable<GHLabel>() {
|
||||||
|
public PagedIterator<GHLabel> iterator() {
|
||||||
|
return new PagedIterator<GHLabel>(root.retrieve().asIterator(getApiTailUrl("labels"), GHLabel[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHLabel[] page) {
|
||||||
|
for (GHLabel c : page)
|
||||||
|
c.wrapUp(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHLabel getLabel(String name) throws IOException {
|
||||||
|
return root.retrieve().to(getApiTailUrl("labels/"+name), GHLabel.class).wrapUp(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHLabel createLabel(String name, String color) throws IOException {
|
||||||
|
return root.retrieve().method("POST")
|
||||||
|
.with("name",name)
|
||||||
|
.with("color",color)
|
||||||
|
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all the subscribers (aka watchers.)
|
||||||
|
*
|
||||||
|
* https://developer.github.com/v3/activity/watching/
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHUser> listSubscribers() {
|
||||||
|
return new PagedIterable<GHUser>() {
|
||||||
|
public PagedIterator<GHUser> iterator() {
|
||||||
|
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("subscribers"), GHUser[].class)) {
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
for (GHUser c : page)
|
||||||
|
c.wrapUp(root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* See https://api.github.com/hooks for possible names and their configuration scheme.
|
* See https://api.github.com/hooks for possible names and their configuration scheme.
|
||||||
@@ -909,7 +986,7 @@ public class GHRepository {
|
|||||||
|
|
||||||
public GHContent getFileContent(String path, String ref) throws IOException {
|
public GHContent getFileContent(String path, String ref) throws IOException {
|
||||||
Requester requester = root.retrieve();
|
Requester requester = root.retrieve();
|
||||||
String target = String.format("/repos/%s/%s/contents/%s", owner.login, name, path);
|
String target = getApiTailUrl("contents/" + path);
|
||||||
|
|
||||||
if (ref != null)
|
if (ref != null)
|
||||||
target = target + "?ref=" + ref;
|
target = target + "?ref=" + ref;
|
||||||
@@ -923,7 +1000,7 @@ public class GHRepository {
|
|||||||
|
|
||||||
public List<GHContent> getDirectoryContent(String path, String ref) throws IOException {
|
public List<GHContent> getDirectoryContent(String path, String ref) throws IOException {
|
||||||
Requester requester = root.retrieve();
|
Requester requester = root.retrieve();
|
||||||
String target = String.format("/repos/%s/%s/contents/%s", owner.login, name, path);
|
String target = getApiTailUrl("contents/" + path);
|
||||||
|
|
||||||
if (ref != null)
|
if (ref != null)
|
||||||
target = target + "?ref=" + ref;
|
target = target + "?ref=" + ref;
|
||||||
@@ -935,19 +1012,31 @@ public class GHRepository {
|
|||||||
return Arrays.asList(files);
|
return Arrays.asList(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHContent getReadme() throws Exception {
|
/**
|
||||||
return getFileContent("readme");
|
* https://developer.github.com/v3/repos/contents/#get-the-readme
|
||||||
|
*/
|
||||||
|
public GHContent getReadme() throws IOException {
|
||||||
|
Requester requester = root.retrieve();
|
||||||
|
return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException {
|
public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException {
|
||||||
return createContent(content, commitMessage, path, null);
|
return createContent(content.getBytes(), commitMessage, path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException {
|
public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException {
|
||||||
|
return createContent(content.getBytes(), commitMessage, path, branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException {
|
||||||
|
return createContent(contentBytes, commitMessage, path, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch) throws IOException {
|
||||||
Requester requester = new Requester(root)
|
Requester requester = new Requester(root)
|
||||||
.with("path", path)
|
.with("path", path)
|
||||||
.with("message", commitMessage)
|
.with("message", commitMessage)
|
||||||
.with("content", DatatypeConverter.printBase64Binary(content.getBytes()))
|
.with("content", DatatypeConverter.printBase64Binary(contentBytes))
|
||||||
.method("PUT");
|
.method("PUT");
|
||||||
|
|
||||||
if (branch != null) {
|
if (branch != null) {
|
||||||
@@ -975,11 +1064,56 @@ public class GHRepository {
|
|||||||
|
|
||||||
public List<GHDeployKey> getDeployKeys() throws IOException{
|
public List<GHDeployKey> getDeployKeys() throws IOException{
|
||||||
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(
|
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(
|
||||||
root.retrieve().to(String.format("/repos/%s/%s/keys", owner.login, name), GHDeployKey[].class)));
|
root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class)));
|
||||||
for (GHDeployKey h : list)
|
for (GHDeployKey h : list)
|
||||||
h.wrap(this);
|
h.wrap(this);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to this repository to get notifications.
|
||||||
|
*/
|
||||||
|
public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException {
|
||||||
|
return new Requester(root)
|
||||||
|
.with("subscribed", subscribed)
|
||||||
|
.with("ignored", ignored)
|
||||||
|
.method("PUT").to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current subscription.
|
||||||
|
*
|
||||||
|
* @return null if no subscription exists.
|
||||||
|
*/
|
||||||
|
public GHSubscription getSubscription() throws IOException {
|
||||||
|
try {
|
||||||
|
return new Requester(root).to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedIterable<Contributor> listContributors() throws IOException {
|
||||||
|
return new PagedIterable<Contributor>() {
|
||||||
|
public PagedIterator<Contributor> iterator() {
|
||||||
|
return new PagedIterator<Contributor>(root.retrieve().asIterator(getApiTailUrl("contributors"), Contributor[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(Contributor[] page) {
|
||||||
|
for (Contributor c : page)
|
||||||
|
c.wrapUp(root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Contributor extends GHUser {
|
||||||
|
private int contributions;
|
||||||
|
|
||||||
|
public int getContributions() {
|
||||||
|
return contributions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1004,6 +1138,7 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getApiTailUrl(String tail) {
|
String getApiTailUrl(String tail) {
|
||||||
return "/repos/" + owner.login + "/" + name +'/'+tail;
|
if (tail.length()>0 && !tail.startsWith("/")) tail='/'+tail;
|
||||||
|
return "/repos/" + owner.login + "/" + name +tail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
src/main/java/org/kohsuke/github/GHSubscription.java
Normal file
62
src/main/java/org/kohsuke/github/GHSubscription.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents your subscribing to a repository.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class GHSubscription {
|
||||||
|
private String created_at, url, repository_url, reason;
|
||||||
|
private boolean subscribed, ignored;
|
||||||
|
|
||||||
|
private GitHub root;
|
||||||
|
private GHRepository repo;
|
||||||
|
|
||||||
|
public Date getCreatedAt() {
|
||||||
|
return GitHub.parseDate(created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepositoryUrl() {
|
||||||
|
return repository_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSubscribed() {
|
||||||
|
return subscribed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIgnored() {
|
||||||
|
return ignored;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRepository getRepository() {
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes this subscription.
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
GHSubscription wrapUp(GHRepository repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
return wrapUp(repo.root);
|
||||||
|
}
|
||||||
|
|
||||||
|
GHSubscription wrapUp(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ public class GHTag {
|
|||||||
/*package*/ GHTag wrap(GHRepository owner) {
|
/*package*/ GHTag wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
|
if (commit!=null)
|
||||||
|
commit.wrapUp(owner);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
@@ -48,13 +47,26 @@ public class GHTeam {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the current members.
|
* Retrieves the current members.
|
||||||
*/
|
*/
|
||||||
public Set<GHUser> getMembers() throws IOException {
|
public PagedIterable<GHUser> listMembers() throws IOException {
|
||||||
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().to(api("/members"), GHUser[].class), org.root)));
|
return new PagedIterable<GHUser>() {
|
||||||
|
public PagedIterator<GHUser> iterator() {
|
||||||
|
return new PagedIterator<GHUser>(org.root.retrieve().asIterator(api("/members"), GHUser[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
GHUser.wrap(page, org.root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<GHUser> getMembers() throws IOException {
|
||||||
|
return Collections.unmodifiableSet(listMembers().asSet());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this team has the specified user as a member.
|
* Checks if this team has the specified user as a member.
|
||||||
*/
|
*/
|
||||||
@@ -68,14 +80,27 @@ public class GHTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,GHRepository> getRepositories() throws IOException {
|
public Map<String,GHRepository> getRepositories() throws IOException {
|
||||||
GHRepository[] repos = org.root.retrieve().to(api("/repos"), GHRepository[].class);
|
|
||||||
Map<String,GHRepository> m = new TreeMap<String, GHRepository>();
|
Map<String,GHRepository> m = new TreeMap<String, GHRepository>();
|
||||||
for (GHRepository r : repos) {
|
for (GHRepository r : listRepositories()) {
|
||||||
m.put(r.getName(),r.wrap(org.root));
|
m.put(r.getName(), r);
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PagedIterable<GHRepository> listRepositories() {
|
||||||
|
return new PagedIterable<GHRepository>() {
|
||||||
|
public PagedIterator<GHRepository> iterator() {
|
||||||
|
return new PagedIterator<GHRepository>(org.root.retrieve().asIterator(api("/repos"), GHRepository[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHRepository[] page) {
|
||||||
|
for (GHRepository r : page)
|
||||||
|
r.wrap(org.root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a member to the team.
|
* Adds a member to the team.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -69,6 +69,24 @@ public class GHUser extends GHPerson {
|
|||||||
return new GHPersonSet<GHUser>(Arrays.asList(wrap(followers,root)));
|
return new GHPersonSet<GHUser>(Arrays.asList(wrap(followers,root)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all the subscribed (aka watched) repositories.
|
||||||
|
*
|
||||||
|
* https://developer.github.com/v3/activity/watching/
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHRepository> listSubscriptions() {
|
||||||
|
return new PagedIterable<GHRepository>() {
|
||||||
|
public PagedIterator<GHRepository> iterator() {
|
||||||
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("subscriptions"), GHRepository[].class)) {
|
||||||
|
protected void wrapUp(GHRepository[] page) {
|
||||||
|
for (GHRepository c : page)
|
||||||
|
c.wrap(root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this user belongs to the specified organization.
|
* Returns true if this user belongs to the specified organization.
|
||||||
*/
|
*/
|
||||||
@@ -162,4 +180,9 @@ public class GHUser extends GHPerson {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getApiTailUrl(String tail) {
|
||||||
|
if (tail.length()>0 && !tail.startsWith("/")) tail='/'+tail;
|
||||||
|
return "/users/" + login + tail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import java.util.Collection;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -53,6 +54,12 @@ import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
|||||||
/**
|
/**
|
||||||
* Root of the GitHub API.
|
* Root of the GitHub API.
|
||||||
*
|
*
|
||||||
|
* <h2>Thread safety</h2>
|
||||||
|
* <p>
|
||||||
|
* This library aims to be safe for use by multiple threads concurrently, although
|
||||||
|
* the library itself makes no attempt to control/serialize potentially conflicting
|
||||||
|
* operations to GitHub, such as updating & deleting a repository at the same time.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GitHub {
|
public class GitHub {
|
||||||
@@ -63,8 +70,8 @@ public class GitHub {
|
|||||||
*/
|
*/
|
||||||
/*package*/ final String encodedAuthorization;
|
/*package*/ final String encodedAuthorization;
|
||||||
|
|
||||||
private final Map<String,GHUser> users = new HashMap<String, GHUser>();
|
private final Map<String,GHUser> users = new Hashtable<String, GHUser>();
|
||||||
private final Map<String,GHOrganization> orgs = new HashMap<String, GHOrganization>();
|
private final Map<String,GHOrganization> orgs = new Hashtable<String, GHOrganization>();
|
||||||
|
|
||||||
private final String apiUrl;
|
private final String apiUrl;
|
||||||
|
|
||||||
@@ -424,6 +431,14 @@ public class GitHub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search issues.
|
||||||
|
*/
|
||||||
|
public GHIssueSearchBuilder searchIssues() {
|
||||||
|
return new GHIssueSearchBuilder(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*package*/ static URL parseURL(String s) {
|
/*package*/ static URL parseURL(String s) {
|
||||||
try {
|
try {
|
||||||
return s==null ? null : new URL(s);
|
return s==null ? null : new URL(s);
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@@ -153,6 +156,19 @@ public class GitHubBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures {@linkplain #withConnector(HttpConnector) connector}
|
||||||
|
* that uses HTTP library in JRE but use a specific proxy, instead of
|
||||||
|
* the system default one.
|
||||||
|
*/
|
||||||
|
public GitHubBuilder withProxy(final Proxy p) {
|
||||||
|
return withConnector(new HttpConnector() {
|
||||||
|
public HttpURLConnection connect(URL url) throws IOException {
|
||||||
|
return (HttpURLConnection) url.openConnection(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public GitHub build() throws IOException {
|
public GitHub build() throws IOException {
|
||||||
return new GitHub(endpoint, user, oauthToken, password, connector);
|
return new GitHub(endpoint, user, oauthToken, password, connector);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Iterable} that returns {@link PagedIterator}
|
* {@link Iterable} that returns {@link PagedIterator}
|
||||||
@@ -21,4 +23,15 @@ public abstract class PagedIterable<T> implements Iterable<T> {
|
|||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eagerly walk {@link Iterable} and return the result in a set.
|
||||||
|
*/
|
||||||
|
public Set<T> asSet() {
|
||||||
|
LinkedHashSet<T> r = new LinkedHashSet<T>();
|
||||||
|
for(PagedIterator<T> i = iterator(); i.hasNext();) {
|
||||||
|
r.addAll(i.nextPage());
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/main/java/org/kohsuke/github/PagedSearchIterable.java
Normal file
54
src/main/java/org/kohsuke/github/PagedSearchIterable.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link PagedIterable} enhanced to report search result specific information.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public abstract class PagedSearchIterable<T> extends PagedIterable<T> {
|
||||||
|
/**
|
||||||
|
* As soon as we have any result fetched, it's set here so that we can report the total count.
|
||||||
|
*/
|
||||||
|
private SearchResult<T> result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total number of hit, including the results that's not yet fetched.
|
||||||
|
*/
|
||||||
|
public int getTotalCount() {
|
||||||
|
populate();
|
||||||
|
return result.total_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIncomplete() {
|
||||||
|
populate();
|
||||||
|
return result.incomplete_results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populate() {
|
||||||
|
if (result==null)
|
||||||
|
iterator().hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapts {@link Iterator}.
|
||||||
|
*/
|
||||||
|
protected Iterator<T[]> adapt(final Iterator<? extends SearchResult<T>> base) {
|
||||||
|
return new Iterator<T[]>() {
|
||||||
|
public boolean hasNext() {
|
||||||
|
return base.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T[] next() {
|
||||||
|
SearchResult<T> v = base.next();
|
||||||
|
if (result==null) result = v;
|
||||||
|
return v.getItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,6 +134,19 @@ class Requester {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlike {@link #with(String, String)}, overrides the existing value
|
||||||
|
*/
|
||||||
|
public Requester set(String key, Object value) {
|
||||||
|
for (Entry e : args) {
|
||||||
|
if (e.key.equals(key)) {
|
||||||
|
e.value = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _with(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
public Requester method(String method) {
|
public Requester method(String method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
13
src/main/java/org/kohsuke/github/SearchResult.java
Normal file
13
src/main/java/org/kohsuke/github/SearchResult.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the result of a search
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
abstract class SearchResult<T> {
|
||||||
|
int total_count;
|
||||||
|
boolean incomplete_results;
|
||||||
|
|
||||||
|
public abstract T[] getItems();
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<item name="Introduction" href="/index.html"/>
|
<item name="Introduction" href="/index.html"/>
|
||||||
<item name="Download" href="http://mvnrepository.com/artifact/${project.groupId}/${project.artifactId}"/>
|
<item name="Download" href="http://mvnrepository.com/artifact/${project.groupId}/${project.artifactId}"/>
|
||||||
<item name="Source code" href="https://github.com/kohsuke/${project.artifactId}"/>
|
<item name="Source code" href="https://github.com/kohsuke/${project.artifactId}"/>
|
||||||
|
<item name="Mailing List" href="https://groups.google.com/forum/#!forum/github-api"/>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
||||||
<menu name="References">
|
<menu name="References">
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
import org.kohsuke.github.GHOrganization;
|
import org.kohsuke.github.GHRepository;
|
||||||
import org.kohsuke.github.GHTeam;
|
|
||||||
import org.kohsuke.github.GitHub;
|
import org.kohsuke.github.GitHub;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class Foo {
|
public class Foo {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
GHOrganization org = GitHub.connect().getOrganization("jenkinsci");
|
Collection<GHRepository> lst = GitHub.connect().getUser("kohsuke").getRepositories().values();
|
||||||
Map<String, GHTeam> teams = org.getTeams();
|
for (GHRepository r : lst) {
|
||||||
System.out.println(teams.size());
|
System.out.println(r.getName());
|
||||||
|
|
||||||
int sz = 0;
|
|
||||||
for (GHTeam t : org.listTeams()) {
|
|
||||||
sz++;
|
|
||||||
}
|
}
|
||||||
System.out.println(sz);
|
System.out.println(lst.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
141
src/test/java/org/kohsuke/github/AppTest.java
Normal file → Executable file
141
src/test/java/org/kohsuke/github/AppTest.java
Normal file → Executable file
@@ -1,22 +1,18 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.google.common.base.Predicate;
|
||||||
import java.net.URL;
|
import com.google.common.collect.Iterables;
|
||||||
import java.util.ArrayList;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kohsuke.github.GHCommit.File;
|
import org.kohsuke.github.GHCommit.File;
|
||||||
import org.kohsuke.github.GHOrganization.Permission;
|
import org.kohsuke.github.GHOrganization.Permission;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import java.io.IOException;
|
||||||
import com.google.common.collect.Iterables;
|
import java.net.URL;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
@@ -82,6 +78,51 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
o.close();
|
o.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDeployment() throws IOException {
|
||||||
|
GHRepository repository = getTestRepository();
|
||||||
|
GHDeployment deployment = repository.createDeployment("master")
|
||||||
|
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
|
||||||
|
.description("question")
|
||||||
|
.create();
|
||||||
|
assertNotNull(deployment.getCreator());
|
||||||
|
assertNotNull(deployment.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListDeployments() throws IOException {
|
||||||
|
GHRepository repository = getTestRepository();
|
||||||
|
GHDeployment deployment = repository.createDeployment("master")
|
||||||
|
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
|
||||||
|
.description("question")
|
||||||
|
.environment("unittest")
|
||||||
|
.create();
|
||||||
|
assertNotNull(deployment.getCreator());
|
||||||
|
assertNotNull(deployment.getId());
|
||||||
|
ArrayList<GHDeployment> deployments = Lists.newArrayList(repository.listDeployments(null, "master", null, "unittest"));
|
||||||
|
assertNotNull(deployments);
|
||||||
|
assertFalse(Iterables.isEmpty(deployments));
|
||||||
|
GHDeployment unitTestDeployment = deployments.get(0);
|
||||||
|
assertEquals("unittest",unitTestDeployment.getEnvironment());
|
||||||
|
assertEquals("master", unitTestDeployment.getRef());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeploymentStatuses() throws IOException {
|
||||||
|
GHRepository repository = getTestRepository();
|
||||||
|
GHDeployment deployment = repository.createDeployment("master")
|
||||||
|
.description("question")
|
||||||
|
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
|
||||||
|
.create();
|
||||||
|
GHDeploymentStatus ghDeploymentStatus = repository.createDeployStatus(deployment.getId(), GHDeploymentState.SUCCESS)
|
||||||
|
.description("success")
|
||||||
|
.targetUrl("http://www.github.com").create();
|
||||||
|
Iterable<GHDeploymentStatus> deploymentStatuses = repository.getDeploymentStatuses(deployment.getId());
|
||||||
|
assertNotNull(deploymentStatuses);
|
||||||
|
assertEquals(1,Iterables.size(deploymentStatuses));
|
||||||
|
assertEquals(ghDeploymentStatus.getId(), Iterables.get(deploymentStatuses, 0).getId());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetIssues() throws Exception {
|
public void testGetIssues() throws Exception {
|
||||||
List<GHIssue> closedIssues = gitHub.getUser("kohsuke").getRepository("github-api").getIssues(GHIssueState.CLOSED);
|
List<GHIssue> closedIssues = gitHub.getUser("kohsuke").getRepository("github-api").getIssues(GHIssueState.CLOSED);
|
||||||
@@ -243,7 +284,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetTeamsForRepo() throws Exception {
|
public void testGetTeamsForRepo() throws Exception {
|
||||||
kohsuke();
|
kohsuke();
|
||||||
assertEquals(1,gitHub.getOrganization("github-api-test-org").getRepository("testGetTeamsForRepo").getTeams().size());
|
assertEquals(1, gitHub.getOrganization("github-api-test-org").getRepository("testGetTeamsForRepo").getTeams().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -266,7 +307,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
assertNotNull(t.getName());
|
assertNotNull(t.getName());
|
||||||
sz++;
|
sz++;
|
||||||
}
|
}
|
||||||
assertTrue(sz<100);
|
assertTrue(sz < 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -458,7 +499,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Map<String, GHRepository> repos = j.getRepositories();
|
Map<String, GHRepository> repos = j.getRepositories();
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.printf("%d repositories in %dms\n",repos.size(),end-start);
|
System.out.printf("%d repositories in %dms\n", repos.size(), end - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -484,7 +525,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
state = lst.get(0);
|
state = lst.get(0);
|
||||||
System.out.println(state);
|
System.out.println(state);
|
||||||
assertEquals("testing!",state.getDescription());
|
assertEquals("testing!",state.getDescription());
|
||||||
assertEquals("http://kohsuke.org/",state.getTargetUrl());
|
assertEquals("http://kohsuke.org/", state.getTargetUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -600,6 +641,74 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMemberPagenation() throws IOException {
|
||||||
|
Set<GHUser> all = new HashSet<GHUser>();
|
||||||
|
for (GHUser u : gitHub.getOrganization("github-api-test-org").getTeamByName("Core Developers").listMembers()) {
|
||||||
|
System.out.println(u.getLogin());
|
||||||
|
all.add(u);
|
||||||
|
}
|
||||||
|
assertFalse(all.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIssueSearch() throws IOException {
|
||||||
|
PagedSearchIterable<GHIssue> r = gitHub.searchIssues().mentions("kohsuke").isOpen().list();
|
||||||
|
for (GHIssue i : r) {
|
||||||
|
System.out.println(i.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // issue #99
|
||||||
|
public void testReadme() throws IOException {
|
||||||
|
GHContent readme = gitHub.getRepository("github-api-test-org/test-readme").getReadme();
|
||||||
|
assertEquals(readme.getName(),"README.md");
|
||||||
|
assertEquals(readme.getContent(),"This is a markdown readme.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRepoLabel() throws IOException {
|
||||||
|
GHRepository r = gitHub.getRepository("github-api-test-org/test-labels");
|
||||||
|
List<GHLabel> lst = r.listLabels().asList();
|
||||||
|
for (GHLabel l : lst) {
|
||||||
|
System.out.println(l.getName());
|
||||||
|
}
|
||||||
|
assertTrue(lst.size() > 5);
|
||||||
|
GHLabel e = r.getLabel("enhancement");
|
||||||
|
assertEquals("enhancement",e.getName());
|
||||||
|
assertNotNull(e.getUrl());
|
||||||
|
assertTrue(Pattern.matches("[0-9a-fA-F]{6}",e.getColor()));
|
||||||
|
|
||||||
|
{// CRUD
|
||||||
|
GHLabel t = r.createLabel("test", "123456");
|
||||||
|
GHLabel t2 = r.getLabel("test");
|
||||||
|
assertEquals(t.getName(), t2.getName());
|
||||||
|
assertEquals(t.getColor(), "123456");
|
||||||
|
assertEquals(t.getColor(), t2.getColor());
|
||||||
|
assertEquals(t.getUrl(), t2.getUrl());
|
||||||
|
t.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSubscribers() throws IOException {
|
||||||
|
boolean kohsuke = false;
|
||||||
|
GHRepository mr = gitHub.getRepository("kohsuke/github-api");
|
||||||
|
for (GHUser u : mr.listSubscribers()) {
|
||||||
|
System.out.println(u.getLogin());
|
||||||
|
kohsuke |= u.getLogin().equals("kohsuke");
|
||||||
|
}
|
||||||
|
assertTrue(kohsuke);
|
||||||
|
System.out.println("---");
|
||||||
|
|
||||||
|
boolean githubApi = false;
|
||||||
|
for (GHRepository r : gitHub.getUser("kohsuke").listRepositories()) {
|
||||||
|
System.out.println(r.getName());
|
||||||
|
githubApi |= r.equals(mr);
|
||||||
|
}
|
||||||
|
assertTrue(githubApi);
|
||||||
|
}
|
||||||
|
|
||||||
private void kohsuke() {
|
private void kohsuke() {
|
||||||
String login = getUser().getLogin();
|
String login = getUser().getLogin();
|
||||||
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
||||||
|
|||||||
16
src/test/java/org/kohsuke/github/CommitTest.java
Normal file
16
src/test/java/org/kohsuke/github/CommitTest.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class CommitTest extends AbstractGitHubApiTestBase {
|
||||||
|
@Test // issue 152
|
||||||
|
public void lastStatus() throws IOException {
|
||||||
|
GHTag t = gitHub.getRepository("stapler/stapler").listTags().iterator().next();
|
||||||
|
t.getCommit().getLastStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
|||||||
String label = rnd.next();
|
String label = rnd.next();
|
||||||
p.setLabels(label);
|
p.setLabels(label);
|
||||||
|
|
||||||
Collection<GHIssue.Label> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
||||||
assertEquals(1, labels.size());
|
assertEquals(1, labels.size());
|
||||||
assertEquals(label, labels.iterator().next().getName());
|
assertEquals(label, labels.iterator().next().getName());
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,22 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
|||||||
assertEquals(user, getRepository().getPullRequest(p.getNumber()).getAssignee());
|
assertEquals(user, getRepository().getPullRequest(p.getNumber()).getAssignee());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetUser() throws IOException {
|
||||||
|
GHPullRequest p = getRepository().createPullRequest(rnd.next(), "stable", "master", "## test");
|
||||||
|
GHPullRequest prSingle = getRepository().getPullRequest(p.getNumber());
|
||||||
|
assertNotNull(prSingle.getUser().root);
|
||||||
|
prSingle.getMergeable();
|
||||||
|
assertNotNull(prSingle.getUser().root);
|
||||||
|
|
||||||
|
PagedIterable<GHPullRequest> ghPullRequests = getRepository().listPullRequests(GHIssueState.OPEN);
|
||||||
|
for (GHPullRequest pr : ghPullRequests) {
|
||||||
|
assertNotNull(pr.getUser().root);
|
||||||
|
assertFalse(pr.getMergeable());
|
||||||
|
assertNotNull(pr.getUser().root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() throws Exception {
|
public void cleanUp() throws Exception {
|
||||||
for (GHPullRequest pr : getRepository().getPullRequests(GHIssueState.OPEN)) {
|
for (GHPullRequest pr : getRepository().getPullRequests(GHIssueState.OPEN)) {
|
||||||
|
|||||||
89
src/test/java/org/kohsuke/github/RepositoryMockTest.java
Normal file
89
src/test/java/org/kohsuke/github/RepositoryMockTest.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luciano P. Sabenca (luciano.sabenca [at] movile [com] | lucianosabenca [at] gmail [dot] com
|
||||||
|
*/
|
||||||
|
public class RepositoryMockTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
GitHub mockGitHub;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
Iterator<GHUser[]> iterator;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
GHRepository mockRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void listCollaborators() throws Exception {
|
||||||
|
GHUser user1 = new GHUser();
|
||||||
|
user1.login = "login1";
|
||||||
|
|
||||||
|
GHUser user2 = new GHUser();
|
||||||
|
user2.login = "login2";
|
||||||
|
|
||||||
|
|
||||||
|
when(iterator.hasNext()).thenReturn(true, false, true);
|
||||||
|
when(iterator.next()).thenReturn(new GHUser[]{user1}, new GHUser[]{user2});
|
||||||
|
|
||||||
|
Requester requester = Mockito.mock(Requester.class);
|
||||||
|
when(mockGitHub.retrieve()).thenReturn(requester);
|
||||||
|
|
||||||
|
|
||||||
|
when(requester.asIterator("/repos/*/*/collaborators",
|
||||||
|
GHUser[].class)).thenReturn(iterator, iterator);
|
||||||
|
|
||||||
|
|
||||||
|
PagedIterable<GHUser> pagedIterable = Mockito.mock(PagedIterable.class);
|
||||||
|
when(mockRepository.listCollaborators()).thenReturn(pagedIterable);
|
||||||
|
|
||||||
|
PagedIterator<GHUser> userPagedIterator = new PagedIterator<GHUser>(iterator) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PagedIterator<GHUser> userPagedIterator2 = new PagedIterator<GHUser>(iterator) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
when(pagedIterable.iterator()).thenReturn(userPagedIterator, userPagedIterator2);
|
||||||
|
|
||||||
|
Iterator<GHUser> returnIterator1 = mockRepository.listCollaborators().iterator();
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertTrue(returnIterator1.hasNext());
|
||||||
|
GHUser user = returnIterator1.next();
|
||||||
|
Assert.assertEquals(user, user1);
|
||||||
|
Assert.assertFalse(returnIterator1.hasNext());
|
||||||
|
|
||||||
|
|
||||||
|
Iterator returnIterator2 = mockRepository.listCollaborators().iterator();
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertTrue(returnIterator2.hasNext());
|
||||||
|
user = returnIterator1.next();
|
||||||
|
Assert.assertEquals(user, user2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,91 +1,46 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
import org.kohsuke.github.GHRepository.Contributor;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luciano P. Sabenca (luciano.sabenca [at] movile [com] | lucianosabenca [at] gmail [dot] com
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class RepositoryTest {
|
public class RepositoryTest extends AbstractGitHubApiTestBase {
|
||||||
|
@Test
|
||||||
|
public void subscription() throws Exception {
|
||||||
|
GHRepository r = getRepository();
|
||||||
|
assertNull(r.getSubscription());
|
||||||
|
|
||||||
@Mock
|
GHSubscription s = r.subscribe(true, false);
|
||||||
GitHub mockGitHub;
|
assertEquals(s.getRepository(), r);
|
||||||
|
|
||||||
@Mock
|
s.delete();
|
||||||
Iterator<GHUser[]> iterator;
|
|
||||||
|
|
||||||
@Mock
|
assertNull(r.getSubscription());
|
||||||
GHRepository mockRepository;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listCollaborators() throws Exception {
|
public void listContributors() throws IOException {
|
||||||
GHUser user1 = new GHUser();
|
GHRepository r = gitHub.getOrganization("stapler").getRepository("stapler");
|
||||||
user1.login = "login1";
|
int i=0;
|
||||||
|
boolean kohsuke = false;
|
||||||
|
|
||||||
GHUser user2 = new GHUser();
|
for (Contributor c : r.listContributors()) {
|
||||||
user2.login = "login2";
|
System.out.println(c.getName());
|
||||||
|
assertTrue(c.getContributions()>0);
|
||||||
|
if (c.getLogin().equals("kohsuke"))
|
||||||
when(iterator.hasNext()).thenReturn(true, false, true);
|
kohsuke = true;
|
||||||
when(iterator.next()).thenReturn(new GHUser[]{user1}, new GHUser[]{user2});
|
if (i++ > 5)
|
||||||
|
break;
|
||||||
Requester requester = Mockito.mock(Requester.class);
|
}
|
||||||
when(mockGitHub.retrieve()).thenReturn(requester);
|
|
||||||
|
|
||||||
|
|
||||||
when(requester.asIterator("/repos/*/*/collaborators",
|
|
||||||
GHUser[].class)).thenReturn(iterator, iterator);
|
|
||||||
|
|
||||||
|
|
||||||
PagedIterable<GHUser> pagedIterable = Mockito.mock(PagedIterable.class);
|
|
||||||
when(mockRepository.listCollaborators()).thenReturn(pagedIterable);
|
|
||||||
|
|
||||||
PagedIterator<GHUser> userPagedIterator = new PagedIterator<GHUser>(iterator) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHUser[] page) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
PagedIterator<GHUser> userPagedIterator2 = new PagedIterator<GHUser>(iterator) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHUser[] page) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
when(pagedIterable.iterator()).thenReturn(userPagedIterator, userPagedIterator2);
|
|
||||||
|
|
||||||
Iterator<GHUser> returnIterator1 = mockRepository.listCollaborators().iterator();
|
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(returnIterator1.hasNext());
|
|
||||||
GHUser user = returnIterator1.next();
|
|
||||||
Assert.assertEquals(user, user1);
|
|
||||||
Assert.assertFalse(returnIterator1.hasNext());
|
|
||||||
|
|
||||||
|
|
||||||
Iterator returnIterator2 = mockRepository.listCollaborators().iterator();
|
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(returnIterator2.hasNext());
|
|
||||||
user = returnIterator1.next();
|
|
||||||
Assert.assertEquals(user, user2);
|
|
||||||
|
|
||||||
|
assertTrue(kohsuke);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GHRepository getRepository() throws IOException {
|
||||||
|
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user