mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 08:21:23 +00:00
Compare commits
118 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db845850b2 | ||
|
|
d516597659 | ||
|
|
3af5a8145a | ||
|
|
31bebd4a7a | ||
|
|
ccb87258b0 | ||
|
|
2ab71e88bd | ||
|
|
78bd7585bb | ||
|
|
92cc81d9b8 | ||
|
|
97a1c741de | ||
|
|
077d693959 | ||
|
|
94831fc10a | ||
|
|
1f298a88b0 | ||
|
|
7e49946bed | ||
|
|
1e81ab1017 | ||
|
|
311180d12e | ||
|
|
0efb206881 | ||
|
|
0b92fa5615 | ||
|
|
a58a5b56b2 | ||
|
|
b9764c0a44 | ||
|
|
590f7ba511 | ||
|
|
449909b0e8 | ||
|
|
40780525f8 | ||
|
|
0e3707d1c3 | ||
|
|
8ddbef093b | ||
|
|
4ccdfccdf0 | ||
|
|
3c8aa0c630 | ||
|
|
ba519f996a | ||
|
|
62d9b92e6e | ||
|
|
d2c909584d | ||
|
|
219916eb14 | ||
|
|
0a37ac901f | ||
|
|
4586baea27 | ||
|
|
d83961e85b | ||
|
|
7e35716ff0 | ||
|
|
d0cf1ac605 | ||
|
|
9a19d07ab8 | ||
|
|
922be0b164 | ||
|
|
d0b8e2e37e | ||
|
|
e3d6e08b6a | ||
|
|
16a6623095 | ||
|
|
7bf31ca149 | ||
|
|
030f2360ca | ||
|
|
08eafc4214 | ||
|
|
134ece9385 | ||
|
|
3e4b06e959 | ||
|
|
3e3c6f70ba | ||
|
|
3097378a10 | ||
|
|
53f7a0f78a | ||
|
|
45a6841772 | ||
|
|
80b93a6e33 | ||
|
|
6aaab641be | ||
|
|
4999490c06 | ||
|
|
c7c1cd8bb3 | ||
|
|
8a1f116305 | ||
|
|
f8fe1dda6d | ||
|
|
bf44232d5c | ||
|
|
8c8ba47ef9 | ||
|
|
b3580002d0 | ||
|
|
1249199b22 | ||
|
|
f39a47f354 | ||
|
|
f58f15925f | ||
|
|
a071f8bb86 | ||
|
|
d33609ee57 | ||
|
|
f2c08bc1e8 | ||
|
|
688d8ed7bc | ||
|
|
2ddb4018b8 | ||
|
|
3ec25683f7 | ||
|
|
25d426f483 | ||
|
|
9d91ebc47a | ||
|
|
c784ab6632 | ||
|
|
ed5e3f13a1 | ||
|
|
3dcd82745e | ||
|
|
c564dc5f29 | ||
|
|
d64453b661 | ||
|
|
834ed7db0e | ||
|
|
db1dde533f | ||
|
|
9c66d9465e | ||
|
|
8c193d004e | ||
|
|
7cbd7f999a | ||
|
|
4340c8cb00 | ||
|
|
6f6583772d | ||
|
|
c62bc8d5da | ||
|
|
f68bfcb3e2 | ||
|
|
a37ade13cd | ||
|
|
1e0129f2d8 | ||
|
|
2e1d4381b0 | ||
|
|
a409b4f49c | ||
|
|
926776204b | ||
|
|
bba490127d | ||
|
|
80672c43c0 | ||
|
|
926e0ea0e5 | ||
|
|
6da169cd56 | ||
|
|
aaf10aa118 | ||
|
|
145bdacf13 | ||
|
|
51309efd46 | ||
|
|
60fe143b07 | ||
|
|
3f921b69f6 | ||
|
|
d2ac81d7ba | ||
|
|
2e5a9479a8 | ||
|
|
ec664ab6a2 | ||
|
|
8818bf8cf0 | ||
|
|
cc53e0c8ff | ||
|
|
8353499d18 | ||
|
|
d2c5994616 | ||
|
|
500b9097f7 | ||
|
|
7993266e6e | ||
|
|
74090103a9 | ||
|
|
a18cde2340 | ||
|
|
ee98e97876 | ||
|
|
ff63bafd72 | ||
|
|
3f8c8be77a | ||
|
|
769cdc73e7 | ||
|
|
cef8f74c00 | ||
|
|
9f5ab709de | ||
|
|
9c02f918c1 | ||
|
|
15c5c9615e | ||
|
|
0b74692d62 | ||
|
|
8f24f55eb7 |
22
LICENSE.txt
Normal file
22
LICENSE.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Copyright (c) 2011- Kohsuke Kawaguchi and other contributors
|
||||||
|
|
||||||
|
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.
|
||||||
35
pom.xml
35
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>10</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.50</version>
|
<version>1.58</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>http://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>HEAD</tag>
|
<tag>github-api-1.58</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,8 +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>
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kohsuke.stapler</groupId>
|
<groupId>org.kohsuke.stapler</groupId>
|
||||||
@@ -92,6 +91,23 @@
|
|||||||
<version>3.1.0.201310021548-r</version>
|
<version>3.1.0.201310021548-r</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp</groupId>
|
||||||
|
<artifactId>okhttp-urlconnection</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.kohsuke</groupId>
|
||||||
|
<artifactId>wordnet-random-name</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-all</artifactId>
|
||||||
|
<version>1.9.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@@ -115,4 +131,11 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The MIT license</name>
|
||||||
|
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
105
src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java
Normal file
105
src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds up query for listing commits.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Call various methods that set the filter criteria, then {@link #list()} method to actually list up the commit.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* GHRepository r = ...;
|
||||||
|
* for (GHCommit c : r.queryCommits().since(x).until(y).author("kohsuke")) {
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHRepository#queryCommits()
|
||||||
|
*/
|
||||||
|
public class GHCommitQueryBuilder {
|
||||||
|
private final Requester req;
|
||||||
|
private final GHRepository repo;
|
||||||
|
|
||||||
|
/*package*/ GHCommitQueryBuilder(GHRepository repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
this.req = repo.root.retrieve(); // requester to build up
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GItHub login or email address by which to filter by commit author.
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder author(String author) {
|
||||||
|
req.with("author",author);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only commits containing this file path will be returned.
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder path(String path) {
|
||||||
|
req.with("path",path);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the SHA1 commit / tag / branch / etc to start listing commits from.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder from(String ref) {
|
||||||
|
req.with("sha",ref);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHCommitQueryBuilder pageSize(int pageSize) {
|
||||||
|
req.with("per_page",pageSize);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only commits after this date will be returned
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder since(Date dt) {
|
||||||
|
req.with("since",GitHub.printDate(dt));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only commits after this date will be returned
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder since(long timestamp) {
|
||||||
|
return since(new Date(timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only commits before this date will be returned
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder until(Date dt) {
|
||||||
|
req.with("until",GitHub.printDate(dt));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only commits before this date will be returned
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder until(long timestamp) {
|
||||||
|
return until(new Date(timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up the commits with the criteria built so far.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHCommit> list() {
|
||||||
|
return new PagedIterable<GHCommit>() {
|
||||||
|
public PagedIterator<GHCommit> iterator() {
|
||||||
|
return new PagedIterator<GHCommit>(req.asIterator(repo.getApiTailUrl("commits"), GHCommit[].class)) {
|
||||||
|
protected void wrapUp(GHCommit[] page) {
|
||||||
|
for (GHCommit c : page)
|
||||||
|
c.wrapUp(repo);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package org.kohsuke.github;
|
|||||||
* The response that is returned when updating
|
* The response that is returned when updating
|
||||||
* repository content.
|
* repository content.
|
||||||
**/
|
**/
|
||||||
public final class GHContentUpdateResponse {
|
public class GHContentUpdateResponse {
|
||||||
private GHContent content;
|
private GHContent content;
|
||||||
private GHCommit commit;
|
private GHCommit commit;
|
||||||
|
|
||||||
|
|||||||
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/main/java/org/kohsuke/github/GHEmail.java
Normal file
69
src/main/java/org/kohsuke/github/GHEmail.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010, Kohsuke Kawaguchi
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an email of GitHub.
|
||||||
|
*
|
||||||
|
* @author Kelly Campbell
|
||||||
|
*/
|
||||||
|
public class GHEmail {
|
||||||
|
|
||||||
|
protected String email;
|
||||||
|
protected boolean primary;
|
||||||
|
protected boolean verified;
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrimary() {
|
||||||
|
return primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVerified() {
|
||||||
|
return verified;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Email:"+email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return email.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof GHEmail) {
|
||||||
|
GHEmail that = (GHEmail) obj;
|
||||||
|
return this.email.equals(that.email);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ public enum GHEvent {
|
|||||||
COMMIT_COMMENT,
|
COMMIT_COMMENT,
|
||||||
CREATE,
|
CREATE,
|
||||||
DELETE,
|
DELETE,
|
||||||
|
DEPLOYMENT,
|
||||||
|
DEPLOYMENT_STATUS,
|
||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
FOLLOW,
|
FOLLOW,
|
||||||
FORK,
|
FORK,
|
||||||
@@ -25,6 +27,8 @@ public enum GHEvent {
|
|||||||
PULL_REQUEST,
|
PULL_REQUEST,
|
||||||
PULL_REQUEST_REVIEW_COMMENT,
|
PULL_REQUEST_REVIEW_COMMENT,
|
||||||
PUSH,
|
PUSH,
|
||||||
|
RELEASE,
|
||||||
|
STATUS,
|
||||||
TEAM_ADD,
|
TEAM_ADD,
|
||||||
WATCH
|
WATCH
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public abstract class GHEventPayload {
|
|||||||
@Override
|
@Override
|
||||||
void wrapUp(GitHub root) {
|
void wrapUp(GitHub root) {
|
||||||
super.wrapUp(root);
|
super.wrapUp(root);
|
||||||
|
if (pull_request==null)
|
||||||
|
throw new IllegalStateException("Expected pull_request payload, but got something else. Maybe we've got another type of event?");
|
||||||
if (repository!=null) {
|
if (repository!=null) {
|
||||||
repository.wrap(root);
|
repository.wrap(root);
|
||||||
pull_request.wrap(repository);
|
pull_request.wrap(repository);
|
||||||
|
|||||||
200
src/main/java/org/kohsuke/github/GHGist.java
Normal file
200
src/main/java/org/kohsuke/github/GHGist.java
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gist
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHUser#listGists()
|
||||||
|
* @see GitHub#getGist(String)
|
||||||
|
* @see GitHub#createGist()
|
||||||
|
*/
|
||||||
|
public class GHGist {
|
||||||
|
/*package almost final*/ GHUser owner;
|
||||||
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
|
private String url, forks_url, commits_url, id, git_pull_url, git_push_url, html_url;
|
||||||
|
|
||||||
|
@JsonProperty("public")
|
||||||
|
private boolean _public;
|
||||||
|
|
||||||
|
private String created_at, updated_at, description;
|
||||||
|
|
||||||
|
private int comments;
|
||||||
|
|
||||||
|
private String comments_url;
|
||||||
|
|
||||||
|
private Map<String,GHGistFile> files = new HashMap<String, GHGistFile>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User that owns this Gist.
|
||||||
|
*/
|
||||||
|
public GHUser getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API URL of this gist, such as 'https://api.github.com/gists/12345'
|
||||||
|
*/
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getForksUrl() {
|
||||||
|
return forks_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommitsUrl() {
|
||||||
|
return commits_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID of this gist, such as '12345'
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL like https://gist.github.com/gists/12345.git
|
||||||
|
*/
|
||||||
|
public String getGitPullUrl() {
|
||||||
|
return git_pull_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGitPushUrl() {
|
||||||
|
return git_push_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHtmlUrl() {
|
||||||
|
return html_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPublic() {
|
||||||
|
return _public;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedAt() {
|
||||||
|
return GitHub.parseDate(created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedAt() {
|
||||||
|
return GitHub.parseDate(updated_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCommentCount() {
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API URL of listing comments.
|
||||||
|
*/
|
||||||
|
public String getCommentsUrl() {
|
||||||
|
return comments_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHGistFile getFile(String name) {
|
||||||
|
return files.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String,GHGistFile> getFiles() {
|
||||||
|
return Collections.unmodifiableMap(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ GHGist wrapUp(GHUser owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.root = owner.root;
|
||||||
|
wrapUp();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used when caller obtains {@link GHGist} without knowing its owner.
|
||||||
|
* A partially constructed owner object is interned.
|
||||||
|
*/
|
||||||
|
/*package*/ GHGist wrapUp(GitHub root) throws IOException {
|
||||||
|
this.owner = root.getUser(owner);
|
||||||
|
this.root = root;
|
||||||
|
wrapUp();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void wrapUp() {
|
||||||
|
for (Entry<String, GHGistFile> e : files.entrySet()) {
|
||||||
|
e.getValue().fileName = e.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String getApiTailUrl(String tail) {
|
||||||
|
return "/gists/" + id + '/' + tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void star() throws IOException {
|
||||||
|
new Requester(root).method("PUT").to(getApiTailUrl("star"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unstar() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to(getApiTailUrl("star"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStarred() throws IOException {
|
||||||
|
return root.retrieve().asHttpStatusCode(getApiTailUrl("star"))/100==2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forks this gist into your own.
|
||||||
|
*/
|
||||||
|
public GHGist fork() throws IOException {
|
||||||
|
return new Requester(root).to(getApiTailUrl("forks"),GHGist.class).wrapUp(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedIterable<GHGist> listForks() {
|
||||||
|
return new PagedIterable<GHGist>() {
|
||||||
|
public PagedIterator<GHGist> iterator() {
|
||||||
|
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHGist[] page) {
|
||||||
|
try {
|
||||||
|
for (GHGist c : page)
|
||||||
|
c.wrapUp(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes this gist.
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to("/gists/" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
GHGist ghGist = (GHGist) o;
|
||||||
|
return id.equals(ghGist.id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id.hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/main/java/org/kohsuke/github/GHGistBuilder.java
Normal file
48
src/main/java/org/kohsuke/github/GHGistBuilder.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder pattern for creating a new Gist.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GitHub#createGist()
|
||||||
|
*/
|
||||||
|
public class GHGistBuilder {
|
||||||
|
private final GitHub root;
|
||||||
|
private final Requester req;
|
||||||
|
private final LinkedHashMap<String,Object> files = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
|
public GHGistBuilder(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
req = new Requester(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHGistBuilder description(String desc) {
|
||||||
|
req.with("description",desc);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHGistBuilder public_(boolean v) {
|
||||||
|
req.with("public",v);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new file.
|
||||||
|
*/
|
||||||
|
public GHGistBuilder file(String fileName, String content) {
|
||||||
|
files.put(fileName, Collections.singletonMap("content", content));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Gist based on the parameters specified thus far.
|
||||||
|
*/
|
||||||
|
public GHGist create() throws IOException {
|
||||||
|
req._with("files",files);
|
||||||
|
return req.to("/gists",GHGist.class).wrapUp(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
60
src/main/java/org/kohsuke/github/GHGistFile.java
Normal file
60
src/main/java/org/kohsuke/github/GHGistFile.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A file inside {@link GHGist}
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHGist#getFile(String)
|
||||||
|
* @see GHGist#getFiles()
|
||||||
|
*/
|
||||||
|
public class GHGistFile {
|
||||||
|
/*package almost final*/ String fileName;
|
||||||
|
|
||||||
|
private int size;
|
||||||
|
private String raw_url, type, language, content;
|
||||||
|
private boolean truncated;
|
||||||
|
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File size in bytes.
|
||||||
|
*/
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL that serves this file as-is.
|
||||||
|
*/
|
||||||
|
public String getRawUrl() {
|
||||||
|
return raw_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content type of this Gist, such as "text/plain"
|
||||||
|
*/
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content of this file.
|
||||||
|
*/
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (?) indicates if {@link #getContent()} contains a truncated content.
|
||||||
|
*/
|
||||||
|
public boolean isTruncated() {
|
||||||
|
return truncated;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public final class GHHook {
|
public class GHHook {
|
||||||
/**
|
/**
|
||||||
* Repository that the hook belongs to.
|
* Repository that the hook belongs to.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -16,18 +17,31 @@ import java.util.TreeMap;
|
|||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHMyself extends GHUser {
|
public class GHMyself extends GHUser {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Use {@link #getEmails2()}
|
||||||
|
*/
|
||||||
|
public List<String> getEmails() throws IOException {
|
||||||
|
List<GHEmail> src = getEmails2();
|
||||||
|
List<String> r = new ArrayList<String>(src.size());
|
||||||
|
for (GHEmail e : src) {
|
||||||
|
r.add(e.getEmail());
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the read-only list of e-mail addresses configured for you.
|
* Returns the read-only list of e-mail addresses configured for you.
|
||||||
*
|
*
|
||||||
* This corresponds to the stuff you configure in https://github.com/settings/emails,
|
* This corresponds to the stuff you configure in https://github.com/settings/emails,
|
||||||
* and not to be confused with {@link #getEmail()} that shows your public e-mail address
|
* and not to be confused with {@link #getEmail()} that shows your public e-mail address
|
||||||
* set in https://github.com/settings/profile
|
* set in https://github.com/settings/profile
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* Always non-null.
|
* Always non-null.
|
||||||
*/
|
*/
|
||||||
public List<String> getEmails() throws IOException {
|
public List<GHEmail> getEmails2() throws IOException {
|
||||||
String[] addresses = root.retrieve().to("/user/emails", String[].class);
|
GHEmail[] addresses = root.retrieve().to("/user/emails", GHEmail[].class);
|
||||||
return Collections.unmodifiableList(Arrays.asList(addresses));
|
return Collections.unmodifiableList(Arrays.asList(addresses));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,11 +101,24 @@ public class GHMyself extends GHUser {
|
|||||||
* Lists up all repositories this user owns (public and private).
|
* Lists up all repositories this user owns (public and private).
|
||||||
*
|
*
|
||||||
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned.
|
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned.
|
||||||
|
* Repositories are returned by GitHub API with a 30 items per page.
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listAllRepositories() {
|
@Override
|
||||||
|
public PagedIterable<GHRepository> listRepositories() {
|
||||||
|
return listRepositories(30);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up all the repositories this user owns (public and private) 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>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> iterator() {
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos", GHRepository[].class)) {
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos?per_page=" + pageSize, GHRepository[].class)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
@@ -102,6 +129,14 @@ public class GHMyself extends GHUser {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Use {@link #listRepositories()}
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHRepository> listAllRepositories() {
|
||||||
|
return listRepositories();
|
||||||
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
|
|||||||
@@ -23,10 +23,15 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Newly created repository.
|
* Newly created repository.
|
||||||
*/
|
*/
|
||||||
public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException {
|
public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException {
|
||||||
return createRepository(name,description,homepage,getTeams().get(team),isPublic);
|
GHTeam t = getTeams().get(team);
|
||||||
|
if (t==null)
|
||||||
|
throw new IllegalArgumentException("No such team: "+team);
|
||||||
|
return createRepository(name,description,homepage,t,isPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
if (team==null)
|
||||||
|
throw new IllegalArgumentException("Invalid team");
|
||||||
// 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)
|
return new Requester(root)
|
||||||
.with("name", name).with("description", description).with("homepage", homepage)
|
.with("name", name).with("description", description).with("homepage", homepage)
|
||||||
@@ -37,14 +42,41 @@ 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().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 : listTeams()) {
|
||||||
r.put(t.getName(),t.wrapUp(this));
|
r.put(t.getName(),t);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List up all the teams.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHTeam> listTeams() throws IOException {
|
||||||
|
return new PagedIterable<GHTeam>() {
|
||||||
|
public PagedIterator<GHTeam> iterator() {
|
||||||
|
return new PagedIterator<GHTeam>(root.retrieve().asIterator(String.format("/orgs/%s/teams", login), GHTeam[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHTeam[] page) {
|
||||||
|
for (GHTeam c : page)
|
||||||
|
c.wrapUp(GHOrganization.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a team that has the given name in its {@link GHTeam#getName()}
|
||||||
|
*/
|
||||||
|
public GHTeam getTeamByName(String name) throws IOException {
|
||||||
|
for (GHTeam t : listTeams()) {
|
||||||
|
if(t.getName().equals(name))
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this organization has the specified user as a member.
|
* Checks if this organization has the specified user as a member.
|
||||||
*/
|
*/
|
||||||
@@ -57,6 +89,14 @@ public class GHOrganization extends GHPerson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a member of the organisation - which will remove them from
|
||||||
|
* all teams, and remove their access to the organization’s repositories.
|
||||||
|
*/
|
||||||
|
public void remove(GHUser user) throws IOException {
|
||||||
|
root.retrieve().method("DELETE").to("/orgs/" + login + "/members/" + user.getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this organization has the specified user as a public member.
|
* Checks if this organization has the specified user as a public member.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -43,13 +43,16 @@ public abstract class GHPerson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the repositories this user owns.
|
* Gets the public repositories this user owns.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* To list your own repositories, including private repositories,
|
||||||
|
* use {@link GHMyself#listRepositories()}
|
||||||
*/
|
*/
|
||||||
public synchronized Map<String,GHRepository> getRepositories() throws IOException {
|
public synchronized Map<String,GHRepository> getRepositories() throws IOException {
|
||||||
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
|
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
|
||||||
for (List<GHRepository> batch : iterateRepositories(100)) {
|
for (GHRepository r : listRepositories()) {
|
||||||
for (GHRepository r : batch)
|
repositories.put(r.getName(),r);
|
||||||
repositories.put(r.getName(),r);
|
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(repositories);
|
return Collections.unmodifiableMap(repositories);
|
||||||
}
|
}
|
||||||
@@ -206,6 +209,10 @@ public abstract class GHPerson {
|
|||||||
return blog;
|
return blog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHtmlUrl() {
|
||||||
|
return html_url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the e-mail address of the user.
|
* Gets the e-mail address of the user.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.HashSet;
|
|||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public final class GHPersonSet<T extends GHPerson> extends HashSet<T> {
|
public class GHPersonSet<T extends GHPerson> extends HashSet<T> {
|
||||||
public GHPersonSet() {
|
public GHPersonSet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.util.Locale;
|
|||||||
* A pull request.
|
* A pull request.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHRepository#getPullRequest(int)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public class GHPullRequest extends GHIssue {
|
public class GHPullRequest extends GHIssue {
|
||||||
@@ -195,7 +196,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
return new PagedIterable<GHPullRequestCommitDetail>() {
|
return new PagedIterable<GHPullRequestCommitDetail>() {
|
||||||
public PagedIterator<GHPullRequestCommitDetail> iterator() {
|
public PagedIterator<GHPullRequestCommitDetail> iterator() {
|
||||||
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
||||||
String.format("%s/commits", getApiURL().getPath()),
|
String.format("%s/commits", getApiURL()),
|
||||||
GHPullRequestCommitDetail[].class)) {
|
GHPullRequestCommitDetail[].class)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,6 +9,7 @@ import java.net.URL;
|
|||||||
* @author Michael Clarke
|
* @author Michael Clarke
|
||||||
*/
|
*/
|
||||||
public class GHRef {
|
public class GHRef {
|
||||||
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
private String ref, url;
|
private String ref, url;
|
||||||
private GHObject object;
|
private GHObject object;
|
||||||
@@ -33,6 +35,48 @@ public class GHRef {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates this ref to the specified commit.
|
||||||
|
*
|
||||||
|
* @param sha
|
||||||
|
* The SHA1 value to set this reference to
|
||||||
|
*/
|
||||||
|
public void updateTo(String sha) throws IOException {
|
||||||
|
updateTo(sha, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates this ref to the specified commit.
|
||||||
|
*
|
||||||
|
* @param sha
|
||||||
|
* The SHA1 value to set this reference to
|
||||||
|
* @param force
|
||||||
|
* Whether or not to force this ref update.
|
||||||
|
*/
|
||||||
|
public void updateTo(String sha, Boolean force) throws IOException {
|
||||||
|
new Requester(root)
|
||||||
|
.with("sha", sha).with("force", force).method("PATCH").to(url, GHRef.class).wrap(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes this ref from the repository using the GitHub API.
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ GHRef wrap(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ static GHRef[] wrap(GHRef[] in, GitHub root) {
|
||||||
|
for (GHRef r : in) {
|
||||||
|
r.wrap(root);
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class GHObject {
|
public static class GHObject {
|
||||||
private String type, sha, url;
|
private String type, sha, url;
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ public class GHRelease {
|
|||||||
private boolean prerelease;
|
private boolean prerelease;
|
||||||
private Date created_at;
|
private Date created_at;
|
||||||
private Date published_at;
|
private Date published_at;
|
||||||
|
private String tarball_url;
|
||||||
|
private String zipball_url;
|
||||||
|
|
||||||
public String getAssetsUrl() {
|
public String getAssetsUrl() {
|
||||||
return assets_url;
|
return assets_url;
|
||||||
@@ -153,6 +155,22 @@ public class GHRelease {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getZipballUrl() {
|
||||||
|
return zipball_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZipballUrl(String zipballUrl) {
|
||||||
|
this.zipball_url = zipballUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarballUrl() {
|
||||||
|
return tarball_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarballUrl(String tarballUrl) {
|
||||||
|
this.tarball_url = tarballUrl;
|
||||||
|
}
|
||||||
|
|
||||||
GHRelease wrap(GHRepository owner) {
|
GHRelease wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
@@ -189,7 +207,18 @@ public class GHRelease {
|
|||||||
|
|
||||||
GHAsset[] assets = builder
|
GHAsset[] assets = builder
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.to(owner.getApiTailUrl(format("releases/%d/assets", id)), GHAsset[].class);
|
.to(getApiTailUrl("assets"), GHAsset[].class);
|
||||||
return Arrays.asList(GHAsset.wrap(assets, this));
|
return Arrays.asList(GHAsset.wrap(assets, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes this release.
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to(owner.getApiTailUrl("releases/"+id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getApiTailUrl(String end) {
|
||||||
|
return owner.getApiTailUrl(format("releases/%s/%s",id,end));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -56,18 +57,19 @@ import static java.util.Arrays.*;
|
|||||||
public class GHRepository {
|
public class GHRepository {
|
||||||
/*package almost final*/ GitHub root;
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
private String description, homepage, name;
|
private String description, homepage, name, full_name;
|
||||||
private String url; // this is the API url
|
private String url; // this is the API url
|
||||||
private String html_url; // this is the UI
|
private String html_url; // this is the UI
|
||||||
|
private String git_url, ssh_url, clone_url, svn_url;
|
||||||
private GHUser owner; // not fully populated. beware.
|
private GHUser owner; // not fully populated. beware.
|
||||||
private boolean has_issues, has_wiki, fork, has_downloads;
|
private boolean has_issues, has_wiki, fork, has_downloads;
|
||||||
@JsonProperty("private")
|
@JsonProperty("private")
|
||||||
private boolean _private;
|
private boolean _private;
|
||||||
private int watchers,forks,open_issues,size;
|
private int watchers,forks,open_issues,size,network_count,subscribers_count;
|
||||||
private String created_at, pushed_at;
|
private String created_at, pushed_at;
|
||||||
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
||||||
|
|
||||||
private String master_branch,language;
|
private String default_branch,language;
|
||||||
private Map<String,GHCommit> commits = new HashMap<String, GHCommit>();
|
private Map<String,GHCommit> commits = new HashMap<String, GHCommit>();
|
||||||
|
|
||||||
private GHRepoPermission permissions;
|
private GHRepoPermission permissions;
|
||||||
@@ -97,7 +99,7 @@ public class GHRepository {
|
|||||||
* This URL is read-only.
|
* This URL is read-only.
|
||||||
*/
|
*/
|
||||||
public String getGitTransportUrl() {
|
public String getGitTransportUrl() {
|
||||||
return "git://github.com/"+getOwnerName()+"/"+name+".git";
|
return git_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +107,21 @@ public class GHRepository {
|
|||||||
* This URL is read-only.
|
* This URL is read-only.
|
||||||
*/
|
*/
|
||||||
public String gitHttpTransportUrl() {
|
public String gitHttpTransportUrl() {
|
||||||
return "https://github.com/"+getOwnerName()+"/"+name+".git";
|
return clone_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Subversion URL to access this repository: https://github.com/rails/rails
|
||||||
|
*/
|
||||||
|
public String getSvnUrl() {
|
||||||
|
return svn_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the SSH URL to access this repository, such as git@github.com:rails/rails.git
|
||||||
|
*/
|
||||||
|
public String getSshUrl() {
|
||||||
|
return ssh_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,6 +131,13 @@ public class GHRepository {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full repository name including the owner or organization. For example 'jenkinsci/jenkins' in case of http://github.com/jenkinsci/jenkins
|
||||||
|
*/
|
||||||
|
public String getFullName() {
|
||||||
|
return full_name;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPullAccess() {
|
public boolean hasPullAccess() {
|
||||||
return permissions!=null && permissions.pull;
|
return permissions!=null && permissions.pull;
|
||||||
}
|
}
|
||||||
@@ -154,7 +177,8 @@ public class GHRepository {
|
|||||||
return Arrays.asList(GHIssue.wrap(root.retrieve()
|
return Arrays.asList(GHIssue.wrap(root.retrieve()
|
||||||
.to(String.format("/repos/%s/%s/issues?state=%s&milestone=%s", owner.login, name,
|
.to(String.format("/repos/%s/%s/issues?state=%s&milestone=%s", owner.login, name,
|
||||||
state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber()),
|
state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber()),
|
||||||
GHIssue[].class), this));
|
GHIssue[].class
|
||||||
|
), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,9 +202,54 @@ public class GHRepository {
|
|||||||
return new GHReleaseBuilder(this,tag);
|
return new GHReleaseBuilder(this,tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a named ref, such as tag, branch, etc.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* The name of the fully qualified reference (ie: refs/heads/master).
|
||||||
|
* If it doesn't start with 'refs' and have at least two slashes, it will be rejected.
|
||||||
|
* @param sha
|
||||||
|
* The SHA1 value to set this reference to
|
||||||
|
*/
|
||||||
|
public GHRef createRef(String name, String sha) throws IOException {
|
||||||
|
return new Requester(root)
|
||||||
|
.with("ref", name).with("sha", sha).method("POST").to(getApiTailUrl("git/refs"), GHRef.class).wrap(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* use {@link #listReleases()}
|
||||||
|
*/
|
||||||
public List<GHRelease> getReleases() throws IOException {
|
public List<GHRelease> getReleases() throws IOException {
|
||||||
return Arrays.asList(GHRelease.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/releases",
|
return listReleases().asList();
|
||||||
GHRelease[].class), this));
|
}
|
||||||
|
|
||||||
|
public PagedIterable<GHRelease> listReleases() throws IOException {
|
||||||
|
return new PagedIterable<GHRelease>() {
|
||||||
|
public PagedIterator<GHRelease> iterator() {
|
||||||
|
return new PagedIterator<GHRelease>(root.retrieve().asIterator(getApiTailUrl("releases"), GHRelease[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHRelease[] page) {
|
||||||
|
for (GHRelease c : page)
|
||||||
|
c.wrap(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public PagedIterable<GHTag> listTags() throws IOException {
|
||||||
|
return new PagedIterable<GHTag>() {
|
||||||
|
public PagedIterator<GHTag> iterator() {
|
||||||
|
return new PagedIterator<GHTag>(root.retrieve().asIterator(getApiTailUrl("tags"), GHTag[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHTag[] page) {
|
||||||
|
for (GHTag c : page)
|
||||||
|
c.wrap(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getOwnerName() {
|
protected String getOwnerName() {
|
||||||
@@ -219,6 +288,14 @@ public class GHRepository {
|
|||||||
return open_issues;
|
return open_issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNetworkCount() {
|
||||||
|
return network_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSubscribersCount() {
|
||||||
|
return subscribers_count;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
@@ -239,7 +316,7 @@ public class GHRepository {
|
|||||||
* This field is null until the user explicitly configures the master branch.
|
* This field is null until the user explicitly configures the master branch.
|
||||||
*/
|
*/
|
||||||
public String getMasterBranch() {
|
public String getMasterBranch() {
|
||||||
return master_branch;
|
return default_branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
@@ -252,7 +329,32 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
@WithBridgeMethods(Set.class)
|
@WithBridgeMethods(Set.class)
|
||||||
public GHPersonSet<GHUser> getCollaborators() throws IOException {
|
public GHPersonSet<GHUser> getCollaborators() throws IOException {
|
||||||
return new GHPersonSet<GHUser>(GHUser.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class),root));
|
return new GHPersonSet<GHUser>(listCollaborators().asList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up the collaborators on this repository.
|
||||||
|
*
|
||||||
|
* @return Users
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHUser> listCollaborators() throws IOException {
|
||||||
|
return new PagedIterable<GHUser>() {
|
||||||
|
public PagedIterator<GHUser> iterator() {
|
||||||
|
|
||||||
|
return new PagedIterator<GHUser>(root.retrieve().asIterator("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class)) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHUser[] users) {
|
||||||
|
for (GHUser user : users) {
|
||||||
|
user.wrapUp(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -347,7 +449,11 @@ public class GHRepository {
|
|||||||
* Deletes this repository.
|
* Deletes this repository.
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).method("DELETE").to("/repos/" + owner.login + "/" + name);
|
try {
|
||||||
|
new Requester(root).method("DELETE").to("/repos/" + owner.login + "/" + name);
|
||||||
|
} catch (FileNotFoundException x) {
|
||||||
|
throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + owner.login + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -415,6 +521,29 @@ public class GHRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new pull request.
|
||||||
|
*
|
||||||
|
* @param title
|
||||||
|
* Required. The title of the pull request.
|
||||||
|
* @param head
|
||||||
|
* Required. The name of the branch where your changes are implemented.
|
||||||
|
* For cross-repository pull requests in the same network,
|
||||||
|
* namespace head with a user like this: username:branch.
|
||||||
|
* @param base
|
||||||
|
* Required. The name of the branch you want your changes pulled into.
|
||||||
|
* This should be an existing branch on the current repository.
|
||||||
|
* @param body
|
||||||
|
* The contents of the pull request. This is the markdown description
|
||||||
|
* of a pull request.
|
||||||
|
*/
|
||||||
|
public GHPullRequest createPullRequest(String title, String head, String base, String body) throws IOException {
|
||||||
|
return new Requester(root).with("title",title)
|
||||||
|
.with("head",head)
|
||||||
|
.with("base",base)
|
||||||
|
.with("body",body).to(getApiTailUrl("pulls"),GHPullRequest.class).wrapUp(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the currently configured hooks.
|
* Retrieves the currently configured hooks.
|
||||||
*/
|
*/
|
||||||
@@ -444,7 +573,7 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException {
|
public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException {
|
||||||
return getCompare(id1.getSHA1(),id2.getSHA1());
|
return getCompare(id1.getSHA1(), id2.getSHA1());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException {
|
public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException {
|
||||||
@@ -457,19 +586,31 @@ public class GHRepository {
|
|||||||
* @throws IOException on failure communicating with GitHub
|
* @throws IOException on failure communicating with GitHub
|
||||||
*/
|
*/
|
||||||
public GHRef[] getRefs() throws IOException {
|
public GHRef[] getRefs() throws IOException {
|
||||||
return root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class);
|
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class),root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrienved all refs of the given type for the current GitHub repository.
|
* Retrieves all refs of the given type for the current GitHub repository.
|
||||||
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
|
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
|
||||||
* @return an array of all refs matching the request type
|
* @return an array of all refs matching the request type
|
||||||
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
||||||
*/
|
*/
|
||||||
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 GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class),root);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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).wrap(root);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Gets a commit object in this repository.
|
* Gets a commit object in this repository.
|
||||||
*/
|
*/
|
||||||
@@ -498,6 +639,13 @@ public class GHRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search commits by specifying filters through a builder pattern.
|
||||||
|
*/
|
||||||
|
public GHCommitQueryBuilder queryCommits() {
|
||||||
|
return new GHCommitQueryBuilder(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up all the commit comments in this repository.
|
* Lists up all the commit comments in this repository.
|
||||||
*/
|
*/
|
||||||
@@ -547,14 +695,24 @@ 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.
|
||||||
@@ -808,6 +966,22 @@ public class GHRepository {
|
|||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.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() {
|
||||||
|
|||||||
36
src/main/java/org/kohsuke/github/GHTag.java
Normal file
36
src/main/java/org/kohsuke/github/GHTag.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a tag in {@link GHRepository}
|
||||||
|
*
|
||||||
|
* @see GHRepository#listTags()
|
||||||
|
*/
|
||||||
|
public class GHTag {
|
||||||
|
private GHRepository owner;
|
||||||
|
private GitHub root;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private GHCommit commit;
|
||||||
|
|
||||||
|
/*package*/ GHTag wrap(GHRepository owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.root = owner.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRepository getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHCommit getCommit() {
|
||||||
|
return commit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import java.util.TreeMap;
|
|||||||
public class GHTeam {
|
public class GHTeam {
|
||||||
private String name,permission;
|
private String name,permission;
|
||||||
private int id;
|
private int id;
|
||||||
|
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together
|
||||||
|
|
||||||
protected /*final*/ GHOrganization org;
|
protected /*final*/ GHOrganization org;
|
||||||
|
|
||||||
@@ -23,6 +24,11 @@ public class GHTeam {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*package*/ GHTeam wrapUp(GitHub root) { // auto-wrapUp when organization is known from GET /user/teams
|
||||||
|
this.organization.wrapUp(root);
|
||||||
|
return wrapUp(organization);
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ static GHTeam[] wrapUp(GHTeam[] teams, GHOrganization owner) {
|
/*package*/ static GHTeam[] wrapUp(GHTeam[] teams, GHOrganization owner) {
|
||||||
for (GHTeam t : teams) {
|
for (GHTeam t : teams) {
|
||||||
t.wrapUp(owner);
|
t.wrapUp(owner);
|
||||||
@@ -95,4 +101,8 @@ public class GHTeam {
|
|||||||
private String api(String tail) {
|
private String api(String tail) {
|
||||||
return "/teams/"+id+tail;
|
return "/teams/"+id+tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHOrganization getOrganization() {
|
||||||
|
return org;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,23 @@ public class GHUser extends GHPerson {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists Gists created by this user.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHGist> listGists() throws IOException {
|
||||||
|
return new PagedIterable<GHGist>() {
|
||||||
|
public PagedIterator<GHGist> iterator() {
|
||||||
|
return new PagedIterator<GHGist>(root.retrieve().asIterator(String.format("/users/%s/gists", login), GHGist[].class)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHGist[] page) {
|
||||||
|
for (GHGist c : page)
|
||||||
|
c.wrapUp(GHUser.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "User:"+login;
|
return "User:"+login;
|
||||||
|
|||||||
@@ -23,10 +23,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.*;
|
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
|
||||||
|
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@@ -37,9 +39,11 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
@@ -68,6 +72,8 @@ public class GitHub {
|
|||||||
|
|
||||||
private final String apiUrl;
|
private final String apiUrl;
|
||||||
|
|
||||||
|
private HttpConnector connector = HttpConnector.DEFAULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to GitHub.com
|
* Connects to GitHub.com
|
||||||
*/
|
*/
|
||||||
@@ -201,6 +207,17 @@ public class GitHub {
|
|||||||
return login==null && encodedAuthorization==null;
|
return login==null && encodedAuthorization==null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpConnector getConnector() {
|
||||||
|
return connector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the custom connector used to make requests to GitHub.
|
||||||
|
*/
|
||||||
|
public void setConnector(HttpConnector connector) {
|
||||||
|
this.connector = connector;
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ void requireCredential() {
|
/*package*/ void requireCredential() {
|
||||||
if (isAnonymous())
|
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");
|
||||||
@@ -226,7 +243,16 @@ 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().to("/rate_limit", JsonRateLimit.class).rate;
|
try {
|
||||||
|
return retrieve().to("/rate_limit", JsonRateLimit.class).rate;
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// GitHub Enterprise doesn't have the rate limit, so in that case
|
||||||
|
// return some big number that's not too big.
|
||||||
|
// see issue #78
|
||||||
|
GHRateLimit r = new GHRateLimit();
|
||||||
|
r.limit = r.remaining = 1000000;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -257,6 +283,15 @@ public class GitHub {
|
|||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clears all cached data in order for external changes (modifications and del
|
||||||
|
*/
|
||||||
|
public void refreshCache() {
|
||||||
|
users.clear();
|
||||||
|
orgs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interns the given {@link GHUser}.
|
* Interns the given {@link GHUser}.
|
||||||
*/
|
*/
|
||||||
@@ -305,17 +340,49 @@ public class GitHub {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets complete map of organizations/teams that current user belongs to.
|
||||||
|
*
|
||||||
|
* Leverages the new GitHub API /user/teams made available recently to
|
||||||
|
* get in a single call the complete set of organizations, teams and permissions
|
||||||
|
* in a single call.
|
||||||
|
*/
|
||||||
|
public Map<String, Set<GHTeam>> getMyTeams() throws IOException {
|
||||||
|
Map<String, Set<GHTeam>> allMyTeams = new HashMap<String, Set<GHTeam>>();
|
||||||
|
for (GHTeam team : retrieve().to("/user/teams", GHTeam[].class)) {
|
||||||
|
team.wrapUp(this);
|
||||||
|
String orgLogin = team.getOrganization().getLogin();
|
||||||
|
Set<GHTeam> teamsPerOrg = allMyTeams.get(orgLogin);
|
||||||
|
if (teamsPerOrg == null) {
|
||||||
|
teamsPerOrg = new HashSet<GHTeam>();
|
||||||
|
}
|
||||||
|
teamsPerOrg.add(team);
|
||||||
|
allMyTeams.put(orgLogin, teamsPerOrg);
|
||||||
|
}
|
||||||
|
return allMyTeams;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public events visible to you. Equivalent of what's displayed on https://github.com/
|
* Public events visible to you. Equivalent of what's displayed on https://github.com/
|
||||||
*/
|
*/
|
||||||
public List<GHEventInfo> getEvents() throws IOException {
|
public List<GHEventInfo> getEvents() throws IOException {
|
||||||
// TODO: pagination
|
|
||||||
GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class);
|
GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class);
|
||||||
for (GHEventInfo e : events)
|
for (GHEventInfo e : events)
|
||||||
e.wrapUp(this);
|
e.wrapUp(this);
|
||||||
return Arrays.asList(events);
|
return Arrays.asList(events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a sigle gist by ID.
|
||||||
|
*/
|
||||||
|
public GHGist getGist(String id) throws IOException {
|
||||||
|
return retrieve().to("/gists/"+id,GHGist.class).wrapUp(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHGistBuilder createGist() {
|
||||||
|
return new GHGistBuilder(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the GitHub event object.
|
* Parses the GitHub event object.
|
||||||
*
|
*
|
||||||
@@ -332,6 +399,9 @@ public class GitHub {
|
|||||||
/**
|
/**
|
||||||
* Creates a new repository.
|
* Creates a new repository.
|
||||||
*
|
*
|
||||||
|
* To create a repository in an organization, see
|
||||||
|
* {@link GHOrganization#createRepository(String, String, String, GHTeam, boolean)}
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* Newly created repository.
|
* Newly created repository.
|
||||||
*/
|
*/
|
||||||
@@ -392,6 +462,10 @@ public class GitHub {
|
|||||||
throw new IllegalStateException("Unable to parse the timestamp: "+timestamp);
|
throw new IllegalStateException("Unable to parse the timestamp: "+timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*package*/ static String printDate(Date dt) {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(dt);
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ static final ObjectMapper MAPPER = new ObjectMapper();
|
/*package*/ static final ObjectMapper MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
private static final String[] TIME_FORMATS = {"yyyy/MM/dd HH:mm:ss ZZZZ","yyyy-MM-dd'T'HH:mm:ss'Z'"};
|
private static final String[] TIME_FORMATS = {"yyyy/MM/dd HH:mm:ss ZZZZ","yyyy-MM-dd'T'HH:mm:ss'Z'"};
|
||||||
|
|||||||
29
src/main/java/org/kohsuke/github/HttpConnector.java
Normal file
29
src/main/java/org/kohsuke/github/HttpConnector.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pluggability for customizing HTTP request behaviors or using altogether different library.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* For example, you can implement this to st custom timeouts.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public interface HttpConnector {
|
||||||
|
/**
|
||||||
|
* Opens a connection to the given URL.
|
||||||
|
*/
|
||||||
|
HttpURLConnection connect(URL url) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation that uses {@link URL#openConnection()}.
|
||||||
|
*/
|
||||||
|
HttpConnector DEFAULT = new HttpConnector() {
|
||||||
|
public HttpURLConnection connect(URL url) throws IOException {
|
||||||
|
return (HttpURLConnection) url.openConnection();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -23,20 +23,22 @@
|
|||||||
*/
|
*/
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import static org.kohsuke.github.GitHub.MAPPER;
|
||||||
|
|
||||||
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;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.ProtocolException;
|
import java.net.ProtocolException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -46,9 +48,13 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import static org.kohsuke.github.GitHub.MAPPER;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder pattern for making HTTP call and parsing its output.
|
* A builder pattern for making HTTP call and parsing its output.
|
||||||
@@ -173,45 +179,99 @@ class Requester {
|
|||||||
while (true) {// loop while API rate limit is hit
|
while (true) {// loop while API rate limit is hit
|
||||||
HttpURLConnection uc = setupConnection(root.getApiURL(tailApiUrl));
|
HttpURLConnection uc = setupConnection(root.getApiURL(tailApiUrl));
|
||||||
|
|
||||||
if (!method.equals("GET")) {
|
buildRequest(uc);
|
||||||
uc.setDoOutput(true);
|
|
||||||
uc.setRequestProperty("Content-type", contentType);
|
|
||||||
|
|
||||||
if (body == null) {
|
|
||||||
Map json = new HashMap();
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return parse(uc,type,instance);
|
T result = parse(uc, type, instance);
|
||||||
|
if (type != null && type.isArray()) { // we might have to loop for pagination - done through recursion
|
||||||
|
final String links = uc.getHeaderField("link");
|
||||||
|
if (links != null && links.contains("rel=\"next\"")) {
|
||||||
|
Pattern nextLinkPattern = Pattern.compile(".*<(.*)>; rel=\"next\"");
|
||||||
|
Matcher nextLinkMatcher = nextLinkPattern.matcher(links);
|
||||||
|
if (nextLinkMatcher.find()) {
|
||||||
|
final String link = nextLinkMatcher.group(1);
|
||||||
|
T nextResult = _to(link, type, instance);
|
||||||
|
|
||||||
|
final int resultLength = Array.getLength(result);
|
||||||
|
final int nextResultLength = Array.getLength(nextResult);
|
||||||
|
T concatResult = (T) Array.newInstance(type.getComponentType(), resultLength + nextResultLength);
|
||||||
|
System.arraycopy(result, 0, concatResult, 0, resultLength);
|
||||||
|
System.arraycopy(nextResult, 0, concatResult, resultLength, nextResultLength);
|
||||||
|
result = concatResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleApiError(e,uc);
|
handleApiError(e,uc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a request and just obtains the HTTP status code.
|
||||||
|
*/
|
||||||
|
public int asHttpStatusCode(String tailApiUrl) throws IOException {
|
||||||
|
while (true) {// loop while API rate limit is hit
|
||||||
|
HttpURLConnection uc = setupConnection(root.getApiURL(tailApiUrl));
|
||||||
|
|
||||||
|
buildRequest(uc);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return uc.getResponseCode();
|
||||||
|
} catch (IOException e) {
|
||||||
|
handleApiError(e,uc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildRequest(HttpURLConnection uc) throws IOException {
|
||||||
|
if (!method.equals("GET")) {
|
||||||
|
uc.setDoOutput(true);
|
||||||
|
uc.setRequestProperty("Content-type", contentType);
|
||||||
|
|
||||||
|
if (body == null) {
|
||||||
|
Map json = new HashMap();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads pagenated resources.
|
* Loads pagenated resources.
|
||||||
*
|
*
|
||||||
* Every iterator call reports a new batch.
|
* Every iterator call reports a new batch.
|
||||||
*/
|
*/
|
||||||
/*package*/ <T> Iterator<T> asIterator(final String tailApiUrl, final Class<T> type) {
|
/*package*/ <T> Iterator<T> asIterator(String _tailApiUrl, final Class<T> type) {
|
||||||
method("GET");
|
method("GET");
|
||||||
if (!args.isEmpty()) throw new IllegalStateException();
|
|
||||||
|
if (!args.isEmpty()) {
|
||||||
|
boolean first=true;
|
||||||
|
try {
|
||||||
|
for (Entry a : args) {
|
||||||
|
_tailApiUrl += first ? '?' : '&';
|
||||||
|
first = false;
|
||||||
|
_tailApiUrl += URLEncoder.encode(a.key,"UTF-8")+'='+URLEncoder.encode(a.value.toString(),"UTF-8");
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new AssertionError(e); // UTF-8 is mandatory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String tailApiUrl = _tailApiUrl;
|
||||||
|
|
||||||
return new Iterator<T>() {
|
return new Iterator<T>() {
|
||||||
/**
|
/**
|
||||||
@@ -294,7 +354,7 @@ class Requester {
|
|||||||
|
|
||||||
|
|
||||||
private HttpURLConnection setupConnection(URL url) throws IOException {
|
private HttpURLConnection setupConnection(URL url) throws IOException {
|
||||||
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
|
HttpURLConnection uc = root.getConnector().connect(url);
|
||||||
|
|
||||||
// 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.)
|
||||||
|
|||||||
32
src/main/java/org/kohsuke/github/extras/OkHttpConnector.java
Normal file
32
src/main/java/org/kohsuke/github/extras/OkHttpConnector.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package org.kohsuke.github.extras;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.OkHttpClient;
|
||||||
|
import com.squareup.okhttp.OkUrlFactory;
|
||||||
|
import org.kohsuke.github.HttpConnector;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link HttpConnector} for {@link OkHttpClient}.
|
||||||
|
*
|
||||||
|
* Unlike {@link #DEFAULT}, OkHttp does response caching.
|
||||||
|
* Making a conditional request against GitHubAPI and receiving a 304
|
||||||
|
* response does not count against the rate limit.
|
||||||
|
* See http://developer.github.com/v3/#conditional-requests
|
||||||
|
*
|
||||||
|
* @author Roberto Tyley
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class OkHttpConnector implements HttpConnector {
|
||||||
|
private final OkUrlFactory urlFactory;
|
||||||
|
|
||||||
|
public OkHttpConnector(OkUrlFactory urlFactory) {
|
||||||
|
this.urlFactory = urlFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpURLConnection connect(URL url) throws IOException {
|
||||||
|
return urlFactory.open(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ operations that act on them as defined as methods (such as `GHUser.follow()`), a
|
|||||||
are used in favor of using string handle (such as `GHUser.isMemberOf(GHOrganization)` instead of
|
are used in favor of using string handle (such as `GHUser.isMemberOf(GHOrganization)` instead of
|
||||||
`GHUser.isMemberOf(String)`)
|
`GHUser.isMemberOf(String)`)
|
||||||
|
|
||||||
|
The library supports both github.com and GitHub Enterprise.
|
||||||
|
|
||||||
There are some corners of the GitHub API that's not yet implemented, but
|
There are some corners of the GitHub API that's not yet implemented, but
|
||||||
the library is implemented with the right abstractions and libraries to make it very easy to improve the coverage.
|
the library is implemented with the right abstractions and libraries to make it very easy to improve the coverage.
|
||||||
|
|
||||||
@@ -34,3 +36,10 @@ Alternatively, you can have just the OAuth token in this file:
|
|||||||
|
|
||||||
oauth=4d98173f7c075527cb64878561d1fe70
|
oauth=4d98173f7c075527cb64878561d1fe70
|
||||||
|
|
||||||
|
OkHttp
|
||||||
|
----
|
||||||
|
This library comes with a pluggable connector to use different HTTP client implementations
|
||||||
|
through `HttpConnector`. In particular, this means you can use [OkHttp](http://square.github.io/okhttp/),
|
||||||
|
so we can make use of it's HTTP response cache.
|
||||||
|
Making a conditional request against the GitHub API and receiving a 304 response
|
||||||
|
[does not count against the rate limit](http://developer.github.com/v3/#conditional-requests).
|
||||||
@@ -1,12 +1,23 @@
|
|||||||
|
import org.kohsuke.github.GHOrganization;
|
||||||
|
import org.kohsuke.github.GHTeam;
|
||||||
import org.kohsuke.github.GitHub;
|
import org.kohsuke.github.GitHub;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class Foo {
|
public class Foo {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.out.println(GitHub.connect().getOrganization("cloudbees").getRepository("grandcentral").isPrivate());
|
GHOrganization org = GitHub.connect().getOrganization("jenkinsci");
|
||||||
|
Map<String, GHTeam> teams = org.getTeams();
|
||||||
|
System.out.println(teams.size());
|
||||||
|
|
||||||
|
int sz = 0;
|
||||||
|
for (GHTeam t : org.listTeams()) {
|
||||||
|
sz++;
|
||||||
|
}
|
||||||
|
System.out.println(sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.kohsuke.randname.RandomNameGenerator;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public abstract class AbstractGitHubApiTestBase extends Assert {
|
||||||
|
|
||||||
|
protected GitHub gitHub;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
Properties props = new Properties();
|
||||||
|
java.io.File f = new java.io.File(System.getProperty("user.home"), ".github.kohsuke2");
|
||||||
|
if (f.exists()) {
|
||||||
|
FileInputStream in = new FileInputStream(f);
|
||||||
|
try {
|
||||||
|
props.load(in);
|
||||||
|
gitHub = GitHub.connect(props.getProperty("login"),props.getProperty("oauth"));
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gitHub = GitHub.connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final RandomNameGenerator rnd = new RandomNameGenerator();
|
||||||
|
}
|
||||||
@@ -1,57 +1,27 @@
|
|||||||
package org.kohsuke;
|
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.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kohsuke.github.GHBranch;
|
|
||||||
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.GHCommitState;
|
|
||||||
import org.kohsuke.github.GHCommitStatus;
|
|
||||||
import org.kohsuke.github.GHEvent;
|
|
||||||
import org.kohsuke.github.GHEventInfo;
|
|
||||||
import org.kohsuke.github.GHEventPayload;
|
|
||||||
import org.kohsuke.github.GHHook;
|
|
||||||
import org.kohsuke.github.GHIssue;
|
|
||||||
import org.kohsuke.github.GHIssueComment;
|
|
||||||
import org.kohsuke.github.GHIssueState;
|
|
||||||
import org.kohsuke.github.GHKey;
|
|
||||||
import org.kohsuke.github.GHMilestone;
|
|
||||||
import org.kohsuke.github.GHMyself;
|
|
||||||
import org.kohsuke.github.GHOrganization;
|
|
||||||
import org.kohsuke.github.GHOrganization.Permission;
|
import org.kohsuke.github.GHOrganization.Permission;
|
||||||
import org.kohsuke.github.GHPullRequest;
|
|
||||||
import org.kohsuke.github.GHRepository;
|
import com.google.common.base.Predicate;
|
||||||
import org.kohsuke.github.GHTeam;
|
import com.google.common.collect.Iterables;
|
||||||
import org.kohsuke.github.GHUser;
|
|
||||||
import org.kohsuke.github.GitHub;
|
|
||||||
import org.kohsuke.github.PagedIterable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest extends AbstractGitHubApiTestBase {
|
||||||
|
|
||||||
private GitHub gitHub;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
gitHub = GitHub.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTestRepositoryName() throws IOException {
|
private String getTestRepositoryName() throws IOException {
|
||||||
return getUser().getLogin() + "/github-api-test";
|
return getUser().getLogin() + "/github-api-test";
|
||||||
}
|
}
|
||||||
@@ -192,6 +162,35 @@ public class AppTest {
|
|||||||
System.out.println(org);
|
System.out.println(org);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMyTeamsContainsAllMyOrganizations() throws IOException {
|
||||||
|
Map<String, Set<GHTeam>> teams = gitHub.getMyTeams();
|
||||||
|
Map<String, GHOrganization> myOrganizations = gitHub.getMyOrganizations();
|
||||||
|
assertEquals(teams.keySet(), myOrganizations.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMyTeamsShouldIncludeMyself() throws IOException {
|
||||||
|
Map<String, Set<GHTeam>> teams = gitHub.getMyTeams();
|
||||||
|
for (Entry<String, Set<GHTeam>> teamsPerOrg : teams.entrySet()) {
|
||||||
|
String organizationName = teamsPerOrg.getKey();
|
||||||
|
for (GHTeam team : teamsPerOrg.getValue()) {
|
||||||
|
String teamName = team.getName();
|
||||||
|
assertTrue("Team " + teamName + " in organization " + organizationName
|
||||||
|
+ " does not contain myself",
|
||||||
|
shouldBelongToTeam(organizationName, teamName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldBelongToTeam(String organizationName, String teamName) throws IOException {
|
||||||
|
GHOrganization org = gitHub.getOrganization(organizationName);
|
||||||
|
assertNotNull(org);
|
||||||
|
GHTeam team = org.getTeamByName(teamName);
|
||||||
|
assertNotNull(team);
|
||||||
|
return team.hasMember(gitHub.getMyself());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchPullRequest() throws Exception {
|
public void testFetchPullRequest() throws Exception {
|
||||||
GHRepository r = gitHub.getOrganization("jenkinsci").getRepository("jenkins");
|
GHRepository r = gitHub.getOrganization("jenkinsci").getRepository("jenkins");
|
||||||
@@ -238,13 +237,13 @@ public class AppTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOrgFork() throws Exception {
|
public void testOrgFork() throws Exception {
|
||||||
kohsuke();
|
kohsuke();
|
||||||
getUser().getRepository("rubywm").forkTo(gitHub.getOrganization("jenkinsci"));
|
gitHub.getRepository("kohsuke/rubywm").forkTo(gitHub.getOrganization("github-api-test-org"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetTeamsForRepo() throws Exception {
|
public void testGetTeamsForRepo() throws Exception {
|
||||||
kohsuke();
|
kohsuke();
|
||||||
assertEquals(1,gitHub.getOrganization("stapler").getRepository("stapler").getTeams().size());
|
assertEquals(1,gitHub.getOrganization("github-api-test-org").getRepository("testGetTeamsForRepo").getTeams().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -252,13 +251,31 @@ public class AppTest {
|
|||||||
Set<String> members = gitHub.getOrganization("jenkinsci").getRepository("violations-plugin").getCollaboratorNames();
|
Set<String> members = gitHub.getOrganization("jenkinsci").getRepository("violations-plugin").getCollaboratorNames();
|
||||||
System.out.println(members.contains("kohsuke"));
|
System.out.println(members.contains("kohsuke"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMemberOrgs() throws Exception {
|
public void testMemberOrgs() throws Exception {
|
||||||
Set<GHOrganization> o = gitHub.getUser("kohsuke").getOrganizations();
|
Set<GHOrganization> o = gitHub.getUser("kohsuke").getOrganizations();
|
||||||
System.out.println(o);
|
System.out.println(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrgTeams() throws Exception {
|
||||||
|
kohsuke();
|
||||||
|
int sz=0;
|
||||||
|
for (GHTeam t : gitHub.getOrganization("github-api-test-org").listTeams()) {
|
||||||
|
assertNotNull(t.getName());
|
||||||
|
sz++;
|
||||||
|
}
|
||||||
|
assertTrue(sz<100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrgTeamByName() throws Exception {
|
||||||
|
kohsuke();
|
||||||
|
GHTeam e = gitHub.getOrganization("github-api-test-org").getTeamByName("Core Developers");
|
||||||
|
assertNotNull(e);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommit() throws Exception {
|
public void testCommit() throws Exception {
|
||||||
GHCommit commit = gitHub.getUser("jenkinsci").getRepository("jenkins").getCommit("08c1c9970af4d609ae754fbe803e06186e3206f7");
|
GHCommit commit = gitHub.getUser("jenkinsci").getRepository("jenkins").getCommit("08c1c9970af4d609ae754fbe803e06186e3206f7");
|
||||||
@@ -279,8 +296,19 @@ public class AppTest {
|
|||||||
System.out.println(c.getSHA1());
|
System.out.println(c.getSHA1());
|
||||||
sha1.add(c.getSHA1());
|
sha1.add(c.getSHA1());
|
||||||
}
|
}
|
||||||
assertEquals("fdfad6be4db6f96faea1f153fb447b479a7a9cb7",sha1.get(0));
|
assertEquals("fdfad6be4db6f96faea1f153fb447b479a7a9cb7", sha1.get(0));
|
||||||
assertEquals(1,sha1.size());
|
assertEquals(1, sha1.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testQueryCommits() throws Exception {
|
||||||
|
List<String> sha1 = new ArrayList<String>();
|
||||||
|
for (GHCommit c : gitHub.getUser("jenkinsci").getRepository("jenkins").queryCommits()
|
||||||
|
.since(new Date(1199174400000L)).until(1201852800000L).path("pom.xml").list()) {
|
||||||
|
System.out.println(c.getSHA1());
|
||||||
|
sha1.add(c.getSHA1());
|
||||||
|
}
|
||||||
|
assertEquals("1cccddb22e305397151b2b7b87b4b47d74ca337b",sha1.get(0));
|
||||||
|
assertEquals(29,sha1.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -436,7 +464,7 @@ public class AppTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOrganization() throws IOException {
|
public void testOrganization() throws IOException {
|
||||||
kohsuke();
|
kohsuke();
|
||||||
GHOrganization j = gitHub.getOrganization("jenkinsci");
|
GHOrganization j = gitHub.getOrganization("github-api-test-org");
|
||||||
GHTeam t = j.getTeams().get("Core Developers");
|
GHTeam t = j.getTeams().get("Core Developers");
|
||||||
|
|
||||||
assertNotNull(j.getRepository("jenkins"));
|
assertNotNull(j.getRepository("jenkins"));
|
||||||
@@ -489,7 +517,91 @@ public class AppTest {
|
|||||||
assertFalse(j.hasPublicMember(b));
|
assertFalse(j.hasPublicMember(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateRelease() throws Exception {
|
||||||
|
kohsuke();
|
||||||
|
|
||||||
|
GHRepository r = gitHub.getRepository("kohsuke2/testCreateRelease");
|
||||||
|
|
||||||
|
String tagName = UUID.randomUUID().toString();
|
||||||
|
String releaseName = "release-" + tagName;
|
||||||
|
|
||||||
|
GHRelease rel = r.createRelease(tagName)
|
||||||
|
.name(releaseName)
|
||||||
|
.prerelease(false)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
for (GHTag tag : r.listTags()) {
|
||||||
|
if (tagName.equals(tag.getName())) {
|
||||||
|
String ash = tag.getCommit().getSHA1();
|
||||||
|
GHRef ref = r.createRef("refs/heads/"+releaseName, ash);
|
||||||
|
assertEquals(ref.getRef(),"refs/heads/"+releaseName);
|
||||||
|
|
||||||
|
for (Map.Entry<String, GHBranch> entry : r.getBranches().entrySet()) {
|
||||||
|
System.out.println(entry.getKey() + "/" + entry.getValue());
|
||||||
|
if (releaseName.equals(entry.getValue().getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail("branch not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail("release creation failed! tag not found");
|
||||||
|
} finally {
|
||||||
|
rel.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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() {
|
||||||
Assume.assumeTrue(getUser().getLogin().equals("kohsuke"));
|
String login = getUser().getLogin();
|
||||||
|
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,26 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test for {@link GHContent}.
|
* Integration test for {@link GHContent}.
|
||||||
*/
|
*/
|
||||||
public class GHContentIntegrationTest extends TestCase {
|
public class GHContentIntegrationTest extends AbstractGitHubApiTestBase {
|
||||||
|
|
||||||
private GitHub gitHub;
|
|
||||||
private GHRepository repo;
|
private GHRepository repo;
|
||||||
private String createdFilename;
|
private String createdFilename = rnd.next();
|
||||||
|
|
||||||
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
repo = gitHub.getRepository("github-api-test-org/GHContentIntegrationTest").fork();
|
||||||
gitHub = GitHub.connect();
|
|
||||||
repo = gitHub.getRepository("acollign/github-api-test").fork();
|
|
||||||
createdFilename = UUID.randomUUID().toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetFileContent() throws Exception {
|
public void testGetFileContent() throws Exception {
|
||||||
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
|
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
|
||||||
|
|
||||||
@@ -30,6 +28,7 @@ public class GHContentIntegrationTest extends TestCase {
|
|||||||
assertEquals("thanks for reading me\n", content.getContent());
|
assertEquals("thanks for reading me\n", content.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetEmptyFileContent() throws Exception {
|
public void testGetEmptyFileContent() throws Exception {
|
||||||
GHContent content = repo.getFileContent("ghcontent-ro/an-empty-file");
|
GHContent content = repo.getFileContent("ghcontent-ro/an-empty-file");
|
||||||
|
|
||||||
@@ -37,12 +36,14 @@ public class GHContentIntegrationTest extends TestCase {
|
|||||||
assertEquals("", content.getContent());
|
assertEquals("", content.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetDirectoryContent() throws Exception {
|
public void testGetDirectoryContent() throws Exception {
|
||||||
List<GHContent> entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries");
|
List<GHContent> entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries");
|
||||||
|
|
||||||
assertTrue(entries.size() == 3);
|
assertTrue(entries.size() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCRUDContent() throws Exception {
|
public void testCRUDContent() throws Exception {
|
||||||
GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n", "Creating a file for integration tests.", createdFilename);
|
GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n", "Creating a file for integration tests.", createdFilename);
|
||||||
GHContent createdContent = created.getContent();
|
GHContent createdContent = created.getContent();
|
||||||
|
|||||||
73
src/test/java/org/kohsuke/github/GistTest.java
Normal file
73
src/test/java/org/kohsuke/github/GistTest.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class GistTest extends AbstractGitHubApiTestBase {
|
||||||
|
/**
|
||||||
|
* CRUD operation.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void lifecycleTest() throws Exception {
|
||||||
|
GHGist gist = gitHub.createGist()
|
||||||
|
.public_(false)
|
||||||
|
.description("Test Gist")
|
||||||
|
.file("abc.txt","abc")
|
||||||
|
.file("def.txt","def")
|
||||||
|
.create();
|
||||||
|
|
||||||
|
assertNotNull(gist.getCreatedAt());
|
||||||
|
assertNotNull(gist.getUpdatedAt());
|
||||||
|
|
||||||
|
assertNotNull(gist.getCommentsUrl());
|
||||||
|
assertNotNull(gist.getCommitsUrl());
|
||||||
|
assertNotNull(gist.getGitPullUrl());
|
||||||
|
assertNotNull(gist.getGitPushUrl());
|
||||||
|
assertNotNull(gist.getHtmlUrl());
|
||||||
|
|
||||||
|
gist.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void starTest() throws Exception {
|
||||||
|
GHGist gist = gitHub.getGist("9903708");
|
||||||
|
assertEquals("rtyler",gist.getOwner().getLogin());
|
||||||
|
|
||||||
|
gist.star();
|
||||||
|
assertTrue(gist.isStarred());
|
||||||
|
gist.unstar();
|
||||||
|
assertFalse(gist.isStarred());
|
||||||
|
|
||||||
|
GHGist newGist = gist.fork();
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (GHGist g : gist.listForks()) {
|
||||||
|
if (g.equals(newGist)) {
|
||||||
|
// expected to find it in the clone list
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fail("Expected to find a newly cloned gist");
|
||||||
|
} finally {
|
||||||
|
newGist.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gistFile() throws Exception {
|
||||||
|
GHGist gist = gitHub.getGist("9903708");
|
||||||
|
|
||||||
|
assertTrue(gist.isPublic());
|
||||||
|
|
||||||
|
assertEquals(1,gist.getFiles().size());
|
||||||
|
GHGistFile f = gist.getFile("keybase.md");
|
||||||
|
|
||||||
|
assertEquals("text/plain", f.getType());
|
||||||
|
assertEquals("Markdown", f.getLanguage());
|
||||||
|
assertTrue(f.getContent().contains("### Keybase proof"));
|
||||||
|
assertNotNull(f.getContent());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,11 @@
|
|||||||
package org.kohsuke;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.eclipse.jgit.dircache.DirCache;
|
import org.eclipse.jgit.dircache.DirCache;
|
||||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||||
import org.kohsuke.github.GHAsset;
|
import org.junit.Test;
|
||||||
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.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -22,24 +15,19 @@ import java.io.PrintWriter;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class LifecycleTest extends TestCase {
|
public class LifecycleTest extends AbstractGitHubApiTestBase {
|
||||||
private GitHub gitHub;
|
@Test
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
gitHub = GitHub.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCreateRepository() throws IOException, GitAPIException, InterruptedException {
|
public void testCreateRepository() throws IOException, GitAPIException, InterruptedException {
|
||||||
GHMyself myself = gitHub.getMyself();
|
GHMyself myself = gitHub.getMyself();
|
||||||
GHRepository repository = myself.getRepository("github-api-test");
|
GHOrganization org = gitHub.getOrganization("github-api-test-org");
|
||||||
|
GHRepository repository = org.getRepository("github-api-test");
|
||||||
if (repository != null) {
|
if (repository != null) {
|
||||||
repository.delete();
|
repository.delete();
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
repository = gitHub.createRepository("github-api-test",
|
repository = org.createRepository("github-api-test",
|
||||||
"a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", true);
|
"a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", "Core Developers", true);
|
||||||
|
Thread.sleep(1000); // wait for the repository to become ready
|
||||||
|
|
||||||
assertTrue(repository.getReleases().isEmpty());
|
assertTrue(repository.getReleases().isEmpty());
|
||||||
try {
|
try {
|
||||||
@@ -54,7 +42,7 @@ public class LifecycleTest extends TestCase {
|
|||||||
delete(repoDir);
|
delete(repoDir);
|
||||||
Git origin = Git.cloneRepository()
|
Git origin = Git.cloneRepository()
|
||||||
.setBare(false)
|
.setBare(false)
|
||||||
.setURI(repository.gitHttpTransportUrl())
|
.setURI(repository.getSshUrl())
|
||||||
.setDirectory(repoDir)
|
.setDirectory(repoDir)
|
||||||
.setCredentialsProvider(getCredentialsProvider(myself))
|
.setCredentialsProvider(getCredentialsProvider(myself))
|
||||||
.call();
|
.call();
|
||||||
18
src/test/java/org/kohsuke/github/PullRequestTest.java
Normal file
18
src/test/java/org/kohsuke/github/PullRequestTest.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class PullRequestTest extends AbstractGitHubApiTestBase {
|
||||||
|
@Test
|
||||||
|
public void createPullRequest() throws Exception {
|
||||||
|
GHRepository j = gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
||||||
|
String name = rnd.next();
|
||||||
|
GHPullRequest p = j.createPullRequest(name, "stable", "master", "## test");
|
||||||
|
System.out.println(p.getUrl());
|
||||||
|
assertEquals(name, p.getTitle());
|
||||||
|
p.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
91
src/test/java/org/kohsuke/github/RepositoryTest.java
Normal file
91
src/test/java/org/kohsuke/github/RepositoryTest.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luciano P. Sabenca (luciano.sabenca [at] movile [com] | lucianosabenca [at] gmail [dot] com
|
||||||
|
*/
|
||||||
|
public class RepositoryTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
GitHub mockGitHub;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
Iterator<GHUser[]> iterator;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
GHRepository mockRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void listCollaborators() throws Exception {
|
||||||
|
GHUser user1 = new GHUser();
|
||||||
|
user1.login = "login1";
|
||||||
|
|
||||||
|
GHUser user2 = new GHUser();
|
||||||
|
user2.login = "login2";
|
||||||
|
|
||||||
|
|
||||||
|
when(iterator.hasNext()).thenReturn(true, false, true);
|
||||||
|
when(iterator.next()).thenReturn(new GHUser[]{user1}, new GHUser[]{user2});
|
||||||
|
|
||||||
|
Requester requester = Mockito.mock(Requester.class);
|
||||||
|
when(mockGitHub.retrieve()).thenReturn(requester);
|
||||||
|
|
||||||
|
|
||||||
|
when(requester.asIterator("/repos/*/*/collaborators",
|
||||||
|
GHUser[].class)).thenReturn(iterator, iterator);
|
||||||
|
|
||||||
|
|
||||||
|
PagedIterable<GHUser> pagedIterable = Mockito.mock(PagedIterable.class);
|
||||||
|
when(mockRepository.listCollaborators()).thenReturn(pagedIterable);
|
||||||
|
|
||||||
|
PagedIterator<GHUser> userPagedIterator = new PagedIterator<GHUser>(iterator) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PagedIterator<GHUser> userPagedIterator2 = new PagedIterator<GHUser>(iterator) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
when(pagedIterable.iterator()).thenReturn(userPagedIterator, userPagedIterator2);
|
||||||
|
|
||||||
|
Iterator<GHUser> returnIterator1 = mockRepository.listCollaborators().iterator();
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertTrue(returnIterator1.hasNext());
|
||||||
|
GHUser user = returnIterator1.next();
|
||||||
|
Assert.assertEquals(user, user1);
|
||||||
|
Assert.assertFalse(returnIterator1.hasNext());
|
||||||
|
|
||||||
|
|
||||||
|
Iterator returnIterator2 = mockRepository.listCollaborators().iterator();
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertTrue(returnIterator2.hasNext());
|
||||||
|
user = returnIterator1.next();
|
||||||
|
Assert.assertEquals(user, user2);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user