mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-21 08:21:21 +00:00
Compare commits
22 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dd738b0db | ||
|
|
6480dde247 | ||
|
|
555dab7403 | ||
|
|
13158a28e1 | ||
|
|
cbaca87bbc | ||
|
|
5166202f67 | ||
|
|
35d45ca47d | ||
|
|
b66ede98c7 | ||
|
|
1ba8f2ccbf | ||
|
|
82133c117a | ||
|
|
f71afca828 | ||
|
|
87f5231c9a | ||
|
|
b17f506c20 | ||
|
|
7f15f12668 | ||
|
|
e53e62bfa0 | ||
|
|
2e74517a4a | ||
|
|
aed888051e | ||
|
|
bd584124bb | ||
|
|
e658a7fa6b | ||
|
|
52108707bb | ||
|
|
0e226a8f78 | ||
|
|
1bf3e025b8 |
9
pom.xml
9
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.32</version>
|
<version>1.34</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>
|
||||||
@@ -85,6 +85,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>repo.jenkins-ci.org</id>
|
||||||
|
<url>http://repo.jenkins-ci.org/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -225,7 +225,6 @@ public class GHCommit {
|
|||||||
.with("path",path)
|
.with("path",path)
|
||||||
.with("line",line)
|
.with("line",line)
|
||||||
.with("position",position)
|
.with("position",position)
|
||||||
.withCredential()
|
|
||||||
.to(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment.class);
|
.to(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment.class);
|
||||||
return r.wrap(owner);
|
return r.wrap(owner);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class GHCommitComment {
|
|||||||
public void update(String body) throws IOException {
|
public void update(String body) throws IOException {
|
||||||
GHCommitComment r = new Requester(owner.root)
|
GHCommitComment r = new Requester(owner.root)
|
||||||
.with("body", body)
|
.with("body", body)
|
||||||
.withCredential().method("PATCH").to(getApiTail(), GHCommitComment.class);
|
.method("PATCH").to(getApiTail(), GHCommitComment.class);
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class GHCommitComment {
|
|||||||
* Deletes this comment.
|
* Deletes this comment.
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).withCredential().method("DELETE").to(getApiTail());
|
new Requester(owner.root).method("DELETE").to(getApiTail());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiTail() {
|
private String getApiTail() {
|
||||||
|
|||||||
@@ -54,6 +54,6 @@ public final class GHHook {
|
|||||||
* Deletes this hook.
|
* Deletes this hook.
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(repository.root).withCredential().method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
|
new Requester(repository.root).method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,11 +138,11 @@ 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).withCredential().with("body",message).to(getApiRoute() + "/comments");
|
new Requester(root).with("body",message).to(getApiRoute() + "/comments");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, Object value) throws IOException {
|
private void edit(String key, Object value) throws IOException {
|
||||||
new Requester(root).withCredential()._with(key, value).method("PATCH").to(getApiRoute());
|
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,7 +211,6 @@ public class GHIssue {
|
|||||||
/**
|
/**
|
||||||
* User who submitted the issue.
|
* User who submitted the issue.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public GHUser getUser() {
|
public GHUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
59
src/main/java/org/kohsuke/github/GHIssueBuilder.java
Normal file
59
src/main/java/org/kohsuke/github/GHIssueBuilder.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class GHIssueBuilder {
|
||||||
|
private final GHRepository repo;
|
||||||
|
private final Requester builder;
|
||||||
|
private List<String> labels = new ArrayList<String>();
|
||||||
|
|
||||||
|
GHIssueBuilder(GHRepository repo, String title) {
|
||||||
|
this.repo = repo;
|
||||||
|
this.builder = new Requester(repo.root);
|
||||||
|
builder.with("title",title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the main text of an issue, which is arbitrary multi-line text.
|
||||||
|
*/
|
||||||
|
public GHIssueBuilder body(String str) {
|
||||||
|
builder.with("body",str);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueBuilder assignee(GHUser user) {
|
||||||
|
if (user!=null)
|
||||||
|
builder.with("assignee",user.getLogin());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueBuilder assignee(String user) {
|
||||||
|
if (user!=null)
|
||||||
|
builder.with("assignee",user);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueBuilder milestone(GHMilestone milestone) {
|
||||||
|
if (milestone!=null)
|
||||||
|
builder.with("milestone",milestone.getNumber());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueBuilder label(String label) {
|
||||||
|
if (label!=null)
|
||||||
|
labels.add(label);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new issue.
|
||||||
|
*/
|
||||||
|
public GHIssue create() throws IOException {
|
||||||
|
return builder.with("labels",labels).to(repo.getApiTailUrl("issues"),GHIssue.class).wrap(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ public class GHMyself extends GHUser {
|
|||||||
* Always non-null.
|
* Always non-null.
|
||||||
*/
|
*/
|
||||||
public List<String> getEmails() throws IOException {
|
public List<String> getEmails() throws IOException {
|
||||||
String[] addresses = root.retrieve().withCredential().to("/user/emails", String[].class);
|
String[] addresses = root.retrieve().to("/user/emails", String[].class);
|
||||||
return Collections.unmodifiableList(Arrays.asList(addresses));
|
return Collections.unmodifiableList(Arrays.asList(addresses));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class GHMyself extends GHUser {
|
|||||||
* Always non-null.
|
* Always non-null.
|
||||||
*/
|
*/
|
||||||
public List<GHKey> getPublicKeys() throws IOException {
|
public List<GHKey> getPublicKeys() throws IOException {
|
||||||
return Collections.unmodifiableList(Arrays.asList(root.retrieve().withCredential().to("/user/keys", GHKey[].class)));
|
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void addEmails(Collection<String> emails) throws IOException {
|
// public void addEmails(Collection<String> emails) throws IOException {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException {
|
public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException {
|
||||||
// such API doesn't exist, so fall back to HTML scraping
|
// such API doesn't exist, so fall back to HTML scraping
|
||||||
return new Requester(root).withCredential()
|
return new Requester(root)
|
||||||
.with("name", name).with("description", description).with("homepage", homepage)
|
.with("name", name).with("description", description).with("homepage", homepage)
|
||||||
.with("public", isPublic).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root);
|
.with("public", isPublic).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root);
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Teams by their names.
|
* Teams by their names.
|
||||||
*/
|
*/
|
||||||
public Map<String,GHTeam> getTeams() throws IOException {
|
public Map<String,GHTeam> getTeams() throws IOException {
|
||||||
GHTeam[] teams = root.retrieve().withCredential().to("/orgs/" + login + "/teams", GHTeam[].class);
|
GHTeam[] teams = root.retrieve().to("/orgs/" + login + "/teams", GHTeam[].class);
|
||||||
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
|
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
|
||||||
for (GHTeam t : teams) {
|
for (GHTeam t : teams) {
|
||||||
r.put(t.getName(),t.wrapUp(this));
|
r.put(t.getName(),t.wrapUp(this));
|
||||||
@@ -54,7 +54,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Publicizes the membership.
|
* Publicizes the membership.
|
||||||
*/
|
*/
|
||||||
public void publicize(GHUser u) throws IOException {
|
public void publicize(GHUser u) throws IOException {
|
||||||
root.retrieve().withCredential().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +64,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
return new AbstractList<GHUser>() {
|
return new AbstractList<GHUser>() {
|
||||||
// these are shallow objects with only some limited values filled out
|
// these are shallow objects with only some limited values filled out
|
||||||
// TODO: it's better to allow objects to fill themselves in later when missing values are requested
|
// TODO: it's better to allow objects to fill themselves in later when missing values are requested
|
||||||
final GHUser[] shallow = root.retrieve().withCredential().to("/orgs/" + login + "/members", GHUser[].class);
|
final GHUser[] shallow = root.retrieve().to("/orgs/" + login + "/members", GHUser[].class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GHUser get(int index) {
|
public GHUser get(int index) {
|
||||||
@@ -86,7 +86,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Conceals the membership.
|
* Conceals the membership.
|
||||||
*/
|
*/
|
||||||
public void conceal(GHUser u) throws IOException {
|
public void conceal(GHUser u) throws IOException {
|
||||||
root.retrieve().withCredential().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Permission { ADMIN, PUSH, PULL }
|
public enum Permission { ADMIN, PUSH, PULL }
|
||||||
@@ -95,7 +95,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Creates a new team and assigns the repositories.
|
* Creates a new team and assigns the repositories.
|
||||||
*/
|
*/
|
||||||
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
|
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
|
||||||
Requester post = new Requester(root).withCredential().with("name", name).with("permission", p.name().toLowerCase());
|
Requester post = new Requester(root).with("name", name).with("permission", p.name().toLowerCase());
|
||||||
List<String> repo_names = new ArrayList<String>();
|
List<String> repo_names = new ArrayList<String>();
|
||||||
for (GHRepository r : repositories) {
|
for (GHRepository r : repositories) {
|
||||||
repo_names.add(r.getName());
|
repo_names.add(r.getName());
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public abstract class GHPerson {
|
|||||||
*/
|
*/
|
||||||
public GHRepository getRepository(String name) throws IOException {
|
public GHRepository getRepository(String name) throws IOException {
|
||||||
try {
|
try {
|
||||||
return root.retrieve().withCredential().to("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
|
return root.retrieve().to("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,14 @@ public class GHRepository {
|
|||||||
return root.getUser(owner.login); // because 'owner' isn't fully populated
|
return root.getUser(owner.login); // because 'owner' isn't fully populated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHIssue getIssue(int id) throws IOException {
|
||||||
|
return root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues/" + id, GHIssue.class).wrap(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHIssueBuilder createIssue(String title) {
|
||||||
|
return new GHIssueBuilder(this,title);
|
||||||
|
}
|
||||||
|
|
||||||
public List<GHIssue> getIssues(GHIssueState state) throws IOException {
|
public List<GHIssue> getIssues(GHIssueState state) throws IOException {
|
||||||
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));
|
||||||
}
|
}
|
||||||
@@ -231,7 +239,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().withCredential().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("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCollaborators(GHUser... users) throws IOException {
|
public void addCollaborators(GHUser... users) throws IOException {
|
||||||
@@ -253,7 +261,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).withCredential().method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
|
new Requester(root).method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +278,7 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, String value) throws IOException {
|
private void edit(String key, String value) throws IOException {
|
||||||
Requester requester = new Requester(root).withCredential();
|
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("/repos/" + owner.login + "/" + name);
|
||||||
@@ -313,7 +321,7 @@ public class GHRepository {
|
|||||||
* Deletes this repository.
|
* Deletes this repository.
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).withCredential().method("DELETE").to("/repos/" + owner.login + "/" + name);
|
new Requester(root).method("DELETE").to("/repos/" + owner.login + "/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -323,7 +331,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).withCredential().method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
|
return new Requester(root).method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -333,7 +341,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).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin()));
|
new Requester(root).to(String.format("/repos/%s/%s/forks?org=%s", owner.login, name, 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++) {
|
||||||
@@ -352,7 +360,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().withCredential().to("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this);
|
return root.retrieve().to("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,14 +394,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().withCredential().to(String.format("/repos/%s/%s/hooks", owner.login, name), GHHook[].class)));
|
root.retrieve().to(String.format("/repos/%s/%s/hooks", owner.login, name), 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().withCredential().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
|
return root.retrieve().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -476,8 +484,7 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.withCredential()
|
.with("state", state.name().toLowerCase(Locale.ENGLISH))
|
||||||
.with("state",state.name().toLowerCase(Locale.ENGLISH))
|
|
||||||
.with("target_url", targetUrl)
|
.with("target_url", targetUrl)
|
||||||
.with("description", description)
|
.with("description", description)
|
||||||
.to(String.format("/repos/%s/%s/statuses/%s",owner.login,this.name,sha1),GHCommitStatus.class).wrapUp(root);
|
.to(String.format("/repos/%s/%s/statuses/%s",owner.login,this.name,sha1),GHCommitStatus.class).wrapUp(root);
|
||||||
@@ -505,8 +512,7 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.withCredential()
|
.with("name", name)
|
||||||
.with("name",name)
|
|
||||||
.with("active", active)
|
.with("active", active)
|
||||||
._with("config", config)
|
._with("config", config)
|
||||||
._with("events",ea)
|
._with("events",ea)
|
||||||
@@ -610,28 +616,46 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public Map<String,GHBranch> getBranches() throws IOException {
|
public Map<String,GHBranch> getBranches() throws IOException {
|
||||||
Map<String,GHBranch> r = new TreeMap<String,GHBranch>();
|
Map<String,GHBranch> r = new TreeMap<String,GHBranch>();
|
||||||
for (GHBranch p : root.retrieve().to("/repos/" + owner.login + "/" + name + "/branches", GHBranch[].class)) {
|
for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) {
|
||||||
p.wrap(this);
|
p.wrap(this);
|
||||||
r.put(p.getName(),p);
|
r.put(p.getName(),p);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Use {@link #listMilestones(GHIssueState)}
|
||||||
|
*/
|
||||||
public Map<Integer, GHMilestone> getMilestones() throws IOException {
|
public Map<Integer, GHMilestone> getMilestones() throws IOException {
|
||||||
Map<Integer,GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();
|
Map<Integer,GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();
|
||||||
GHMilestone[] ms = root.retrieve().to("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone[].class);
|
for (GHMilestone m : listMilestones(GHIssueState.OPEN)) {
|
||||||
for (GHMilestone m : ms) {
|
|
||||||
m.owner = this;
|
|
||||||
m.root = root;
|
|
||||||
milestones.put(m.getNumber(), m);
|
milestones.put(m.getNumber(), m);
|
||||||
}
|
}
|
||||||
return milestones;
|
return milestones;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up all the milestones in this repository.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHMilestone> listMilestones(final GHIssueState state) {
|
||||||
|
return new PagedIterable<GHMilestone>() {
|
||||||
|
public PagedIterator<GHMilestone> iterator() {
|
||||||
|
return new PagedIterator<GHMilestone>(root.retrieve().asIterator(getApiTailUrl("milestones?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHMilestone[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHMilestone[] page) {
|
||||||
|
for (GHMilestone c : page)
|
||||||
|
c.wrap(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public GHMilestone getMilestone(int number) throws IOException {
|
public GHMilestone getMilestone(int number) throws IOException {
|
||||||
GHMilestone m = milestones.get(number);
|
GHMilestone m = milestones.get(number);
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
m = root.retrieve().to("/repos/" + owner.login + "/" + name + "/milestones/" + number, GHMilestone.class);
|
m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class);
|
||||||
m.owner = this;
|
m.owner = this;
|
||||||
m.root = root;
|
m.root = root;
|
||||||
milestones.put(m.getNumber(), m);
|
milestones.put(m.getNumber(), m);
|
||||||
@@ -640,8 +664,8 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestone createMilestone(String title, String description) throws IOException {
|
public GHMilestone createMilestone(String title, String description) throws IOException {
|
||||||
return new Requester(root).withCredential()
|
return new Requester(root)
|
||||||
.with("title", title).with("description", description).method("POST").to("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone.class).wrap(this);
|
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -663,4 +687,8 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getApiTailUrl(String tail) {
|
||||||
|
return "/repos/" + owner.login + "/" + name +'/'+tail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ public class GHTeam {
|
|||||||
* Retrieves the current members.
|
* Retrieves the current members.
|
||||||
*/
|
*/
|
||||||
public Set<GHUser> getMembers() throws IOException {
|
public Set<GHUser> getMembers() throws IOException {
|
||||||
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().withCredential().to(api("/members"), GHUser[].class), org.root)));
|
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().to(api("/members"), GHUser[].class), org.root)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,GHRepository> getRepositories() throws IOException {
|
public Map<String,GHRepository> getRepositories() throws IOException {
|
||||||
GHRepository[] repos = org.root.retrieve().withCredential().to(api("/repos"), GHRepository[].class);
|
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 : repos) {
|
||||||
m.put(r.getName(),r.wrap(org.root));
|
m.put(r.getName(),r.wrap(org.root));
|
||||||
@@ -62,22 +62,22 @@ public class GHTeam {
|
|||||||
* Adds a member to the team.
|
* Adds a member to the team.
|
||||||
*/
|
*/
|
||||||
public void add(GHUser u) throws IOException {
|
public void add(GHUser u) throws IOException {
|
||||||
org.root.retrieve().withCredential().method("PUT").to(api("/members/" + u.getLogin()), null);
|
org.root.retrieve().method("PUT").to(api("/members/" + u.getLogin()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a member to the team.
|
* Removes a member to the team.
|
||||||
*/
|
*/
|
||||||
public void remove(GHUser u) throws IOException {
|
public void remove(GHUser u) throws IOException {
|
||||||
org.root.retrieve().withCredential().method("DELETE").to(api("/members/" + u.getLogin()), null);
|
org.root.retrieve().method("DELETE").to(api("/members/" + u.getLogin()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(GHRepository r) throws IOException {
|
public void add(GHRepository r) throws IOException {
|
||||||
org.root.retrieve().withCredential().method("PUT").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
|
org.root.retrieve().method("PUT").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(GHRepository r) throws IOException {
|
public void remove(GHRepository r) throws IOException {
|
||||||
org.root.retrieve().withCredential().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
|
org.root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String api(String tail) {
|
private String api(String tail) {
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ public class GHUser extends GHPerson {
|
|||||||
* Follow this user.
|
* Follow this user.
|
||||||
*/
|
*/
|
||||||
public void follow() throws IOException {
|
public void follow() throws IOException {
|
||||||
new Requester(root).withCredential().method("PUT").to("/user/following/" + login);
|
new Requester(root).method("PUT").to("/user/following/" + login);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unfollow this user.
|
* Unfollow this user.
|
||||||
*/
|
*/
|
||||||
public void unfollow() throws IOException {
|
public void unfollow() throws IOException {
|
||||||
new Requester(root).withCredential().method("DELETE").to("/user/following/" + login);
|
new Requester(root).method("DELETE").to("/user/following/" + login);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -66,19 +66,22 @@ public class GitHub {
|
|||||||
private final Map<String,GHOrganization> orgs = new HashMap<String, GHOrganization>();
|
private final Map<String,GHOrganization> orgs = new HashMap<String, GHOrganization>();
|
||||||
/*package*/ String oauthAccessToken;
|
/*package*/ String oauthAccessToken;
|
||||||
|
|
||||||
private final String githubServer;
|
private final String apiUrl;
|
||||||
|
|
||||||
private GitHub(String login, String apiToken, String password) {
|
private GitHub(String login, String apiToken, String password) {
|
||||||
this ("github.com", login, apiToken, password);
|
this ("https://api.github.com", login, apiToken, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param githubServer
|
* @param apiUrl
|
||||||
* The host name of the GitHub (or GitHub enterprise) server, such as "github.com".
|
* The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or
|
||||||
|
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
|
||||||
|
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
|
||||||
*/
|
*/
|
||||||
private GitHub(String githubServer, String login, String apiToken, String password) {
|
private GitHub(String apiUrl, String login, String apiToken, String password) {
|
||||||
this.githubServer = githubServer;
|
if (apiUrl.endsWith("/")) apiUrl = apiUrl.substring(0, apiUrl.length()-1); // normalize
|
||||||
|
this.apiUrl = apiUrl;
|
||||||
this.login = login;
|
this.login = login;
|
||||||
this.apiToken = apiToken;
|
this.apiToken = apiToken;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -91,9 +94,9 @@ public class GitHub {
|
|||||||
encodedAuthorization = null;
|
encodedAuthorization = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GitHub (String githubServer, String oauthAccessToken) throws IOException {
|
private GitHub (String apiUrl, String oauthAccessToken) throws IOException {
|
||||||
|
|
||||||
this.githubServer = githubServer;
|
this.apiUrl = apiUrl;
|
||||||
this.password = null;
|
this.password = null;
|
||||||
this.encodedAuthorization = null;
|
this.encodedAuthorization = null;
|
||||||
|
|
||||||
@@ -118,6 +121,21 @@ public class GitHub {
|
|||||||
return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password"));
|
return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version that connects to GitHub Enterprise.
|
||||||
|
*
|
||||||
|
* @param apiUrl
|
||||||
|
* The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or
|
||||||
|
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
|
||||||
|
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
|
||||||
|
*/
|
||||||
|
public static GitHub connectToEnterprise(String apiUrl, String login, String apiToken) {
|
||||||
|
// not exposing password because the login process still assumes https://github.com/
|
||||||
|
// if we are to fix this, fix that by getting rid of createWebClient() and replace the e-mail service hook
|
||||||
|
// with GitHub API.
|
||||||
|
return new GitHub(apiUrl,login,apiToken,null);
|
||||||
|
}
|
||||||
|
|
||||||
public static GitHub connect(String login, String apiToken){
|
public static GitHub connect(String login, String apiToken){
|
||||||
return new GitHub(login,apiToken,null);
|
return new GitHub(login,apiToken,null);
|
||||||
}
|
}
|
||||||
@@ -153,10 +171,15 @@ public class GitHub {
|
|||||||
tailApiUrl = tailApiUrl + (tailApiUrl.indexOf('?')>=0 ?'&':'?') + "access_token=" + oauthAccessToken;
|
tailApiUrl = tailApiUrl + (tailApiUrl.indexOf('?')>=0 ?'&':'?') + "access_token=" + oauthAccessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tailApiUrl.startsWith("/"))
|
if (tailApiUrl.startsWith("/")) {
|
||||||
return new URL("https://api."+githubServer+tailApiUrl);
|
if ("github.com".equals(apiUrl)) {// backward compatibility
|
||||||
else
|
return new URL("https://api.github.com" + tailApiUrl);
|
||||||
|
} else {
|
||||||
|
return new URL(apiUrl + tailApiUrl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return new URL(tailApiUrl);
|
return new URL(tailApiUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ Requester retrieve() {
|
/*package*/ Requester retrieve() {
|
||||||
@@ -167,7 +190,7 @@ public class GitHub {
|
|||||||
* Gets the current rate limit.
|
* Gets the current rate limit.
|
||||||
*/
|
*/
|
||||||
public GHRateLimit getRateLimit() throws IOException {
|
public GHRateLimit getRateLimit() throws IOException {
|
||||||
return retrieve().withCredential().to("/rate_limit", JsonRateLimit.class).rate;
|
return retrieve().to("/rate_limit", JsonRateLimit.class).rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,7 +200,7 @@ public class GitHub {
|
|||||||
public GHMyself getMyself() throws IOException {
|
public GHMyself getMyself() throws IOException {
|
||||||
requireCredential();
|
requireCredential();
|
||||||
|
|
||||||
GHMyself u = retrieve().withCredential().to("/user", GHMyself.class);
|
GHMyself u = retrieve().to("/user", GHMyself.class);
|
||||||
|
|
||||||
u.root = this;
|
u.root = this;
|
||||||
users.put(u.getLogin(), u);
|
users.put(u.getLogin(), u);
|
||||||
@@ -227,7 +250,7 @@ public class GitHub {
|
|||||||
*/
|
*/
|
||||||
public GHRepository getRepository(String name) throws IOException {
|
public GHRepository getRepository(String name) throws IOException {
|
||||||
String[] tokens = name.split("/");
|
String[] tokens = name.split("/");
|
||||||
return getUser(tokens[0]).getRepository(tokens[1]);
|
return retrieve().to("/repos/" + tokens[0] + '/' + tokens[1], GHRepository.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,7 +260,7 @@ public class GitHub {
|
|||||||
* TODO: make this automatic.
|
* TODO: make this automatic.
|
||||||
*/
|
*/
|
||||||
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
|
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
|
||||||
GHOrganization[] orgs = retrieve().withCredential().to("/user/orgs", GHOrganization[].class);
|
GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class);
|
||||||
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
|
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
|
||||||
for (GHOrganization o : orgs) {
|
for (GHOrganization o : orgs) {
|
||||||
// don't put 'o' into orgs because they are shallow
|
// don't put 'o' into orgs because they are shallow
|
||||||
@@ -277,7 +300,7 @@ public class GitHub {
|
|||||||
* Newly created repository.
|
* Newly created repository.
|
||||||
*/
|
*/
|
||||||
public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException {
|
public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException {
|
||||||
Requester requester = new Requester(this).withCredential()
|
Requester requester = new Requester(this)
|
||||||
.with("name", name).with("description", description).with("homepage", homepage)
|
.with("name", name).with("description", description).with("homepage", homepage)
|
||||||
.with("public", isPublic ? 1 : 0);
|
.with("public", isPublic ? 1 : 0);
|
||||||
return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this);
|
return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this);
|
||||||
@@ -288,7 +311,7 @@ public class GitHub {
|
|||||||
*/
|
*/
|
||||||
public boolean isCredentialValid() throws IOException {
|
public boolean isCredentialValid() throws IOException {
|
||||||
try {
|
try {
|
||||||
retrieve().withCredential().to("/user", GHUser.class);
|
retrieve().to("/user", GHUser.class);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterator over a pagenated data source.
|
* Iterator over a pagenated data source.
|
||||||
@@ -28,17 +29,24 @@ public abstract class PagedIterator<T> implements Iterator<T> {
|
|||||||
protected abstract void wrapUp(T[] page);
|
protected abstract void wrapUp(T[] page);
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return (current!=null && pos<current.length) || base.hasNext();
|
fetch();
|
||||||
|
return current!=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T next() {
|
public T next() {
|
||||||
fetch();
|
fetch();
|
||||||
|
if (current==null) throw new NoSuchElementException();
|
||||||
return current[pos++];
|
return current[pos++];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetch() {
|
private void fetch() {
|
||||||
while (current==null || current.length<=pos) {
|
while (current==null || current.length<=pos) {
|
||||||
|
if (!base.hasNext()) {// no more to retrieve
|
||||||
|
current = null;
|
||||||
|
pos = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
current = base.next();
|
current = base.next();
|
||||||
wrapUp(current);
|
wrapUp(current);
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import static org.kohsuke.github.GitHub.*;
|
|||||||
class Requester {
|
class Requester {
|
||||||
private final GitHub root;
|
private final GitHub root;
|
||||||
private final List<Entry> args = new ArrayList<Entry>();
|
private final List<Entry> args = new ArrayList<Entry>();
|
||||||
private boolean authenticate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request method.
|
* Request method.
|
||||||
@@ -79,10 +78,10 @@ class Requester {
|
|||||||
/**
|
/**
|
||||||
* Makes a request with authentication credential.
|
* Makes a request with authentication credential.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Requester withCredential() {
|
public Requester withCredential() {
|
||||||
// keeping it inline with retrieveWithAuth not to enforce the check
|
// keeping it inline with retrieveWithAuth not to enforce the check
|
||||||
// root.requireCredential();
|
// root.requireCredential();
|
||||||
authenticate = true;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +268,7 @@ class Requester {
|
|||||||
// 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.)
|
||||||
// if OAuth token is present, it'll be set in the URL, so need to set the Authorization header
|
// if OAuth token is present, it'll be set in the URL, so need to set the Authorization header
|
||||||
if (authenticate && root.encodedAuthorization!=null && root.oauthAccessToken == null)
|
if (root.encodedAuthorization!=null && root.oauthAccessToken == null)
|
||||||
uc.setRequestProperty("Authorization", "Basic " + root.encodedAuthorization);
|
uc.setRequestProperty("Authorization", "Basic " + root.encodedAuthorization);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import junit.framework.TestCase;
|
|||||||
import org.kohsuke.github.GHCommit;
|
import org.kohsuke.github.GHCommit;
|
||||||
import org.kohsuke.github.GHCommit.File;
|
import org.kohsuke.github.GHCommit.File;
|
||||||
import org.kohsuke.github.GHCommitComment;
|
import org.kohsuke.github.GHCommitComment;
|
||||||
import org.kohsuke.github.GHCommitState;
|
|
||||||
import org.kohsuke.github.GHCommitStatus;
|
import org.kohsuke.github.GHCommitStatus;
|
||||||
import org.kohsuke.github.GHEvent;
|
import org.kohsuke.github.GHEvent;
|
||||||
import org.kohsuke.github.GHEventInfo;
|
import org.kohsuke.github.GHEventInfo;
|
||||||
@@ -12,8 +11,10 @@ import org.kohsuke.github.GHEventPayload;
|
|||||||
import org.kohsuke.github.GHHook;
|
import org.kohsuke.github.GHHook;
|
||||||
import org.kohsuke.github.GHBranch;
|
import org.kohsuke.github.GHBranch;
|
||||||
import org.kohsuke.github.GHIssue;
|
import org.kohsuke.github.GHIssue;
|
||||||
|
import org.kohsuke.github.GHIssueComment;
|
||||||
import org.kohsuke.github.GHIssueState;
|
import org.kohsuke.github.GHIssueState;
|
||||||
import org.kohsuke.github.GHKey;
|
import org.kohsuke.github.GHKey;
|
||||||
|
import org.kohsuke.github.GHMilestone;
|
||||||
import org.kohsuke.github.GHMyself;
|
import org.kohsuke.github.GHMyself;
|
||||||
import org.kohsuke.github.GHOrganization;
|
import org.kohsuke.github.GHOrganization;
|
||||||
import org.kohsuke.github.GHOrganization.Permission;
|
import org.kohsuke.github.GHOrganization.Permission;
|
||||||
@@ -23,7 +24,6 @@ import org.kohsuke.github.GHTeam;
|
|||||||
import org.kohsuke.github.GHUser;
|
import org.kohsuke.github.GHUser;
|
||||||
import org.kohsuke.github.GitHub;
|
import org.kohsuke.github.GitHub;
|
||||||
import org.kohsuke.github.PagedIterable;
|
import org.kohsuke.github.PagedIterable;
|
||||||
import org.kohsuke.github.PagedIterator;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -51,6 +51,26 @@ public class AppTest extends TestCase {
|
|||||||
assertFalse(GitHub.connect("totally", "bogus").isCredentialValid());
|
assertFalse(GitHub.connect("totally", "bogus").isCredentialValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testIssueWithNoComment() throws IOException {
|
||||||
|
GHRepository repository = GitHub.connect().getRepository("kohsuke/test");
|
||||||
|
List<GHIssueComment> v = repository.getIssue(4).getComments();
|
||||||
|
System.out.println(v);
|
||||||
|
assertTrue(v.isEmpty());
|
||||||
|
|
||||||
|
v = repository.getIssue(3).getComments();
|
||||||
|
System.out.println(v);
|
||||||
|
assertTrue(v.size()==3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreateIssue() throws IOException {
|
||||||
|
GHUser u = GitHub.connect().getUser("kohsuke");
|
||||||
|
GHRepository r = u.getRepository("test");
|
||||||
|
GHMilestone someMilestone = r.listMilestones(GHIssueState.CLOSED).iterator().next();
|
||||||
|
GHIssue o = r.createIssue("testing").body("this is body").assignee(u).label("bug").label("question").milestone(someMilestone).create();
|
||||||
|
System.out.println(o.getUrl());
|
||||||
|
o.close();
|
||||||
|
}
|
||||||
|
|
||||||
public void testRateLimit() throws IOException {
|
public void testRateLimit() throws IOException {
|
||||||
System.out.println(GitHub.connect().getRateLimit());
|
System.out.println(GitHub.connect().getRateLimit());
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/test/java/org/kohsuke/github/GitHubTest.java
Normal file
24
src/test/java/org/kohsuke/github/GitHubTest.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for {@link GitHub}.
|
||||||
|
*/
|
||||||
|
public class GitHubTest extends TestCase {
|
||||||
|
|
||||||
|
public void testGitHubServerWithHttp() throws Exception {
|
||||||
|
GitHub hub = GitHub.connectToEnterprise("http://enterprise.kohsuke.org/api/v3", "kohsuke", "token");
|
||||||
|
assertEquals("http://enterprise.kohsuke.org/api/v3/test", hub.getApiURL("/test").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGitHubServerWithHttps() throws Exception {
|
||||||
|
GitHub hub = GitHub.connectToEnterprise("https://enterprise.kohsuke.org/api/v3", "kohsuke", "token");
|
||||||
|
assertEquals("https://enterprise.kohsuke.org/api/v3/test", hub.getApiURL("/test").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGitHubServerWithoutServer() throws Exception {
|
||||||
|
GitHub hub = GitHub.connect("kohsuke", "token", "password");
|
||||||
|
assertEquals("https://api.github.com/test", hub.getApiURL("/test").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user