mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-12 00:11:22 +00:00
Compare commits
42 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
553df7ac85 | ||
|
|
9648602252 | ||
|
|
63d0d13330 | ||
|
|
ff9b538a49 | ||
|
|
6632da34c0 | ||
|
|
178c9ff4d0 | ||
|
|
bfefeae5c1 | ||
|
|
ebf953cbc4 | ||
|
|
19ec3321ae | ||
|
|
d82af9f1a0 | ||
|
|
4712d2c8ac | ||
|
|
a2df4217fd | ||
|
|
096c96550b | ||
|
|
2fb3f31930 | ||
|
|
f52b4a2e11 | ||
|
|
bbc78ffec6 | ||
|
|
3606f412b3 | ||
|
|
6e0e94094b | ||
|
|
976960f495 | ||
|
|
d2f2f3b2d3 | ||
|
|
2da7c45840 | ||
|
|
fb078de627 | ||
|
|
da46b7fddb | ||
|
|
c4e0729b7d | ||
|
|
eee9f0ace5 | ||
|
|
d0692458a3 | ||
|
|
c96e6c7c92 | ||
|
|
4956278f17 | ||
|
|
5858a86624 | ||
|
|
c87d178a6a | ||
|
|
6fc872b1fd | ||
|
|
589c5783a0 | ||
|
|
40165628d6 | ||
|
|
435be77249 | ||
|
|
b932ba856d | ||
|
|
094514f617 | ||
|
|
fab96879d0 | ||
|
|
367a5f0c57 | ||
|
|
0d2ecfbc67 | ||
|
|
5410ba3b1d | ||
|
|
716bfd4611 | ||
|
|
3830a58493 |
17
pom.xml
17
pom.xml
@@ -3,11 +3,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>pom</artifactId>
|
<artifactId>pom</artifactId>
|
||||||
<version>4</version>
|
<version>6</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.41</version>
|
<version>1.45</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>
|
||||||
@@ -64,9 +64,9 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-mapper-asl</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>1.9.9</version>
|
<version>2.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
@@ -85,8 +85,13 @@
|
|||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jgit</groupId>
|
||||||
|
<artifactId>org.eclipse.jgit</artifactId>
|
||||||
|
<version>3.1.0.201310021548-r</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>repo.jenkins-ci.org</id>
|
<id>repo.jenkins-ci.org</id>
|
||||||
|
|||||||
108
src/main/java/org/kohsuke/github/GHAsset.java
Normal file
108
src/main/java/org/kohsuke/github/GHAsset.java
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asset in a release.
|
||||||
|
*
|
||||||
|
* @see GHRelease#getAssets()
|
||||||
|
*/
|
||||||
|
public class GHAsset {
|
||||||
|
GitHub root;
|
||||||
|
GHRepository owner;
|
||||||
|
private String url;
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String label;
|
||||||
|
private String state;
|
||||||
|
private String content_type;
|
||||||
|
private long size;
|
||||||
|
private long download_count;
|
||||||
|
private Date created_at;
|
||||||
|
private Date updated_at;
|
||||||
|
|
||||||
|
public String getContentType() {
|
||||||
|
return content_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentType(String contentType) throws IOException {
|
||||||
|
edit("content_type", contentType);
|
||||||
|
this.content_type = contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedAt() {
|
||||||
|
return created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDownloadCount() {
|
||||||
|
return download_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) throws IOException {
|
||||||
|
edit("label", label);
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRepository getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedAt() {
|
||||||
|
return updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void edit(String key, Object value) throws IOException {
|
||||||
|
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getApiRoute() {
|
||||||
|
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/releases/assets/" + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHAsset wrap(GHRelease release) {
|
||||||
|
this.owner = release.getOwner();
|
||||||
|
this.root = owner.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GHAsset[] wrap(GHAsset[] assets, GHRelease release) {
|
||||||
|
for (GHAsset aTo : assets) {
|
||||||
|
aTo.wrap(release);
|
||||||
|
}
|
||||||
|
return assets;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import java.net.URL;
|
|||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,6 +17,55 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class GHCommit {
|
public class GHCommit {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
|
private ShortInfo commit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short summary of this commit.
|
||||||
|
*/
|
||||||
|
public static class ShortInfo {
|
||||||
|
private GHAuthor author;
|
||||||
|
private GHAuthor committer;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private int comment_count;
|
||||||
|
|
||||||
|
public GHAuthor getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHAuthor getCommitter() {
|
||||||
|
return committer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit message.
|
||||||
|
*/
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCommentCount() {
|
||||||
|
return comment_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GHAuthor {
|
||||||
|
private String name,email,date;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return GitHub.parseDate(date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Stats {
|
public static class Stats {
|
||||||
int total,additions,deletions;
|
int total,additions,deletions;
|
||||||
@@ -110,8 +160,14 @@ public class GHCommit {
|
|||||||
Stats stats;
|
Stats stats;
|
||||||
List<Parent> parents;
|
List<Parent> parents;
|
||||||
User author,committer;
|
User author,committer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
public ShortInfo getCommitShortInfo() {
|
||||||
|
return commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* The repository that contains the commit.
|
* The repository that contains the commit.
|
||||||
*/
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import org.codehaus.jackson.node.ObjectNode;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an event.
|
* Represents an event.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public abstract class GHEventPayload {
|
|||||||
private String action;
|
private String action;
|
||||||
private int number;
|
private int number;
|
||||||
private GHPullRequest pull_request;
|
private GHPullRequest pull_request;
|
||||||
|
private GHRepository repository;
|
||||||
|
|
||||||
public String getAction() {
|
public String getAction() {
|
||||||
return action;
|
return action;
|
||||||
@@ -41,10 +42,19 @@ public abstract class GHEventPayload {
|
|||||||
return pull_request;
|
return pull_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHRepository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void wrapUp(GitHub root) {
|
void wrapUp(GitHub root) {
|
||||||
super.wrapUp(root);
|
super.wrapUp(root);
|
||||||
pull_request.wrapUp(root);
|
if (repository!=null) {
|
||||||
|
repository.wrap(root);
|
||||||
|
pull_request.wrap(repository);
|
||||||
|
} else {
|
||||||
|
pull_request.wrapUp(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class GHIssue {
|
|||||||
protected String closed_at;
|
protected String closed_at;
|
||||||
protected int comments;
|
protected int comments;
|
||||||
protected String body;
|
protected String body;
|
||||||
protected List<String> labels;
|
protected List<Label> labels;
|
||||||
protected GHUser user;
|
protected GHUser user;
|
||||||
protected String title, created_at, html_url;
|
protected String title, created_at, html_url;
|
||||||
protected GHIssue.PullRequest pull_request;
|
protected GHIssue.PullRequest pull_request;
|
||||||
@@ -58,6 +58,24 @@ public class GHIssue {
|
|||||||
protected int id;
|
protected int id;
|
||||||
protected GHUser closed_by;
|
protected GHUser closed_by;
|
||||||
|
|
||||||
|
public static class Label {
|
||||||
|
private String url;
|
||||||
|
private String name;
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
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;
|
this.root = owner.root;
|
||||||
@@ -111,7 +129,7 @@ public class GHIssue {
|
|||||||
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getLabels() {
|
public Collection<Label> getLabels() {
|
||||||
if(labels == null){
|
if(labels == null){
|
||||||
return Collections.EMPTY_LIST;
|
return Collections.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
@@ -138,7 +156,7 @@ public class GHIssue {
|
|||||||
* Updates the issue by adding a comment.
|
* Updates the issue by adding a comment.
|
||||||
*/
|
*/
|
||||||
public void comment(String message) throws IOException {
|
public void comment(String message) throws IOException {
|
||||||
new Requester(root).with("body",message).to(getApiRoute() + "/comments");
|
new Requester(root).with("body",message).to(getIssuesApiRoute() + "/comments");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, Object value) throws IOException {
|
private void edit(String key, Object value) throws IOException {
|
||||||
@@ -190,7 +208,7 @@ public class GHIssue {
|
|||||||
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
||||||
return new PagedIterable<GHIssueComment>() {
|
return new PagedIterable<GHIssueComment>() {
|
||||||
public PagedIterator<GHIssueComment> iterator() {
|
public PagedIterator<GHIssueComment> iterator() {
|
||||||
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getApiRoute() + "/comments", GHIssueComment[].class)) {
|
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getIssuesApiRoute() + "/comments", GHIssueComment[].class)) {
|
||||||
protected void wrapUp(GHIssueComment[] page) {
|
protected void wrapUp(GHIssueComment[] page) {
|
||||||
for (GHIssueComment c : page)
|
for (GHIssueComment c : page)
|
||||||
c.wrapUp(GHIssue.this);
|
c.wrapUp(GHIssue.this);
|
||||||
@@ -201,6 +219,10 @@ public class GHIssue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
|
return getIssuesApiRoute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getIssuesApiRoute() {
|
||||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
|
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,4 +272,4 @@ public class GHIssue {
|
|||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ package org.kohsuke.github;
|
|||||||
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.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the account that's logging into GitHub.
|
* Represents the account that's logging into GitHub.
|
||||||
@@ -35,7 +40,50 @@ public class GHMyself extends GHUser {
|
|||||||
public List<GHKey> getPublicKeys() throws IOException {
|
public List<GHKey> getPublicKeys() throws IOException {
|
||||||
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
|
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the organization that this user belongs to.
|
||||||
|
*/
|
||||||
|
public GHPersonSet<GHOrganization> getAllOrganizations() throws IOException {
|
||||||
|
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
|
||||||
|
Set<String> names = new HashSet<String>();
|
||||||
|
for (GHOrganization o : root.retrieve().to("/user/orgs", GHOrganization[].class)) {
|
||||||
|
if (names.add(o.getLogin())) // in case of rumoured duplicates in the data
|
||||||
|
orgs.add(root.getOrganization(o.getLogin()));
|
||||||
|
}
|
||||||
|
return orgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the all repositories this user owns (public and private).
|
||||||
|
*/
|
||||||
|
public synchronized Map<String,GHRepository> getAllRepositories() throws IOException {
|
||||||
|
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
|
||||||
|
for (GHRepository r : listAllRepositories()) {
|
||||||
|
repositories.put(r.getName(),r);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableMap(repositories);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up all repositories this user owns (public and private).
|
||||||
|
*
|
||||||
|
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHRepository> listAllRepositories() {
|
||||||
|
return new PagedIterable<GHRepository>() {
|
||||||
|
public PagedIterator<GHRepository> iterator() {
|
||||||
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos", GHRepository[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHRepository[] page) {
|
||||||
|
for (GHRepository c : page)
|
||||||
|
c.wrap(root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// public void addEmails(Collection<String> emails) throws IOException {
|
// public void addEmails(Collection<String> emails) throws IOException {
|
||||||
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
|
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
|
||||||
// root.retrieveWithAuth3()
|
// root.retrieveWithAuth3()
|
||||||
|
|||||||
@@ -130,10 +130,13 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List up repositories that has some open pull requests.
|
* List up repositories that has some open pull requests.
|
||||||
|
*
|
||||||
|
* This used to be an efficient method that didn't involve traversing every repository, but now
|
||||||
|
* it doesn't do any optimization.
|
||||||
*/
|
*/
|
||||||
public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOException {
|
public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOException {
|
||||||
List<GHRepository> r = new ArrayList<GHRepository>();
|
List<GHRepository> r = new ArrayList<GHRepository>();
|
||||||
for (GHRepository repository : root.retrieve().to("/orgs/" + login + "/repos", GHRepository[].class)) {
|
for (GHRepository repository : listRepositories()) {
|
||||||
repository.wrap(root);
|
repository.wrap(root);
|
||||||
List<GHPullRequest> pullRequests = repository.getPullRequests(GHIssueState.OPEN);
|
List<GHPullRequest> pullRequests = repository.getPullRequests(GHIssueState.OPEN);
|
||||||
if (pullRequests.size() > 0) {
|
if (pullRequests.size() > 0) {
|
||||||
|
|||||||
@@ -54,6 +54,36 @@ public abstract class GHPerson {
|
|||||||
return Collections.unmodifiableMap(repositories);
|
return Collections.unmodifiableMap(repositories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up all the repositories using a 30 items page size.
|
||||||
|
*
|
||||||
|
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHRepository> listRepositories() {
|
||||||
|
return listRepositories(30);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up all the repositories using the specified page size.
|
||||||
|
*
|
||||||
|
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
|
||||||
|
*
|
||||||
|
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
|
return new PagedIterable<GHRepository>() {
|
||||||
|
public PagedIterator<GHRepository> iterator() {
|
||||||
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHRepository[] page) {
|
||||||
|
for (GHRepository c : page)
|
||||||
|
c.wrap(root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads repository list in a pagenated fashion.
|
* Loads repository list in a pagenated fashion.
|
||||||
*
|
*
|
||||||
@@ -63,6 +93,9 @@ public abstract class GHPerson {
|
|||||||
*
|
*
|
||||||
* Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped
|
* Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped
|
||||||
* into {@link Error}.
|
* into {@link Error}.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* Use {@link #listRepositories()}
|
||||||
*/
|
*/
|
||||||
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
||||||
return new Iterable<List<GHRepository>>() {
|
return new Iterable<List<GHRepository>>() {
|
||||||
@@ -202,5 +235,4 @@ public abstract class GHPerson {
|
|||||||
populate();
|
populate();
|
||||||
return followers;
|
return followers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pull request.
|
* A pull request.
|
||||||
@@ -118,7 +119,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> getLabels() {
|
public Collection<Label> getLabels() {
|
||||||
return super.getLabels();
|
return super.getLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,4 +187,22 @@ public class GHPullRequest extends GHIssue {
|
|||||||
|
|
||||||
root.retrieve().to(url, this);
|
root.retrieve().to(url, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all the commits associated to this pull request.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
|
||||||
|
return new PagedIterable<GHPullRequestCommitDetail>() {
|
||||||
|
public PagedIterator<GHPullRequestCommitDetail> iterator() {
|
||||||
|
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
||||||
|
String.format("%s/commits", getApiURL().getPath()),
|
||||||
|
GHPullRequestCommitDetail[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
139
src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java
Normal file
139
src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, Luca Milanesio
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit detail inside a {@link GHPullRequest}.
|
||||||
|
*
|
||||||
|
* @author Luca Milanesio
|
||||||
|
*/
|
||||||
|
public class GHPullRequestCommitDetail {
|
||||||
|
|
||||||
|
public static class Authorship {
|
||||||
|
String name;
|
||||||
|
String email;
|
||||||
|
String date;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return GitHub.parseDate(date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Tree {
|
||||||
|
String sha;
|
||||||
|
String url;
|
||||||
|
|
||||||
|
public String getSha() {
|
||||||
|
return sha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getUrl() {
|
||||||
|
return GitHub.parseURL(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Commit {
|
||||||
|
Authorship author;
|
||||||
|
Authorship committer;
|
||||||
|
String message;
|
||||||
|
Tree tree;
|
||||||
|
String url;
|
||||||
|
int comment_count;
|
||||||
|
|
||||||
|
public Authorship getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Authorship getCommitter() {
|
||||||
|
return committer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getUrl() {
|
||||||
|
return GitHub.parseURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getComment_count() {
|
||||||
|
return comment_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CommitPointer {
|
||||||
|
String sha;
|
||||||
|
String url;
|
||||||
|
String html_url;
|
||||||
|
|
||||||
|
public URL getUrl() {
|
||||||
|
return GitHub.parseURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getHtml_url() {
|
||||||
|
return GitHub.parseURL(html_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSha() {
|
||||||
|
return sha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String sha;
|
||||||
|
Commit commit;
|
||||||
|
String url;
|
||||||
|
String html_url;
|
||||||
|
String comments_url;
|
||||||
|
CommitPointer[] parents;
|
||||||
|
|
||||||
|
public String getSha() {
|
||||||
|
return sha;
|
||||||
|
}
|
||||||
|
public Commit getCommit() {
|
||||||
|
return commit;
|
||||||
|
}
|
||||||
|
public URL getApiUrl() {
|
||||||
|
return GitHub.parseURL(url);
|
||||||
|
}
|
||||||
|
public URL getUrl() {
|
||||||
|
return GitHub.parseURL(html_url);
|
||||||
|
}
|
||||||
|
public URL getCommentsUrl() {
|
||||||
|
return GitHub.parseURL(comments_url);
|
||||||
|
}
|
||||||
|
public CommitPointer[] getParents() {
|
||||||
|
return parents;
|
||||||
|
}
|
||||||
|
}
|
||||||
195
src/main/java/org/kohsuke/github/GHRelease.java
Normal file
195
src/main/java/org/kohsuke/github/GHRelease.java
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release in a github repository.
|
||||||
|
*
|
||||||
|
* @see GHRepository#getReleases()
|
||||||
|
* @see GHRepository#createRelease(String)
|
||||||
|
*/
|
||||||
|
public class GHRelease {
|
||||||
|
GitHub root;
|
||||||
|
GHRepository owner;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
private String html_url;
|
||||||
|
private String assets_url;
|
||||||
|
private String upload_url;
|
||||||
|
private long id;
|
||||||
|
private String tag_name;
|
||||||
|
private String target_commitish;
|
||||||
|
private String name;
|
||||||
|
private String body;
|
||||||
|
private boolean draft;
|
||||||
|
private boolean prerelease;
|
||||||
|
private Date created_at;
|
||||||
|
private Date published_at;
|
||||||
|
|
||||||
|
public String getAssetsUrl() {
|
||||||
|
return assets_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssetsUrl(String assets_url) {
|
||||||
|
this.assets_url = assets_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBody() {
|
||||||
|
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() {
|
||||||
|
return draft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDraft(boolean draft) {
|
||||||
|
this.draft = draft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHtmlUrl() {
|
||||||
|
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() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRepository getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(GHRepository owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrerelease() {
|
||||||
|
return prerelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrerelease(boolean prerelease) {
|
||||||
|
this.prerelease = prerelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getPublished_at() {
|
||||||
|
return published_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublished_at(Date published_at) {
|
||||||
|
this.published_at = published_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoot(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTagName() {
|
||||||
|
return tag_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTagName(String tag_name) {
|
||||||
|
this.tag_name = tag_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetCommitish() {
|
||||||
|
return target_commitish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetCommitish(String target_commitish) {
|
||||||
|
this.target_commitish = target_commitish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUploadUrl() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHRelease wrap(GHRepository owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.root = owner.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) {
|
||||||
|
for (GHRelease release : releases) {
|
||||||
|
release.wrap(owner);
|
||||||
|
}
|
||||||
|
return releases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on
|
||||||
|
* Java 7 or greater. Options for fixing this for earlier JVMs can be found here
|
||||||
|
* http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated
|
||||||
|
* handling of the HTTP requests to github's API.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
||||||
|
Requester builder = new Requester(owner.root);
|
||||||
|
|
||||||
|
String url = format("https://uploads.github.com%sreleases/%d/assets?name=%s",
|
||||||
|
owner.getApiTailUrl(""), getId(), file.getName());
|
||||||
|
return builder.contentType(contentType)
|
||||||
|
.with(new FileInputStream(file))
|
||||||
|
.to(url, GHAsset.class).wrap(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GHAsset> getAssets() throws IOException {
|
||||||
|
Requester builder = new Requester(owner.root);
|
||||||
|
|
||||||
|
GHAsset[] assets = builder
|
||||||
|
.method("GET")
|
||||||
|
.to(owner.getApiTailUrl(format("releases/%d/assets", id)), GHAsset[].class);
|
||||||
|
return Arrays.asList(GHAsset.wrap(assets, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
80
src/main/java/org/kohsuke/github/GHReleaseBuilder.java
Normal file
80
src/main/java/org/kohsuke/github/GHReleaseBuilder.java
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder pattern for creating a {@link GHRelease}
|
||||||
|
*
|
||||||
|
* @see GHRepository#createRelease(String)
|
||||||
|
*/
|
||||||
|
public class GHReleaseBuilder {
|
||||||
|
private final GHRepository repo;
|
||||||
|
private final Requester builder;
|
||||||
|
|
||||||
|
public GHReleaseBuilder(GHRepository ghRepository, String tag) {
|
||||||
|
this.repo = ghRepository;
|
||||||
|
this.builder = new Requester(repo.root);
|
||||||
|
builder.with("tag_name", tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param body The release notes body.
|
||||||
|
*/
|
||||||
|
public GHReleaseBuilder body(String body) {
|
||||||
|
if (body != null) {
|
||||||
|
builder.with("body", body);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or
|
||||||
|
* commit SHA.
|
||||||
|
*
|
||||||
|
* @param commitish Defaults to the repository’s default branch (usually "master"). Unused if the Git tag
|
||||||
|
* already exists.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public GHReleaseBuilder commitish(String commitish) {
|
||||||
|
if (commitish != null) {
|
||||||
|
builder.with("target_commitish", commitish);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional.
|
||||||
|
*
|
||||||
|
* @param draft {@code true} to create a draft (unpublished) release, {@code false} to create a published one.
|
||||||
|
* Default is {@code false}.
|
||||||
|
*/
|
||||||
|
public GHReleaseBuilder draft(boolean draft) {
|
||||||
|
builder.with("draft", draft);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name the name of the release
|
||||||
|
*/
|
||||||
|
public GHReleaseBuilder name(String name) {
|
||||||
|
if (name != null) {
|
||||||
|
builder.with("name", name);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
*
|
||||||
|
* @param prerelease {@code true} to identify the release as a prerelease. {@code false} to identify the release
|
||||||
|
* as a full release. Default is {@code false}.
|
||||||
|
*/
|
||||||
|
public GHReleaseBuilder prerelease(boolean prerelease) {
|
||||||
|
builder.with("prerelease", prerelease);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRelease create() throws IOException {
|
||||||
|
return builder.to(repo.getApiTailUrl("releases"), GHRelease.class).wrap(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -146,6 +146,15 @@ public class GHRepository {
|
|||||||
return Arrays.asList(GHIssue.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this));
|
return Arrays.asList(GHIssue.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHReleaseBuilder createRelease(String tag) {
|
||||||
|
return new GHReleaseBuilder(this,tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GHRelease> getReleases() throws IOException {
|
||||||
|
return Arrays.asList(GHRelease.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/releases",
|
||||||
|
GHRelease[].class), this));
|
||||||
|
}
|
||||||
|
|
||||||
protected String getOwnerName() {
|
protected String getOwnerName() {
|
||||||
return owner.login;
|
return owner.login;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.*;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.codehaus.jackson.map.DeserializationConfig.Feature;
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.codehaus.jackson.map.introspect.VisibilityChecker.Std;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -47,7 +42,13 @@ import java.util.Map;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.*;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std;
|
||||||
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root of the GitHub API.
|
* Root of the GitHub API.
|
||||||
@@ -123,7 +124,7 @@ public class GitHub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (login==null)
|
if (login==null && encodedAuthorization!=null)
|
||||||
login = getMyself().getLogin();
|
login = getMyself().getLogin();
|
||||||
this.login = login;
|
this.login = login;
|
||||||
}
|
}
|
||||||
@@ -192,8 +193,16 @@ public class GitHub {
|
|||||||
return new GitHub(null,null,null);
|
return new GitHub(null,null,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this an anonymous connection
|
||||||
|
* @return {@code true} if operations that require authentication will fail.
|
||||||
|
*/
|
||||||
|
public boolean isAnonymous() {
|
||||||
|
return login==null && encodedAuthorization==null;
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ void requireCredential() {
|
/*package*/ void requireCredential() {
|
||||||
if (login==null || encodedAuthorization==null)
|
if (isAnonymous())
|
||||||
throw new IllegalStateException("This operation requires a credential but none is given to the GitHub constructor");
|
throw new IllegalStateException("This operation requires a credential but none is given to the GitHub constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +398,7 @@ public class GitHub {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY));
|
MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY));
|
||||||
MAPPER.getDeserializationConfig().set(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String GITHUB_URL = "https://api.github.com";
|
private static final String GITHUB_URL = "https://api.github.com";
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -47,7 +48,7 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import static org.kohsuke.github.GitHub.*;
|
import static org.kohsuke.github.GitHub.MAPPER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder pattern for making HTTP call and parsing its output.
|
* A builder pattern for making HTTP call and parsing its output.
|
||||||
@@ -62,6 +63,8 @@ class Requester {
|
|||||||
* Request method.
|
* Request method.
|
||||||
*/
|
*/
|
||||||
private String method = "POST";
|
private String method = "POST";
|
||||||
|
private String contentType = "application/x-www-form-urlencoded";
|
||||||
|
private InputStream body;
|
||||||
|
|
||||||
private static class Entry {
|
private static class Entry {
|
||||||
String key;
|
String key;
|
||||||
@@ -113,6 +116,11 @@ class Requester {
|
|||||||
return _with(key, value);
|
return _with(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Requester with(InputStream body) {
|
||||||
|
this.body = body;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Requester _with(String key, Object value) {
|
public Requester _with(String key, Object value) {
|
||||||
if (value!=null) {
|
if (value!=null) {
|
||||||
args.add(new Entry(key,value));
|
args.add(new Entry(key,value));
|
||||||
@@ -125,6 +133,11 @@ class Requester {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Requester contentType(String contentType) {
|
||||||
|
this.contentType = contentType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void to(String tailApiUrl) throws IOException {
|
public void to(String tailApiUrl) throws IOException {
|
||||||
to(tailApiUrl,null);
|
to(tailApiUrl,null);
|
||||||
}
|
}
|
||||||
@@ -162,13 +175,25 @@ class Requester {
|
|||||||
|
|
||||||
if (!method.equals("GET")) {
|
if (!method.equals("GET")) {
|
||||||
uc.setDoOutput(true);
|
uc.setDoOutput(true);
|
||||||
uc.setRequestProperty("Content-type","application/x-www-form-urlencoded");
|
uc.setRequestProperty("Content-type", contentType);
|
||||||
|
|
||||||
Map json = new HashMap();
|
if (body == null) {
|
||||||
for (Entry e : args) {
|
Map json = new HashMap();
|
||||||
json.put(e.key, e.value);
|
for (Entry e : args) {
|
||||||
|
json.put(e.key, e.value);
|
||||||
|
}
|
||||||
|
MAPPER.writeValue(uc.getOutputStream(), json);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
byte[] bytes = new byte[32768];
|
||||||
|
int read = 0;
|
||||||
|
while ((read = body.read(bytes)) != -1) {
|
||||||
|
uc.getOutputStream().write(bytes, 0, read);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
body.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MAPPER.writeValue(uc.getOutputStream(),json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -269,7 +294,7 @@ class Requester {
|
|||||||
|
|
||||||
|
|
||||||
private HttpURLConnection setupConnection(URL url) throws IOException {
|
private HttpURLConnection setupConnection(URL url) throws IOException {
|
||||||
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
|
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
|
||||||
|
|
||||||
// if the authentication is needed but no credential is given, try it anyway (so that some calls
|
// if the authentication is needed but no credential is given, try it anyway (so that some calls
|
||||||
// that do work with anonymous access in the reduced form should still work.)
|
// that do work with anonymous access in the reduced form should still work.)
|
||||||
|
|||||||
@@ -332,6 +332,12 @@ public class AppTest extends TestCase {
|
|||||||
assertEquals("oops!",state.getDescription());
|
assertEquals("oops!",state.getDescription());
|
||||||
assertEquals("http://jenkins-ci.org/",state.getTargetUrl());
|
assertEquals("http://jenkins-ci.org/",state.getTargetUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCommitShortInfo() throws Exception {
|
||||||
|
GHCommit commit = gitHub.getUser("kohsuke").getRepository("test").getCommit("c77360d6f2ff2c2e6dd11828ad5dccf72419fa1b");
|
||||||
|
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Kohsuke Kawaguchi");
|
||||||
|
assertEquals(commit.getCommitShortInfo().getMessage(), "Added a file");
|
||||||
|
}
|
||||||
|
|
||||||
public void testPullRequestPopulate() throws Exception {
|
public void testPullRequestPopulate() throws Exception {
|
||||||
GHRepository r = gitHub.getUser("kohsuke").getRepository("github-api");
|
GHRepository r = gitHub.getUser("kohsuke").getRepository("github-api");
|
||||||
|
|||||||
146
src/test/java/org/kohsuke/LifecycleTest.java
Normal file
146
src/test/java/org/kohsuke/LifecycleTest.java
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package org.kohsuke;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.eclipse.jgit.api.Git;
|
||||||
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
|
import org.eclipse.jgit.dircache.DirCache;
|
||||||
|
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||||
|
import org.kohsuke.github.GHAsset;
|
||||||
|
import org.kohsuke.github.GHIssue;
|
||||||
|
import org.kohsuke.github.GHMilestone;
|
||||||
|
import org.kohsuke.github.GHMyself;
|
||||||
|
import org.kohsuke.github.GHRelease;
|
||||||
|
import org.kohsuke.github.GHRepository;
|
||||||
|
import org.kohsuke.github.GitHub;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class LifecycleTest extends TestCase {
|
||||||
|
private GitHub gitHub;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
gitHub = GitHub.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreateRepository() throws IOException, GitAPIException {
|
||||||
|
GHMyself myself = gitHub.getMyself();
|
||||||
|
GHRepository repository = myself.getRepository("github-api-test");
|
||||||
|
if (repository != null) {
|
||||||
|
repository.delete();
|
||||||
|
}
|
||||||
|
repository = gitHub.createRepository("github-api-test",
|
||||||
|
"a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", true);
|
||||||
|
|
||||||
|
assertTrue(repository.getReleases().isEmpty());
|
||||||
|
try {
|
||||||
|
GHMilestone milestone = repository.createMilestone("Initial Release", "first one");
|
||||||
|
GHIssue issue = repository.createIssue("Test Issue")
|
||||||
|
.body("issue body just for grins")
|
||||||
|
.milestone(milestone)
|
||||||
|
.assignee(myself)
|
||||||
|
.label("bug")
|
||||||
|
.create();
|
||||||
|
File repoDir = new File(System.getProperty("java.io.tmpdir"), "github-api-test");
|
||||||
|
delete(repoDir);
|
||||||
|
Git origin = Git.cloneRepository()
|
||||||
|
.setBare(false)
|
||||||
|
.setURI(repository.gitHttpTransportUrl())
|
||||||
|
.setDirectory(repoDir)
|
||||||
|
.setCredentialsProvider(getCredentialsProvider(myself))
|
||||||
|
.call();
|
||||||
|
|
||||||
|
commitTestFile(myself, repoDir, origin);
|
||||||
|
|
||||||
|
|
||||||
|
GHRelease release = createRelease(repository);
|
||||||
|
|
||||||
|
GHAsset asset = uploadAsset(release);
|
||||||
|
|
||||||
|
updateAsset(release, asset);
|
||||||
|
|
||||||
|
deleteAsset(release, asset);
|
||||||
|
} finally {
|
||||||
|
repository.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateAsset(GHRelease release, GHAsset asset) throws IOException {
|
||||||
|
asset.setLabel("test label");
|
||||||
|
assertEquals("test label", release.getAssets().get(0).getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteAsset(GHRelease release, GHAsset asset) throws IOException {
|
||||||
|
asset.delete();
|
||||||
|
assertEquals(0, release.getAssets().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private GHAsset uploadAsset(GHRelease release) throws IOException {
|
||||||
|
GHAsset asset = release.uploadAsset(new File("pom.xml"), "application/text");
|
||||||
|
assertNotNull(asset);
|
||||||
|
List<GHAsset> assets = release.getAssets();
|
||||||
|
assertEquals(1, assets.size());
|
||||||
|
assertEquals("pom.xml", assets.get(0).getName());
|
||||||
|
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GHRelease createRelease(GHRepository repository) throws IOException {
|
||||||
|
GHRelease builder = repository.createRelease("release_tag")
|
||||||
|
.name("Test Release")
|
||||||
|
.body("How exciting! To be able to programmatically create releases is a dream come true!")
|
||||||
|
.create();
|
||||||
|
List<GHRelease> releases = repository.getReleases();
|
||||||
|
assertEquals(1, releases.size());
|
||||||
|
GHRelease release = releases.get(0);
|
||||||
|
assertEquals("Test Release", release.getName());
|
||||||
|
return release;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void commitTestFile(GHMyself myself, File repoDir, Git origin) throws IOException, GitAPIException {
|
||||||
|
File dummyFile = createDummyFile(repoDir);
|
||||||
|
DirCache cache = origin.add().addFilepattern(dummyFile.getName()).call();
|
||||||
|
origin.commit().setMessage("test commit").call();
|
||||||
|
origin.push().setCredentialsProvider(getCredentialsProvider(myself)).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
private UsernamePasswordCredentialsProvider getCredentialsProvider(GHMyself myself) throws IOException {
|
||||||
|
Properties props = new Properties();
|
||||||
|
File homeDir = new File(System.getProperty("user.home"));
|
||||||
|
FileInputStream in = new FileInputStream(new File(homeDir, ".github"));
|
||||||
|
try {
|
||||||
|
props.load(in);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
}
|
||||||
|
return new UsernamePasswordCredentialsProvider(props.getProperty("login"), props.getProperty("oauth"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void delete(File toDelete) {
|
||||||
|
if (toDelete.isDirectory()) {
|
||||||
|
for (File file : toDelete.listFiles()) {
|
||||||
|
delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toDelete.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createDummyFile(File repoDir) throws IOException {
|
||||||
|
File file = new File(repoDir, "testFile-" + System.currentTimeMillis());
|
||||||
|
PrintWriter writer = new PrintWriter(new FileWriter(file));
|
||||||
|
try {
|
||||||
|
writer.println("test file");
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user