mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 00:11:25 +00:00
Compare commits
77 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1bab63ebd | ||
|
|
40f012b03c | ||
|
|
a380059389 | ||
|
|
24b998ba2d | ||
|
|
9a1bb09c9f | ||
|
|
3ad66f8937 | ||
|
|
a6f3e7df55 | ||
|
|
9345d3be31 | ||
|
|
8e85bf8839 | ||
|
|
1012dcd194 | ||
|
|
70251ea11e | ||
|
|
9381471fbd | ||
|
|
1c4b716f1a | ||
|
|
c8b0584127 | ||
|
|
5194a361f4 | ||
|
|
c44e5d2a87 | ||
|
|
ee4d514b66 | ||
|
|
863995cb50 | ||
|
|
cbfe72a76e | ||
|
|
4f17d3519c | ||
|
|
3cfcad76ac | ||
|
|
1ca6535811 | ||
|
|
53612ad2e4 | ||
|
|
4b799d264c | ||
|
|
ca5594703a | ||
|
|
7fc2d9dcca | ||
|
|
c413fc1e30 | ||
|
|
b5086c7759 | ||
|
|
92a015ca4d | ||
|
|
3b2802e36d | ||
|
|
7bf23eaa15 | ||
|
|
9afd1c5ee8 | ||
|
|
5e36377b36 | ||
|
|
c988df13a8 | ||
|
|
29a40d31b7 | ||
|
|
ddc27e818b | ||
|
|
3fa70ac841 | ||
|
|
b2b7dfaf37 | ||
|
|
c309c2cf13 | ||
|
|
0ffcbdbd38 | ||
|
|
e368a17420 | ||
|
|
2fcfb2f67d | ||
|
|
f68a85056e | ||
|
|
943f47d29d | ||
|
|
fd37a2c466 | ||
|
|
eacdd7afe8 | ||
|
|
fe5ea52cdf | ||
|
|
ca6d77cbb3 | ||
|
|
1145941d11 | ||
|
|
d61697a152 | ||
|
|
38b77a9c79 | ||
|
|
7d294ee8c2 | ||
|
|
33d9422d03 | ||
|
|
bb7302c23a | ||
|
|
d50ae63a5a | ||
|
|
1961836e19 | ||
|
|
f2ed7c15ce | ||
|
|
4dce173630 | ||
|
|
86f868b2d4 | ||
|
|
363064f5c0 | ||
|
|
9d99ee9cfc | ||
|
|
db8969707d | ||
|
|
a24ac37dfd | ||
|
|
1b04d471b3 | ||
|
|
9cc400a081 | ||
|
|
e233aeec0c | ||
|
|
5dfd621900 | ||
|
|
f0f6a9988f | ||
|
|
587438938c | ||
|
|
75918c59cc | ||
|
|
8b38a20c18 | ||
|
|
e7b76bfdc5 | ||
|
|
3503ff6d36 | ||
|
|
192e21a9fc | ||
|
|
24e288d584 | ||
|
|
0e5ffda5e5 | ||
|
|
cdf6f18ec0 |
13
pom.xml
13
pom.xml
@@ -3,11 +3,11 @@
|
||||
<parent>
|
||||
<groupId>org.kohsuke</groupId>
|
||||
<artifactId>pom</artifactId>
|
||||
<version>17</version>
|
||||
<version>20</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>github-api</artifactId>
|
||||
<version>1.91</version>
|
||||
<version>1.95</version>
|
||||
<name>GitHub API for Java</name>
|
||||
<url>http://github-api.kohsuke.org/</url>
|
||||
<description>GitHub API for Java</description>
|
||||
@@ -16,7 +16,7 @@
|
||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||
<tag>github-api-1.91</tag>
|
||||
<tag>github-api-1.95</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
@@ -36,6 +36,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<configuration>
|
||||
<rerunFailingTestsCount>2</rerunFailingTestsCount>
|
||||
</configuration>
|
||||
@@ -96,9 +97,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
|
||||
@@ -65,9 +65,8 @@ public class GHBranch {
|
||||
return GitHub.parseURL(protection_url);
|
||||
}
|
||||
|
||||
@Preview @Deprecated
|
||||
public GHBranchProtection getProtection() throws IOException {
|
||||
return root.retrieve().withPreview(LOKI).to(protection_url, GHBranchProtection.class);
|
||||
return root.retrieve().to(protection_url, GHBranchProtection.class).wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,9 +79,8 @@ public class GHBranch {
|
||||
/**
|
||||
* Disables branch protection and allows anyone with push access to push changes.
|
||||
*/
|
||||
@Preview @Deprecated
|
||||
public void disableProtection() throws IOException {
|
||||
new Requester(root).method("DELETE").withPreview(LOKI).to(protection_url);
|
||||
new Requester(root).method("DELETE").to(protection_url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,27 +3,46 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import static org.kohsuke.github.Previews.ZZZAX;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||
"URF_UNREAD_FIELD" }, justification = "JSON API")
|
||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||
"URF_UNREAD_FIELD"}, justification = "JSON API")
|
||||
public class GHBranchProtection {
|
||||
@JsonProperty("enforce_admins")
|
||||
private EnforceAdmins enforceAdmins;
|
||||
private static final String REQUIRE_SIGNATURES_URI = "/required_signatures";
|
||||
|
||||
@JsonProperty("required_pull_request_reviews")
|
||||
private RequiredReviews requiredReviews;
|
||||
@JsonProperty("enforce_admins")
|
||||
private EnforceAdmins enforceAdmins;
|
||||
|
||||
@JsonProperty("required_status_checks")
|
||||
private RequiredStatusChecks requiredStatusChecks;
|
||||
private GitHub root;
|
||||
|
||||
@JsonProperty
|
||||
private Restrictions restrictions;
|
||||
@JsonProperty("required_pull_request_reviews")
|
||||
private RequiredReviews requiredReviews;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
public EnforceAdmins getEnforceAdmins() {
|
||||
@JsonProperty("required_status_checks")
|
||||
private RequiredStatusChecks requiredStatusChecks;
|
||||
|
||||
@JsonProperty
|
||||
private Restrictions restrictions;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
@Preview @Deprecated
|
||||
public void enabledSignedCommits() throws IOException {
|
||||
requester().method("POST")
|
||||
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class);
|
||||
}
|
||||
|
||||
@Preview @Deprecated
|
||||
public void disableSignedCommits() throws IOException {
|
||||
requester().method("DELETE")
|
||||
.to(url + REQUIRE_SIGNATURES_URI);
|
||||
}
|
||||
|
||||
public EnforceAdmins getEnforceAdmins() {
|
||||
return enforceAdmins;
|
||||
}
|
||||
|
||||
@@ -31,6 +50,12 @@ public class GHBranchProtection {
|
||||
return requiredReviews;
|
||||
}
|
||||
|
||||
@Preview @Deprecated
|
||||
public boolean getRequiredSignatures() throws IOException {
|
||||
return requester().method("GET")
|
||||
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled;
|
||||
}
|
||||
|
||||
public RequiredStatusChecks getRequiredStatusChecks() {
|
||||
return requiredStatusChecks;
|
||||
}
|
||||
@@ -43,12 +68,21 @@ public class GHBranchProtection {
|
||||
return url;
|
||||
}
|
||||
|
||||
public static class EnforceAdmins {
|
||||
@JsonProperty
|
||||
private boolean enabled;
|
||||
GHBranchProtection wrap(GHBranch branch) {
|
||||
this.root = branch.getRoot();
|
||||
return this;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
private Requester requester() {
|
||||
return new Requester(root).withPreview(ZZZAX);
|
||||
}
|
||||
|
||||
public static class EnforceAdmins {
|
||||
@JsonProperty
|
||||
private boolean enabled;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
@@ -57,20 +91,23 @@ public class GHBranchProtection {
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequiredReviews {
|
||||
@JsonProperty("dismissal_restrictions")
|
||||
private Restrictions dismissalRestriction;
|
||||
public static class RequiredReviews {
|
||||
@JsonProperty("dismissal_restrictions")
|
||||
private Restrictions dismissalRestriction;
|
||||
|
||||
@JsonProperty("dismiss_stale_reviews")
|
||||
private boolean dismissStaleReviews;
|
||||
@JsonProperty("dismiss_stale_reviews")
|
||||
private boolean dismissStaleReviews;
|
||||
|
||||
@JsonProperty("require_code_owner_reviews")
|
||||
private boolean requireCodeOwnerReviews;
|
||||
@JsonProperty("require_code_owner_reviews")
|
||||
private boolean requireCodeOwnerReviews;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
@JsonProperty("required_approving_review_count")
|
||||
private int requiredReviewers;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
public Restrictions getDismissalRestrictions() {
|
||||
return dismissalRestriction;
|
||||
@@ -87,17 +124,37 @@ public class GHBranchProtection {
|
||||
public boolean isRequireCodeOwnerReviews() {
|
||||
return requireCodeOwnerReviews;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequiredStatusChecks {
|
||||
@JsonProperty
|
||||
private Collection<String> contexts;
|
||||
public int getRequiredReviewers() {
|
||||
return requiredReviewers;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
private boolean strict;
|
||||
private static class RequiredSignatures {
|
||||
@JsonProperty
|
||||
private boolean enabled;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequiredStatusChecks {
|
||||
@JsonProperty
|
||||
private Collection<String> contexts;
|
||||
|
||||
@JsonProperty
|
||||
private boolean strict;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
public Collection<String> getContexts() {
|
||||
return contexts;
|
||||
@@ -110,23 +167,23 @@ public class GHBranchProtection {
|
||||
public boolean isRequiresBranchUpToDate() {
|
||||
return strict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Restrictions {
|
||||
@JsonProperty
|
||||
private Collection<GHTeam> teams;
|
||||
public static class Restrictions {
|
||||
@JsonProperty
|
||||
private Collection<GHTeam> teams;
|
||||
|
||||
@JsonProperty("teams_url")
|
||||
private String teamsUrl;
|
||||
@JsonProperty("teams_url")
|
||||
private String teamsUrl;
|
||||
|
||||
@JsonProperty
|
||||
private String url;
|
||||
@JsonProperty
|
||||
private String url;
|
||||
|
||||
@JsonProperty
|
||||
private Collection<GHUser> users;
|
||||
@JsonProperty
|
||||
private Collection<GHUser> users;
|
||||
|
||||
@JsonProperty("users_url")
|
||||
private String usersUrl;
|
||||
@JsonProperty("users_url")
|
||||
private String usersUrl;
|
||||
|
||||
public Collection<GHTeam> getTeams() {
|
||||
return teams;
|
||||
@@ -147,5 +204,5 @@ public class GHBranchProtection {
|
||||
public String getUsersUrl() {
|
||||
return usersUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,11 @@ public class GHBranchProtectionBuilder {
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder dismissStaleReviews() {
|
||||
getPrReviews().put("dismiss_stale_reviews", true);
|
||||
return dismissStaleReviews(true);
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder dismissStaleReviews(boolean v) {
|
||||
getPrReviews().put("dismiss_stale_reviews", v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -54,7 +58,8 @@ public class GHBranchProtectionBuilder {
|
||||
.withNullable("required_pull_request_reviews", prReviews)
|
||||
.withNullable("restrictions", restrictions)
|
||||
.withNullable("enforce_admins", enforceAdmins)
|
||||
.to(branch.getProtectionUrl().toString(), GHBranchProtection.class);
|
||||
.to(branch.getProtectionUrl().toString(), GHBranchProtection.class)
|
||||
.wrap(branch);
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder includeAdmins() {
|
||||
@@ -66,6 +71,11 @@ public class GHBranchProtectionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder requiredReviewers(int v) {
|
||||
getPrReviews().put("required_approving_review_count", v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder requireBranchIsUpToDate() {
|
||||
return requireBranchIsUpToDate(true);
|
||||
}
|
||||
@@ -89,6 +99,16 @@ public class GHBranchProtectionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder restrictReviewDismissals() {
|
||||
getPrReviews();
|
||||
|
||||
if (!prReviews.containsKey("dismissal_restrictions")) {
|
||||
prReviews.put("dismissal_restrictions", new Restrictions());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHBranchProtectionBuilder restrictPushAccess() {
|
||||
getRestrictions();
|
||||
return this;
|
||||
@@ -151,12 +171,7 @@ public class GHBranchProtectionBuilder {
|
||||
}
|
||||
|
||||
private void addReviewRestriction(String restriction, boolean isTeam) {
|
||||
getPrReviews();
|
||||
|
||||
if (!prReviews.containsKey("dismissal_restrictions")) {
|
||||
prReviews.put("dismissal_restrictions", new Restrictions());
|
||||
}
|
||||
|
||||
restrictReviewDismissals();
|
||||
Restrictions restrictions = (Restrictions) prReviews.get("dismissal_restrictions");
|
||||
|
||||
if (isTeam) {
|
||||
@@ -188,7 +203,7 @@ public class GHBranchProtectionBuilder {
|
||||
}
|
||||
|
||||
private Requester requester() {
|
||||
return new Requester(branch.getRoot()).withPreview(LOKI);
|
||||
return new Requester(branch.getRoot()).withPreview(LUKE_CAGE);
|
||||
}
|
||||
|
||||
private static class Restrictions {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
/**
|
||||
* How is an user associated with a repository?
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public enum GHCommentAuthorAssociation {
|
||||
/**
|
||||
* Author has been invited to collaborate on the repository.
|
||||
*/
|
||||
COLLABORATOR,
|
||||
/**
|
||||
* Author has previously committed to the repository.
|
||||
*/
|
||||
CONTRIBUTOR,
|
||||
/**
|
||||
* Author has not previously committed to GitHub.
|
||||
*/
|
||||
FIRST_TIMER,
|
||||
/**
|
||||
* Author has not previously committed to the repository.
|
||||
*/
|
||||
FIRST_TIME_CONTRIBUTOR,
|
||||
/**
|
||||
* Author is a member of the organization that owns the repository.
|
||||
*/
|
||||
MEMBER,
|
||||
/**
|
||||
* Author has no association with the repository.
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* Author is the owner of the repository.
|
||||
*/
|
||||
OWNER
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
76
src/main/java/org/kohsuke/github/GHContentBuilder.java
Normal file
76
src/main/java/org/kohsuke/github/GHContentBuilder.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* Used to create/update content.
|
||||
*
|
||||
* <p>
|
||||
* Call various methods to build up parameters, then call {@link #commit()} to make the change effective.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @see GHRepository#createContent()
|
||||
*/
|
||||
public final class GHContentBuilder {
|
||||
private final GHRepository repo;
|
||||
private final Requester req;
|
||||
private String path;
|
||||
|
||||
GHContentBuilder(GHRepository repo) {
|
||||
this.repo = repo;
|
||||
this.req = new Requester(repo.root).method("PUT");
|
||||
}
|
||||
|
||||
public GHContentBuilder path(String path) {
|
||||
this.path = path;
|
||||
req.with("path",path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHContentBuilder branch(String branch) {
|
||||
req.with("branch", branch);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when updating (but not creating a new content) to specify
|
||||
* Thetblob SHA of the file being replaced.
|
||||
*/
|
||||
public GHContentBuilder sha(String sha) {
|
||||
req.with("sha", sha);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHContentBuilder content(byte[] content) {
|
||||
req.with("content", Base64.encodeBase64String(content));
|
||||
return this;
|
||||
}
|
||||
|
||||
public GHContentBuilder content(String content) {
|
||||
try {
|
||||
return content(content.getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException x) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public GHContentBuilder message(String commitMessage) {
|
||||
req.with("message", commitMessage);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits a new content.
|
||||
*/
|
||||
public GHContentUpdateResponse commit() throws IOException {
|
||||
GHContentUpdateResponse response = req.to(repo.getApiTailUrl("contents/" + path), GHContentUpdateResponse.class);
|
||||
|
||||
response.getContent().wrap(repo);
|
||||
response.getCommit().wrapUp(repo);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -174,6 +174,51 @@ public abstract class GHEventPayload {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Issue has been assigned, unassigned, labeled, unlabeled, opened, edited, milestoned, demilestoned, closed, or reopened.
|
||||
*
|
||||
* @see <a href="http://developer.github.com/v3/activity/events/types/#issueevent">authoritative source</a>
|
||||
*/
|
||||
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
|
||||
justification = "Constructed by JSON deserialization")
|
||||
public static class Issue extends GHEventPayload {
|
||||
private String action;
|
||||
private GHIssue issue;
|
||||
private GHRepository repository;
|
||||
|
||||
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public GHIssue getIssue() {
|
||||
return issue;
|
||||
}
|
||||
|
||||
public void setIssue(GHIssue issue) {
|
||||
this.issue = issue;
|
||||
}
|
||||
|
||||
public GHRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public void setRepository(GHRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
void wrapUp(GitHub root) {
|
||||
super.wrapUp(root);
|
||||
if (repository != null) {
|
||||
repository.wrap(root);
|
||||
issue.wrap(repository);
|
||||
} else {
|
||||
issue.wrap(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A comment was added to an issue
|
||||
*
|
||||
@@ -716,6 +761,48 @@ public abstract class GHEventPayload {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A release was added to the repo
|
||||
*
|
||||
* @see <a href="http://developer.github.com/v3/activity/events/types/#releaseevent">authoritative source</a>
|
||||
*/
|
||||
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
|
||||
justification = "Constructed by JSON deserialization")
|
||||
public static class Release extends GHEventPayload {
|
||||
private String action;
|
||||
private GHRelease release;
|
||||
private GHRepository repository;
|
||||
|
||||
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public GHRelease getRelease() {
|
||||
return release;
|
||||
}
|
||||
|
||||
public void setRelease(GHRelease release) {
|
||||
this.release = release;
|
||||
}
|
||||
|
||||
public GHRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public void setRepository(GHRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
void wrapUp(GitHub root) {
|
||||
super.wrapUp(root);
|
||||
if (repository != null) {
|
||||
repository.wrap(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A repository was created, deleted, made public, or made private.
|
||||
*
|
||||
|
||||
46
src/main/java/org/kohsuke/github/GHInvitation.java
Normal file
46
src/main/java/org/kohsuke/github/GHInvitation.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @see GitHub#getMyInvitations()
|
||||
* @see GHRepository#listInvitations()
|
||||
*/
|
||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
||||
"NP_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD"}, justification = "JSON API")
|
||||
public class GHInvitation extends GHObject {
|
||||
/*package almost final*/ GitHub root;
|
||||
|
||||
private int id;
|
||||
private GHRepository repository;
|
||||
private GHUser invitee, inviter;
|
||||
private String permissions;
|
||||
private String html_url;
|
||||
|
||||
/*package*/ GHInvitation wrapUp(GitHub root) {
|
||||
this.root = root;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a repository invitation.
|
||||
*/
|
||||
public void accept() throws IOException {
|
||||
root.retrieve().method("PATCH").to("/user/repository_invitations/" + id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decline a repository invitation.
|
||||
*/
|
||||
public void decline() throws IOException {
|
||||
root.retrieve().method("DELETE").to("/user/repository_invitations/" + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getHtmlUrl() {
|
||||
return GitHub.parseURL(html_url);
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,10 @@
|
||||
|
||||
package org.kohsuke.github;
|
||||
|
||||
import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
|
||||
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -34,10 +35,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents an issue on GitHub.
|
||||
@@ -49,6 +50,8 @@ import static org.kohsuke.github.Previews.*;
|
||||
* @see GHIssueSearchBuilder
|
||||
*/
|
||||
public class GHIssue extends GHObject implements Reactable{
|
||||
private static final String ASSIGNEES = "assignees";
|
||||
|
||||
GitHub root;
|
||||
GHRepository owner;
|
||||
|
||||
@@ -215,6 +218,67 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
editIssue("labels",labels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds labels to the issue.
|
||||
*
|
||||
* @param names Names of the label
|
||||
*/
|
||||
public void addLabels(String... names) throws IOException {
|
||||
_addLabels(Arrays.asList(names));
|
||||
}
|
||||
|
||||
public void addLabels(GHLabel... labels) throws IOException {
|
||||
addLabels(Arrays.asList(labels));
|
||||
}
|
||||
|
||||
public void addLabels(Collection<GHLabel> labels) throws IOException {
|
||||
_addLabels(GHLabel.toNames(labels));
|
||||
}
|
||||
|
||||
private void _addLabels(Collection<String> names) throws IOException {
|
||||
List<String> newLabels = new ArrayList<String>();
|
||||
|
||||
for (GHLabel label : getLabels()) {
|
||||
newLabels.add(label.getName());
|
||||
}
|
||||
for (String name : names) {
|
||||
if (!newLabels.contains(name)) {
|
||||
newLabels.add(name);
|
||||
}
|
||||
}
|
||||
setLabels(newLabels.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given label by name from this issue.
|
||||
*/
|
||||
public void removeLabels(String... names) throws IOException {
|
||||
_removeLabels(Arrays.asList(names));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #removeLabels(String...)
|
||||
*/
|
||||
public void removeLabels(GHLabel... labels) throws IOException {
|
||||
removeLabels(Arrays.asList(labels));
|
||||
}
|
||||
|
||||
public void removeLabels(Collection<GHLabel> labels) throws IOException {
|
||||
_removeLabels(GHLabel.toNames(labels));
|
||||
}
|
||||
|
||||
private void _removeLabels(Collection<String> names) throws IOException {
|
||||
List<String> newLabels = new ArrayList<String>();
|
||||
|
||||
for (GHLabel l : getLabels()) {
|
||||
if (!names.contains(l.getName())) {
|
||||
newLabels.add(l.getName());
|
||||
}
|
||||
}
|
||||
|
||||
setLabels(newLabels.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains all the comments associated with this issue.
|
||||
*
|
||||
@@ -268,8 +332,7 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
}
|
||||
|
||||
public void addAssignees(Collection<GHUser> assignees) throws IOException {
|
||||
List<String> names = toLogins(assignees);
|
||||
root.retrieve().method("POST").with("assignees",names).to(getIssuesApiRoute()+"/assignees",this);
|
||||
root.retrieve().method("POST").withLogins(ASSIGNEES,assignees).to(getIssuesApiRoute()+"/assignees",this);
|
||||
}
|
||||
|
||||
public void setAssignees(GHUser... assignees) throws IOException {
|
||||
@@ -277,7 +340,7 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
}
|
||||
|
||||
public void setAssignees(Collection<GHUser> assignees) throws IOException {
|
||||
editIssue("assignees",toLogins(assignees));
|
||||
new Requester(root).withLogins(ASSIGNEES, assignees).method("PATCH").to(getIssuesApiRoute());
|
||||
}
|
||||
|
||||
public void removeAssignees(GHUser... assignees) throws IOException {
|
||||
@@ -285,16 +348,7 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
}
|
||||
|
||||
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
|
||||
List<String> names = toLogins(assignees);
|
||||
root.retrieve().method("DELETE").with("assignees",names).inBody().to(getIssuesApiRoute()+"/assignees",this);
|
||||
}
|
||||
|
||||
private List<String> toLogins(Collection<GHUser> assignees) {
|
||||
List<String> names = new ArrayList<String>(assignees.size());
|
||||
for (GHUser a : assignees) {
|
||||
names.add(a.getLogin());
|
||||
}
|
||||
return names;
|
||||
root.retrieve().method("DELETE").withLogins(ASSIGNEES,assignees).inBody().to(getIssuesApiRoute()+"/assignees",this);
|
||||
}
|
||||
|
||||
protected String getApiRoute() {
|
||||
|
||||
@@ -32,11 +32,13 @@ import static org.kohsuke.github.Previews.*;
|
||||
* Comment to the issue
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @see GHIssue#comment(String)
|
||||
* @see GHIssue#listComments()
|
||||
*/
|
||||
public class GHIssueComment extends GHObject implements Reactable {
|
||||
GHIssue owner;
|
||||
|
||||
private String body, gravatar_id;
|
||||
private String body, gravatar_id, html_url, author_association;
|
||||
private GHUser user; // not fully populated. beware.
|
||||
|
||||
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
||||
@@ -73,12 +75,13 @@ public class GHIssueComment extends GHObject implements Reactable {
|
||||
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.getLogin());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This object has no HTML URL.
|
||||
*/
|
||||
@Override
|
||||
public URL getHtmlUrl() {
|
||||
return null;
|
||||
return GitHub.parseURL(html_url);
|
||||
}
|
||||
|
||||
public GHCommentAuthorAssociation getAuthorAssociation() {
|
||||
return GHCommentAuthorAssociation.valueOf(author_association);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* SSH public key.
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -42,4 +45,12 @@ public class GHLabel {
|
||||
public void setColor(String newColor) throws IOException {
|
||||
repo.root.retrieve().method("PATCH").with("name", name).with("color", newColor).to(url);
|
||||
}
|
||||
|
||||
/*package*/ static Collection<String> toNames(Collection<GHLabel> labels) {
|
||||
List<String> r = new ArrayList<String>();
|
||||
for (GHLabel l : labels) {
|
||||
r.add(l.getName());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.kohsuke.github;
|
||||
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class GHOrganization extends GHPerson {
|
||||
* You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()}
|
||||
* to finally createa repository.
|
||||
*/
|
||||
public GHCreateRepositoryBuilder createRepository(String name) throws IOException {
|
||||
public GHCreateRepositoryBuilder createRepository(String name) {
|
||||
return new GHCreateRepositoryBuilder(root,"/orgs/"+login+"/repos",name);
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ public class GHOrganization extends GHPerson {
|
||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||
return new PagedIterable<GHRepository>() {
|
||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos?per_page=" + pageSize, GHRepository[].class, pageSize)) {
|
||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos", GHRepository[].class, pageSize)) {
|
||||
@Override
|
||||
protected void wrapUp(GHRepository[] page) {
|
||||
for (GHRepository c : page)
|
||||
@@ -277,7 +277,7 @@ public class GHOrganization extends GHPerson {
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}.withPageSize(pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class GHPerson extends GHObject {
|
||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||
return new PagedIterable<GHRepository>() {
|
||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class, pageSize)) {
|
||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos", GHRepository[].class, pageSize)) {
|
||||
@Override
|
||||
protected void wrapUp(GHRepository[] page) {
|
||||
for (GHRepository c : page)
|
||||
@@ -89,7 +89,7 @@ public abstract class GHPerson extends GHObject {
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}.withPageSize(pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ public abstract class GHPerson extends GHObject {
|
||||
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
||||
return new Iterable<List<GHRepository>>() {
|
||||
public Iterator<List<GHRepository>> iterator() {
|
||||
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class, pageSize);
|
||||
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos",GHRepository[].class, pageSize);
|
||||
|
||||
return new Iterator<List<GHRepository>>() {
|
||||
public boolean hasNext() {
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,6 +42,7 @@ import java.util.List;
|
||||
public class GHPullRequest extends GHIssue {
|
||||
|
||||
private static final String COMMENTS_ACTION = "/comments";
|
||||
private static final String REQUEST_REVIEWERS = "/requested_reviewers";
|
||||
|
||||
private String patch_url, diff_url, issue_url;
|
||||
private GHCommitPointer base;
|
||||
@@ -57,6 +59,9 @@ public class GHPullRequest extends GHIssue {
|
||||
private int changed_files;
|
||||
private String merge_commit_sha;
|
||||
|
||||
// pull request reviewers
|
||||
private GHUser[] requested_reviewers;
|
||||
|
||||
/**
|
||||
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API
|
||||
* route as opposed to 'issues' API route. This flag remembers whether we made the GET call on the 'issues' route
|
||||
@@ -75,6 +80,7 @@ public class GHPullRequest extends GHIssue {
|
||||
if (base != null) base.wrapUp(root);
|
||||
if (head != null) head.wrapUp(root);
|
||||
if (merged_by != null) merged_by.wrapUp(root);
|
||||
if (requested_reviewers != null) GHUser.wrap(requested_reviewers, root);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -218,6 +224,11 @@ public class GHPullRequest extends GHIssue {
|
||||
return merge_commit_sha;
|
||||
}
|
||||
|
||||
public List<GHUser> getRequestedReviewers() throws IOException {
|
||||
populate();
|
||||
return Collections.unmodifiableList(Arrays.asList(requested_reviewers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fully populate the data by retrieving missing data.
|
||||
*
|
||||
@@ -345,6 +356,12 @@ public class GHPullRequest extends GHIssue {
|
||||
.to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class).wrapUp(this);
|
||||
}
|
||||
|
||||
public void requestReviewers(List<GHUser> reviewers) throws IOException {
|
||||
new Requester(root).method("POST")
|
||||
.withLogins("reviewers", reviewers)
|
||||
.to(getApiRoute() + REQUEST_REVIEWERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge this pull request.
|
||||
*
|
||||
@@ -393,7 +410,7 @@ public class GHPullRequest extends GHIssue {
|
||||
|
||||
private void fetchIssue() throws IOException {
|
||||
if (!fetchedIssueDetails) {
|
||||
new Requester(root).to(getIssuesApiRoute(), this);
|
||||
new Requester(root).method("GET").to(getIssuesApiRoute(), this);
|
||||
fetchedIssueDetails = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class GHPullRequestFileDetail {
|
||||
String raw_url;
|
||||
String contents_url;
|
||||
String patch;
|
||||
String previous_filename;
|
||||
|
||||
public String getSha() {
|
||||
return sha;
|
||||
@@ -83,4 +84,9 @@ public class GHPullRequestFileDetail {
|
||||
public String getPatch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
public String getPreviousFilename()
|
||||
{
|
||||
return previous_filename;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class GHPullRequestReviewBuilder {
|
||||
/**
|
||||
* The review action you want to perform. The review actions include: APPROVE, REQUEST_CHANGES, or COMMENT.
|
||||
* By leaving this blank, you set the review action state to PENDING,
|
||||
* which means you will need to {@linkplain GHPullRequestReview#submit() submit the pull request review} when you are ready.
|
||||
* which means you will need to {@linkplain GHPullRequestReview#submit(String, GHPullRequestReviewEvent) submit the pull request review} when you are ready.
|
||||
*/
|
||||
public GHPullRequestReviewBuilder event(GHPullRequestReviewEvent event) {
|
||||
builder.with("event",event.action());
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -125,12 +126,21 @@ public class GHRelease extends GHObject {
|
||||
* handling of the HTTP requests to github's API.
|
||||
*/
|
||||
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
||||
FileInputStream s = new FileInputStream(file);
|
||||
try {
|
||||
return uploadAsset(file.getName(), s, contentType);
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
|
||||
Requester builder = new Requester(owner.root);
|
||||
|
||||
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
|
||||
owner.getApiTailUrl(""), getId(), file.getName());
|
||||
owner.getApiTailUrl(""), getId(), filename);
|
||||
return builder.contentType(contentType)
|
||||
.with(new FileInputStream(file))
|
||||
.with(stream)
|
||||
.to(url, GHAsset.class).wrap(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -35,7 +34,6 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.ArrayList;
|
||||
@@ -50,6 +48,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
@@ -76,15 +75,15 @@ public class GHRepository extends GHObject {
|
||||
|
||||
private String git_url, ssh_url, clone_url, svn_url, mirror_url;
|
||||
private GHUser owner; // not fully populated. beware.
|
||||
private boolean has_issues, has_wiki, fork, has_downloads, has_pages;
|
||||
private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived;
|
||||
@JsonProperty("private")
|
||||
private boolean _private;
|
||||
private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count;
|
||||
private String pushed_at;
|
||||
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
||||
private Map<Integer,GHMilestone> milestones = new WeakHashMap<Integer, GHMilestone>();
|
||||
|
||||
private String default_branch,language;
|
||||
private Map<String,GHCommit> commits = new HashMap<String, GHCommit>();
|
||||
private Map<String,GHCommit> commits = new WeakHashMap<String, GHCommit>();
|
||||
|
||||
@SkipFromToString
|
||||
private GHRepoPermission permissions;
|
||||
@@ -310,6 +309,22 @@ public class GHRepository extends GHObject {
|
||||
public List<GHRelease> getReleases() throws IOException {
|
||||
return listReleases().asList();
|
||||
}
|
||||
|
||||
public GHRelease getRelease(long id) throws IOException {
|
||||
try {
|
||||
return root.retrieve().to(getApiTailUrl("releases/" + id), GHRelease.class).wrap(this);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null; // no release for this id
|
||||
}
|
||||
}
|
||||
|
||||
public GHRelease getReleaseByTagName(String tag) throws IOException {
|
||||
try {
|
||||
return root.retrieve().to(getApiTailUrl("releases/tags/" + tag), GHRelease.class).wrap(this);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null; // no release for this tag
|
||||
}
|
||||
}
|
||||
|
||||
public GHRelease getLatestRelease() throws IOException {
|
||||
try {
|
||||
@@ -379,6 +394,10 @@ public class GHRepository extends GHObject {
|
||||
return fork;
|
||||
}
|
||||
|
||||
public boolean isArchived() {
|
||||
return archived;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of all forks of this repository.
|
||||
* This not only counts direct forks, but also forks of forks, and so on.
|
||||
@@ -815,7 +834,9 @@ public class GHRepository extends GHObject {
|
||||
public PagedIterator<GHRef> _iterator(int pageSize) {
|
||||
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
|
||||
protected void wrapUp(GHRef[] page) {
|
||||
// no-op
|
||||
for(GHRef p: page) {
|
||||
p.wrap(root);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1137,6 +1158,22 @@ public class GHRepository extends GHObject {
|
||||
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the invitations.
|
||||
*/
|
||||
public PagedIterable<GHInvitation> listInvitations() {
|
||||
return new PagedIterable<GHInvitation>() {
|
||||
public PagedIterator<GHInvitation> _iterator(int pageSize) {
|
||||
return new PagedIterator<GHInvitation>(root.retrieve().asIterator(String.format("/repos/%s/%s/invitations", getOwnerName(), name), GHInvitation[].class, pageSize)) {
|
||||
protected void wrapUp(GHInvitation[] page) {
|
||||
for (GHInvitation c : page)
|
||||
c.wrapUp(root);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the subscribers (aka watchers.)
|
||||
*
|
||||
@@ -1306,7 +1343,7 @@ public class GHRepository extends GHObject {
|
||||
*/
|
||||
public Map<String,GHBranch> getBranches() throws IOException {
|
||||
Map<String,GHBranch> r = new TreeMap<String,GHBranch>();
|
||||
for (GHBranch p : root.retrieve().withPreview(LOKI).to(getApiTailUrl("branches"), GHBranch[].class)) {
|
||||
for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) {
|
||||
p.wrap(this);
|
||||
r.put(p.getName(),p);
|
||||
}
|
||||
@@ -1314,7 +1351,7 @@ public class GHRepository extends GHObject {
|
||||
}
|
||||
|
||||
public GHBranch getBranch(String name) throws IOException {
|
||||
return root.retrieve().withPreview(LOKI).to(getApiTailUrl("branches/"+name),GHBranch.class).wrap(this);
|
||||
return root.retrieve().to(getApiTailUrl("branches/"+name),GHBranch.class).wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1394,41 +1431,43 @@ public class GHRepository extends GHObject {
|
||||
return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new content, or update an existing content.
|
||||
*/
|
||||
public GHContentBuilder createContent() {
|
||||
return new GHContentBuilder(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #createContent()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException {
|
||||
return createContent(content, commitMessage, path, null);
|
||||
return createContent().content(content).message(commitMessage).path(path).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #createContent()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException {
|
||||
final byte[] payload;
|
||||
try {
|
||||
payload = content.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw (IOException) new IOException("UTF-8 encoding is not supported").initCause(ex);
|
||||
}
|
||||
return createContent(payload, commitMessage, path, branch);
|
||||
return createContent().content(content).message(commitMessage).path(path).branch(branch).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #createContent()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException {
|
||||
return createContent(contentBytes, commitMessage, path, null);
|
||||
return createContent().content(contentBytes).message(commitMessage).path(path).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #createContent()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch) throws IOException {
|
||||
Requester requester = new Requester(root)
|
||||
.with("path", path)
|
||||
.with("message", commitMessage)
|
||||
.with("content", Base64.encodeBase64String(contentBytes))
|
||||
.method("PUT");
|
||||
|
||||
if (branch != null) {
|
||||
requester.with("branch", branch);
|
||||
}
|
||||
|
||||
GHContentUpdateResponse response = requester.to(getApiTailUrl("contents/" + path), GHContentUpdateResponse.class);
|
||||
|
||||
response.getContent().wrap(this);
|
||||
response.getCommit().wrapUp(this);
|
||||
|
||||
return response;
|
||||
return createContent().content(contentBytes).message(commitMessage).path(path).branch(branch).commit();
|
||||
}
|
||||
|
||||
public GHMilestone createMilestone(String title, String description) throws IOException {
|
||||
|
||||
@@ -55,6 +55,10 @@ public class GHRepositorySearchBuilder extends GHSearchBuilder<GHRepository> {
|
||||
return q("stars:"+v);
|
||||
}
|
||||
|
||||
public GHRepositorySearchBuilder topic(String v) {
|
||||
return q("topic:"+v);
|
||||
}
|
||||
|
||||
public GHRepositorySearchBuilder order(GHDirection v) {
|
||||
req.with("order",v);
|
||||
return this;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
@@ -529,6 +530,15 @@ public class GitHub {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets complete list of open invitations for current user.
|
||||
*/
|
||||
public List<GHInvitation> getMyInvitations() throws IOException {
|
||||
GHInvitation[] invitations = retrieve().to("/user/repository_invitations", GHInvitation[].class);
|
||||
for (GHInvitation i : invitations) {
|
||||
i.wrapUp(this);
|
||||
}
|
||||
return Arrays.asList(invitations);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a shallowly populated organizations.
|
||||
@@ -909,6 +919,7 @@ public class GitHub {
|
||||
static {
|
||||
MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY));
|
||||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);
|
||||
}
|
||||
|
||||
/* package */ static final String GITHUB_URL = "https://api.github.com";
|
||||
|
||||
@@ -4,8 +4,9 @@ package org.kohsuke.github;
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
/*package*/ class Previews {
|
||||
static final String LOKI = "application/vnd.github.loki-preview+json";
|
||||
static final String LUKE_CAGE = "application/vnd.github.luke-cage-preview+json";
|
||||
static final String DRAX = "application/vnd.github.drax-preview+json";
|
||||
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
|
||||
static final String CLOAK = "application/vnd.github.cloak-preview";
|
||||
static final String ZZZAX = "application/vnd.github.zzzax-preview+json";
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class RateLimitHandler {
|
||||
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
||||
try {
|
||||
Thread.sleep(parseWaitTime(uc));
|
||||
} catch (InterruptedException _) {
|
||||
} catch (InterruptedException x) {
|
||||
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.WillClose;
|
||||
@@ -63,7 +63,7 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.FINEST;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.apache.commons.lang.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.kohsuke.github.GitHub.MAPPER;
|
||||
|
||||
/**
|
||||
@@ -169,6 +169,14 @@ class Requester {
|
||||
return _with(key, value);
|
||||
}
|
||||
|
||||
public Requester withLogins(String key, Collection<GHUser> users) {
|
||||
List<String> names = new ArrayList<String>(users.size());
|
||||
for (GHUser a : users) {
|
||||
names.add(a.getLogin());
|
||||
}
|
||||
return with(key,names);
|
||||
}
|
||||
|
||||
public Requester with(String key, Map<String, String> value) {
|
||||
return _with(key, value);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
package org.kohsuke.github.extras;
|
||||
|
||||
import com.squareup.okhttp.ConnectionSpec;
|
||||
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;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
/**
|
||||
* {@link HttpConnector} for {@link OkHttpClient}.
|
||||
*
|
||||
@@ -23,10 +35,33 @@ public class OkHttpConnector implements HttpConnector {
|
||||
private final OkUrlFactory urlFactory;
|
||||
|
||||
public OkHttpConnector(OkUrlFactory urlFactory) {
|
||||
urlFactory.client().setSslSocketFactory(TlsSocketFactory());
|
||||
urlFactory.client().setConnectionSpecs(TlsConnectionSpecs());
|
||||
this.urlFactory = urlFactory;
|
||||
}
|
||||
|
||||
public HttpURLConnection connect(URL url) throws IOException {
|
||||
return urlFactory.open(url);
|
||||
}
|
||||
|
||||
/** Returns TLSv1.2 only SSL Socket Factory. */
|
||||
private SSLSocketFactory TlsSocketFactory() {
|
||||
SSLContext sc;
|
||||
try {
|
||||
sc = SSLContext.getInstance("TLSv1.2");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
sc.init(null, null, null);
|
||||
return sc.getSocketFactory();
|
||||
} catch (KeyManagementException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns connection spec with TLS v1.2 in it */
|
||||
private List<ConnectionSpec> TlsConnectionSpecs() {
|
||||
return Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
||||
|
||||
@Test
|
||||
public void testMembership() throws Exception {
|
||||
Set<String> members = gitHub.getOrganization("jenkinsci").getRepository("violations-plugin").getCollaboratorNames();
|
||||
Set<String> members = gitHub.getOrganization("github-api-test-org").getRepository("jenkins").getCollaboratorNames();
|
||||
System.out.println(members.contains("kohsuke"));
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,12 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
||||
branch = repo.getBranch(BRANCH);
|
||||
|
||||
if (branch.isProtected()) {
|
||||
GHBranchProtection protection = branch.getProtection();
|
||||
if (protection.getRequiredSignatures()) {
|
||||
protection.disableSignedCommits();
|
||||
}
|
||||
|
||||
assertFalse(protection.getRequiredSignatures());
|
||||
branch.disableProtection();
|
||||
}
|
||||
|
||||
@@ -47,6 +53,7 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
||||
.requireBranchIsUpToDate()
|
||||
.requireCodeOwnReviews()
|
||||
.dismissStaleReviews()
|
||||
.requiredReviewers(2)
|
||||
.includeAdmins()
|
||||
.enable();
|
||||
|
||||
@@ -59,6 +66,7 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
||||
assertNotNull(requiredReviews);
|
||||
assertTrue(requiredReviews.isDismissStaleReviews());
|
||||
assertTrue(requiredReviews.isRequireCodeOwnerReviews());
|
||||
assertEquals(2, requiredReviews.getRequiredReviewers());
|
||||
|
||||
EnforceAdmins enforceAdmins = protection.getEnforceAdmins();
|
||||
assertNotNull(enforceAdmins);
|
||||
@@ -79,4 +87,17 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
||||
|
||||
assertNotNull(protection.getRequiredReviews());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignedCommits() throws Exception {
|
||||
GHBranchProtection protection = branch.enableProtection().enable();
|
||||
|
||||
assertFalse(protection.getRequiredSignatures());
|
||||
|
||||
protection.enabledSignedCommits();
|
||||
assertTrue(protection.getRequiredSignatures());
|
||||
|
||||
protection.disableSignedCommits();
|
||||
assertFalse(protection.getRequiredSignatures());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ public class GHContentIntegrationTest extends AbstractGitHubApiTestBase {
|
||||
|
||||
@Test
|
||||
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();
|
||||
|
||||
assertNotNull(created.getCommit());
|
||||
|
||||
@@ -120,9 +120,19 @@ public class GHEventPayloadTest {
|
||||
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
||||
}
|
||||
|
||||
// TODO implement support classes and write test
|
||||
// @Test
|
||||
// public void issues() throws Exception {}
|
||||
@Test
|
||||
public void issues() throws Exception {
|
||||
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(),GHEventPayload.Issue.class);
|
||||
assertThat(event.getAction(),is("opened"));
|
||||
assertThat(event.getIssue().getNumber(), is(2));
|
||||
assertThat(event.getIssue().getTitle(), is("Spelling error in the README file"));
|
||||
assertThat(event.getIssue().getState(), is(GHIssueState.OPEN));
|
||||
assertThat(event.getIssue().getLabels().size(), is(1));
|
||||
assertThat(event.getIssue().getLabels().iterator().next().getName(), is("bug"));
|
||||
assertThat(event.getRepository().getName(), is("public-repo"));
|
||||
assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker"));
|
||||
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
||||
}
|
||||
|
||||
// TODO implement support classes and write test
|
||||
// @Test
|
||||
|
||||
@@ -105,6 +105,7 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
||||
String name = rnd.next();
|
||||
GHRef masterRef = getRepository().getRef("heads/master");
|
||||
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
|
||||
|
||||
getRepository().createContent(name, name, name, name);
|
||||
Thread.sleep(1000);
|
||||
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
|
||||
@@ -112,6 +113,27 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
||||
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
|
||||
branchRef.delete();
|
||||
}
|
||||
@Test
|
||||
public void testUpdateContentSquashMerge() throws Exception {
|
||||
String name = rnd.next();
|
||||
GHRef masterRef = getRepository().getRef("heads/master");
|
||||
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
|
||||
|
||||
GHContentUpdateResponse response = getRepository().createContent(name, name, name, name);
|
||||
Thread.sleep(1000);
|
||||
|
||||
getRepository().createContent()
|
||||
.content(name + name)
|
||||
.path(name)
|
||||
.branch(name)
|
||||
.message(name)
|
||||
.sha(response.getContent().getSha())
|
||||
.commit();
|
||||
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
|
||||
Thread.sleep(1000);
|
||||
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
|
||||
branchRef.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
// Requires push access to the test repo to pass
|
||||
|
||||
@@ -94,6 +94,36 @@ public class RepositoryTest extends AbstractGitHubApiTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void listReleases() throws IOException {
|
||||
PagedIterable<GHRelease> releases = gitHub.getOrganization("github").getRepository("hub").listReleases();
|
||||
assertTrue(releases.iterator().hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseExists() throws IOException {
|
||||
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getRelease(6839710);
|
||||
assertEquals("v2.3.0-pre10", release.getTagName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseDoesNotExist() throws IOException {
|
||||
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getRelease(Long.MAX_VALUE);
|
||||
assertNull(release);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseByTagNameExists() throws IOException {
|
||||
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getReleaseByTagName("v2.3.0-pre10");
|
||||
assertNotNull(release);
|
||||
assertEquals("v2.3.0-pre10", release.getTagName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseByTagNameDoesNotExist() throws IOException {
|
||||
GHRelease release = getRepository().getReleaseByTagName("foo-bar-baz");
|
||||
assertNull(release);
|
||||
}
|
||||
|
||||
private GHRepository getRepository() throws IOException {
|
||||
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ public class UserTest extends AbstractGitHubApiTestBase {
|
||||
public void listFollowsAndFollowers() throws IOException {
|
||||
GHUser u = gitHub.getUser("rtyler");
|
||||
assertNotEquals(
|
||||
count50(u.listFollowers()),
|
||||
count50(u.listFollows()));
|
||||
count30(u.listFollowers()),
|
||||
count30(u.listFollows()));
|
||||
}
|
||||
|
||||
private Set<GHUser> count50(PagedIterable<GHUser> l) {
|
||||
private Set<GHUser> count30(PagedIterable<GHUser> l) {
|
||||
Set<GHUser> users = new HashSet<GHUser>();
|
||||
PagedIterator<GHUser> itr = l.iterator();
|
||||
for (int i=0; i<50 && itr.hasNext(); i++) {
|
||||
for (int i=0; i<30 && itr.hasNext(); i++) {
|
||||
users.add(itr.next());
|
||||
}
|
||||
assertEquals(50, users.size());
|
||||
assertEquals(30, users.size());
|
||||
return users;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user