mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-21 15:50:49 +00:00
Compare commits
18 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0cf1ac605 | ||
|
|
9a19d07ab8 | ||
|
|
922be0b164 | ||
|
|
d0b8e2e37e | ||
|
|
e3d6e08b6a | ||
|
|
16a6623095 | ||
|
|
7bf31ca149 | ||
|
|
030f2360ca | ||
|
|
08eafc4214 | ||
|
|
134ece9385 | ||
|
|
3e4b06e959 | ||
|
|
3e3c6f70ba | ||
|
|
3097378a10 | ||
|
|
53f7a0f78a | ||
|
|
45a6841772 | ||
|
|
80b93a6e33 | ||
|
|
6aaab641be | ||
|
|
4999490c06 |
10
pom.xml
10
pom.xml
@@ -3,11 +3,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>pom</artifactId>
|
<artifactId>pom</artifactId>
|
||||||
<version>6</version>
|
<version>8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.53</version>
|
<version>1.55</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>http://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>github-api-1.53</tag>
|
<tag>github-api-1.55</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.infradna.tool</groupId>
|
<groupId>com.infradna.tool</groupId>
|
||||||
<artifactId>bridge-method-injector</artifactId>
|
<artifactId>bridge-method-injector</artifactId>
|
||||||
<version>1.8</version>
|
<version>1.12</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.infradna.tool</groupId>
|
<groupId>com.infradna.tool</groupId>
|
||||||
<artifactId>bridge-method-annotation</artifactId>
|
<artifactId>bridge-method-annotation</artifactId>
|
||||||
<version>1.8</version>
|
<version>1.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kohsuke.stapler</groupId>
|
<groupId>org.kohsuke.stapler</groupId>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class GHCommitStatus {
|
|||||||
String target_url,description;
|
String target_url,description;
|
||||||
int id;
|
int id;
|
||||||
String url;
|
String url;
|
||||||
|
String context;
|
||||||
GHUser creator;
|
GHUser creator;
|
||||||
|
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
@@ -69,4 +70,8 @@ public class GHCommitStatus {
|
|||||||
public GHUser getCreator() {
|
public GHUser getCreator() {
|
||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
|
||||||
@@ -8,7 +10,9 @@ import javax.xml.bind.DatatypeConverter;
|
|||||||
* A Content of a repository.
|
* A Content of a repository.
|
||||||
*
|
*
|
||||||
* @author Alexandre COLLIGNON
|
* @author Alexandre COLLIGNON
|
||||||
|
* @see GHRepository#getFileContent(String)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public class GHContent {
|
public class GHContent {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
@@ -105,6 +109,25 @@ public class GHContent {
|
|||||||
return "dir".equals(type);
|
return "dir".equals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List immediate children of this directory.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHContent> listDirectoryContent() throws IOException {
|
||||||
|
if (!isDirectory())
|
||||||
|
throw new IllegalStateException(path+" is not a directory");
|
||||||
|
|
||||||
|
return new PagedIterable<GHContent>() {
|
||||||
|
public PagedIterator<GHContent> iterator() {
|
||||||
|
return new PagedIterator<GHContent>(owner.root.retrieve().asIterator(url, GHContent[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHContent[] page) {
|
||||||
|
GHContent.wrap(page,owner);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
|
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
|
||||||
return update(newContent, commitMessage, null);
|
return update(newContent, commitMessage, null);
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/main/java/org/kohsuke/github/GHDeployKey.java
Normal file
46
src/main/java/org/kohsuke/github/GHDeployKey.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||||
|
|
||||||
|
public class GHDeployKey {
|
||||||
|
|
||||||
|
protected String url, key, title;
|
||||||
|
protected boolean verified;
|
||||||
|
protected int id;
|
||||||
|
private GHRepository owner;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVerified() {
|
||||||
|
return verified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHDeployKey wrap(GHRepository repo) {
|
||||||
|
this.owner = repo;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(owner.root).method("DELETE").to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -561,7 +561,19 @@ public class GHRepository {
|
|||||||
public GHRef[] getRefs(String refType) throws IOException {
|
public GHRef[] getRefs(String refType) throws IOException {
|
||||||
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class);
|
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Retrive a ref of the given type for the current GitHub repository.
|
||||||
|
*
|
||||||
|
* @param refName
|
||||||
|
* eg: heads/branch
|
||||||
|
* @return refs matching the request type
|
||||||
|
* @throws IOException
|
||||||
|
* on failure communicating with GitHub, potentially due to an
|
||||||
|
* invalid ref type being requested
|
||||||
|
*/
|
||||||
|
public GHRef getRef(String refName) throws IOException {
|
||||||
|
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Gets a commit object in this repository.
|
* Gets a commit object in this repository.
|
||||||
*/
|
*/
|
||||||
@@ -646,15 +658,25 @@ public class GHRepository {
|
|||||||
* Optional parameter that points to the URL that has more details.
|
* Optional parameter that points to the URL that has more details.
|
||||||
* @param description
|
* @param description
|
||||||
* Optional short description.
|
* Optional short description.
|
||||||
|
* @param context
|
||||||
|
* Optinal commit status context.
|
||||||
*/
|
*/
|
||||||
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException {
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.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)
|
||||||
|
.with("context", context)
|
||||||
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link #createCommitStatus(String, GHCommitState,String,String,String) createCommitStatus}
|
||||||
|
*/
|
||||||
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
||||||
|
return createCommitStatus(sha1, state, targetUrl, description,null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists repository events.
|
* Lists repository events.
|
||||||
*/
|
*/
|
||||||
@@ -908,6 +930,22 @@ public class GHRepository {
|
|||||||
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
|
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHDeployKey addDeployKey(String title,String key) throws IOException {
|
||||||
|
return new Requester(root)
|
||||||
|
.with("title", title).with("key", key).method("POST").to(getApiTailUrl("keys"), GHDeployKey.class).wrap(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GHDeployKey> getDeployKeys() throws IOException{
|
||||||
|
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(
|
||||||
|
root.retrieve().to(String.format("/repos/%s/%s/keys", owner.login, name), GHDeployKey[].class)));
|
||||||
|
for (GHDeployKey h : list)
|
||||||
|
h.wrap(this);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Repository:"+owner.login+":"+name;
|
return "Repository:"+owner.login+":"+name;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -20,6 +21,9 @@ import org.junit.Test;
|
|||||||
import org.kohsuke.github.GHCommit.File;
|
import org.kohsuke.github.GHCommit.File;
|
||||||
import org.kohsuke.github.GHOrganization.Permission;
|
import org.kohsuke.github.GHOrganization.Permission;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -529,6 +533,52 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRef() throws IOException {
|
||||||
|
GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master");
|
||||||
|
assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void directoryListing() throws IOException {
|
||||||
|
List<GHContent> children = gitHub.getRepository("jenkinsci/jenkins").getDirectoryContent("core");
|
||||||
|
for (GHContent c : children) {
|
||||||
|
System.out.println(c.getName());
|
||||||
|
if (c.isDirectory()) {
|
||||||
|
for (GHContent d : c.listDirectoryContent()) {
|
||||||
|
System.out.println(" "+d.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddDeployKey() throws IOException {
|
||||||
|
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(),0);
|
||||||
|
final GHDeployKey newDeployKey = myRepository.addDeployKey("test", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUt0RAycC5cS42JKh6SecfFZBR1RrF+2hYMctz4mk74/arBE+wFb7fnSHGzdGKX2h5CFOWODifRCJVhB7hlVxodxe+QkQQYAEL/x1WVCJnGgTGQGOrhOMj95V3UE5pQKhsKD608C+u5tSofcWXLToP1/wZ7U4/AHjqYi08OLsWToHCax55TZkvdt2jo0hbIoYU+XI9Q8Uv4ONDN1oabiOdgeKi8+crvHAuvNleiBhWVBzFh8KdfzaH5uNdw7ihhFjEd1vzqACsjCINCjdMfzl6jD9ExuWuE92nZJnucls2cEoNC6k2aPmrZDg9hA32FXVpyseY+bDUWFU6LO2LG6PB kohsuke@atlas");
|
||||||
|
try {
|
||||||
|
assertNotNull(newDeployKey.getId());
|
||||||
|
|
||||||
|
GHDeployKey k = Iterables.find(myRepository.getDeployKeys(), new Predicate<GHDeployKey>() {
|
||||||
|
public boolean apply(GHDeployKey deployKey) {
|
||||||
|
return newDeployKey.getId() == deployKey.getId();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assertNotNull(k);
|
||||||
|
} finally {
|
||||||
|
newDeployKey.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommitStatusContext() throws IOException {
|
||||||
|
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(), 0);
|
||||||
|
GHRef masterRef = myRepository.getRef("heads/master");
|
||||||
|
GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
|
||||||
|
assertEquals("test/context", commitStatus.getContext());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void kohsuke() {
|
private void kohsuke() {
|
||||||
String login = getUser().getLogin();
|
String login = getUser().getLogin();
|
||||||
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
||||||
|
|||||||
Reference in New Issue
Block a user