mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-12 00:11:22 +00:00
Compare commits
98 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
188245fa7f | ||
|
|
e10b747d6a | ||
|
|
f2bb6a05a5 | ||
|
|
f41da19db5 | ||
|
|
d0a56dbb21 | ||
|
|
acbf286e59 | ||
|
|
0f7c160409 | ||
|
|
5113aacb89 | ||
|
|
4e31636181 | ||
|
|
1e497d2c44 | ||
|
|
70bd4fa161 | ||
|
|
65996050d5 | ||
|
|
7f52031199 | ||
|
|
5430f3d33c | ||
|
|
43075faaf8 | ||
|
|
f3a1272e31 | ||
|
|
41c028d4d9 | ||
|
|
a17ce04552 | ||
|
|
d0b4652dcd | ||
|
|
e66f71c76e | ||
|
|
6effd4b846 | ||
|
|
df861f5403 | ||
|
|
e74346fed6 | ||
|
|
6961c467a6 | ||
|
|
892d305165 | ||
|
|
fa16261d7a | ||
|
|
15991fd2f7 | ||
|
|
c80b8f60f8 | ||
|
|
ab6253cbd0 | ||
|
|
35ba267115 | ||
|
|
ab24e6e1c1 | ||
|
|
e25ae27a15 | ||
|
|
0f81d1dbb3 | ||
|
|
ae1ec8b558 | ||
|
|
09c2b39530 |
11
pom.xml
11
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.90</version>
|
<version>1.94</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>http://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>github-api-1.90</tag>
|
<tag>github-api-1.94</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
@@ -96,9 +96,9 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>2.6</version>
|
<version>3.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
@@ -131,6 +131,7 @@
|
|||||||
<groupId>com.infradna.tool</groupId>
|
<groupId>com.infradna.tool</groupId>
|
||||||
<artifactId>bridge-method-annotation</artifactId>
|
<artifactId>bridge-method-annotation</artifactId>
|
||||||
<version>1.17</version>
|
<version>1.17</version>
|
||||||
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kohsuke.stapler</groupId>
|
<groupId>org.kohsuke.stapler</groupId>
|
||||||
|
|||||||
@@ -65,9 +65,8 @@ public class GHBranch {
|
|||||||
return GitHub.parseURL(protection_url);
|
return GitHub.parseURL(protection_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
|
||||||
public GHBranchProtection getProtection() throws IOException {
|
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.
|
* Disables branch protection and allows anyone with push access to push changes.
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
|
||||||
public void disableProtection() throws IOException {
|
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 com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.ZZZAX;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
"URF_UNREAD_FIELD" }, justification = "JSON API")
|
"URF_UNREAD_FIELD"}, justification = "JSON API")
|
||||||
public class GHBranchProtection {
|
public class GHBranchProtection {
|
||||||
@JsonProperty("enforce_admins")
|
private static final String REQUIRE_SIGNATURES_URI = "/required_signatures";
|
||||||
private EnforceAdmins enforceAdmins;
|
|
||||||
|
|
||||||
@JsonProperty("required_pull_request_reviews")
|
@JsonProperty("enforce_admins")
|
||||||
private RequiredReviews requiredReviews;
|
private EnforceAdmins enforceAdmins;
|
||||||
|
|
||||||
@JsonProperty("required_status_checks")
|
private GitHub root;
|
||||||
private RequiredStatusChecks requiredStatusChecks;
|
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty("required_pull_request_reviews")
|
||||||
private Restrictions restrictions;
|
private RequiredReviews requiredReviews;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty("required_status_checks")
|
||||||
private String url;
|
private RequiredStatusChecks requiredStatusChecks;
|
||||||
|
|
||||||
public EnforceAdmins getEnforceAdmins() {
|
@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;
|
return enforceAdmins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +50,12 @@ public class GHBranchProtection {
|
|||||||
return requiredReviews;
|
return requiredReviews;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview @Deprecated
|
||||||
|
public boolean getRequiredSignatures() throws IOException {
|
||||||
|
return requester().method("GET")
|
||||||
|
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public RequiredStatusChecks getRequiredStatusChecks() {
|
public RequiredStatusChecks getRequiredStatusChecks() {
|
||||||
return requiredStatusChecks;
|
return requiredStatusChecks;
|
||||||
}
|
}
|
||||||
@@ -43,12 +68,21 @@ public class GHBranchProtection {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EnforceAdmins {
|
GHBranchProtection wrap(GHBranch branch) {
|
||||||
@JsonProperty
|
this.root = branch.getRoot();
|
||||||
private boolean enabled;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@JsonProperty
|
private Requester requester() {
|
||||||
private String url;
|
return new Requester(root).withPreview(ZZZAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EnforceAdmins {
|
||||||
|
@JsonProperty
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String url;
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
@@ -57,20 +91,23 @@ public class GHBranchProtection {
|
|||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RequiredReviews {
|
public static class RequiredReviews {
|
||||||
@JsonProperty("dismissal_restrictions")
|
@JsonProperty("dismissal_restrictions")
|
||||||
private Restrictions dismissalRestriction;
|
private Restrictions dismissalRestriction;
|
||||||
|
|
||||||
@JsonProperty("dismiss_stale_reviews")
|
@JsonProperty("dismiss_stale_reviews")
|
||||||
private boolean dismissStaleReviews;
|
private boolean dismissStaleReviews;
|
||||||
|
|
||||||
@JsonProperty("require_code_owner_reviews")
|
@JsonProperty("require_code_owner_reviews")
|
||||||
private boolean requireCodeOwnerReviews;
|
private boolean requireCodeOwnerReviews;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty("required_approving_review_count")
|
||||||
private String url;
|
private int requiredReviewers;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String url;
|
||||||
|
|
||||||
public Restrictions getDismissalRestrictions() {
|
public Restrictions getDismissalRestrictions() {
|
||||||
return dismissalRestriction;
|
return dismissalRestriction;
|
||||||
@@ -87,17 +124,37 @@ public class GHBranchProtection {
|
|||||||
public boolean isRequireCodeOwnerReviews() {
|
public boolean isRequireCodeOwnerReviews() {
|
||||||
return requireCodeOwnerReviews;
|
return requireCodeOwnerReviews;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static class RequiredStatusChecks {
|
public int getRequiredReviewers() {
|
||||||
@JsonProperty
|
return requiredReviewers;
|
||||||
private Collection<String> contexts;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JsonProperty
|
private static class RequiredSignatures {
|
||||||
private boolean strict;
|
@JsonProperty
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
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() {
|
public Collection<String> getContexts() {
|
||||||
return contexts;
|
return contexts;
|
||||||
@@ -110,23 +167,23 @@ public class GHBranchProtection {
|
|||||||
public boolean isRequiresBranchUpToDate() {
|
public boolean isRequiresBranchUpToDate() {
|
||||||
return strict;
|
return strict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Restrictions {
|
public static class Restrictions {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private Collection<GHTeam> teams;
|
private Collection<GHTeam> teams;
|
||||||
|
|
||||||
@JsonProperty("teams_url")
|
@JsonProperty("teams_url")
|
||||||
private String teamsUrl;
|
private String teamsUrl;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private Collection<GHUser> users;
|
private Collection<GHUser> users;
|
||||||
|
|
||||||
@JsonProperty("users_url")
|
@JsonProperty("users_url")
|
||||||
private String usersUrl;
|
private String usersUrl;
|
||||||
|
|
||||||
public Collection<GHTeam> getTeams() {
|
public Collection<GHTeam> getTeams() {
|
||||||
return teams;
|
return teams;
|
||||||
@@ -147,5 +204,5 @@ public class GHBranchProtection {
|
|||||||
public String getUsersUrl() {
|
public String getUsersUrl() {
|
||||||
return usersUrl;
|
return usersUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ public class GHBranchProtectionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHBranchProtectionBuilder dismissStaleReviews() {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +58,8 @@ public class GHBranchProtectionBuilder {
|
|||||||
.withNullable("required_pull_request_reviews", prReviews)
|
.withNullable("required_pull_request_reviews", prReviews)
|
||||||
.withNullable("restrictions", restrictions)
|
.withNullable("restrictions", restrictions)
|
||||||
.withNullable("enforce_admins", enforceAdmins)
|
.withNullable("enforce_admins", enforceAdmins)
|
||||||
.to(branch.getProtectionUrl().toString(), GHBranchProtection.class);
|
.to(branch.getProtectionUrl().toString(), GHBranchProtection.class)
|
||||||
|
.wrap(branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHBranchProtectionBuilder includeAdmins() {
|
public GHBranchProtectionBuilder includeAdmins() {
|
||||||
@@ -66,6 +71,11 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHBranchProtectionBuilder requiredReviewers(int v) {
|
||||||
|
getPrReviews().put("required_approving_review_count", v);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public GHBranchProtectionBuilder requireBranchIsUpToDate() {
|
public GHBranchProtectionBuilder requireBranchIsUpToDate() {
|
||||||
return requireBranchIsUpToDate(true);
|
return requireBranchIsUpToDate(true);
|
||||||
}
|
}
|
||||||
@@ -89,6 +99,16 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHBranchProtectionBuilder restrictReviewDismissals() {
|
||||||
|
getPrReviews();
|
||||||
|
|
||||||
|
if (!prReviews.containsKey("dismissal_restrictions")) {
|
||||||
|
prReviews.put("dismissal_restrictions", new Restrictions());
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public GHBranchProtectionBuilder restrictPushAccess() {
|
public GHBranchProtectionBuilder restrictPushAccess() {
|
||||||
getRestrictions();
|
getRestrictions();
|
||||||
return this;
|
return this;
|
||||||
@@ -151,12 +171,7 @@ public class GHBranchProtectionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addReviewRestriction(String restriction, boolean isTeam) {
|
private void addReviewRestriction(String restriction, boolean isTeam) {
|
||||||
getPrReviews();
|
restrictReviewDismissals();
|
||||||
|
|
||||||
if (!prReviews.containsKey("dismissal_restrictions")) {
|
|
||||||
prReviews.put("dismissal_restrictions", new Restrictions());
|
|
||||||
}
|
|
||||||
|
|
||||||
Restrictions restrictions = (Restrictions) prReviews.get("dismissal_restrictions");
|
Restrictions restrictions = (Restrictions) prReviews.get("dismissal_restrictions");
|
||||||
|
|
||||||
if (isTeam) {
|
if (isTeam) {
|
||||||
@@ -188,7 +203,7 @@ public class GHBranchProtectionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Requester requester() {
|
private Requester requester() {
|
||||||
return new Requester(branch.getRoot()).withPreview(LOKI);
|
return new Requester(branch.getRoot()).withPreview(LUKE_CAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Restrictions {
|
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;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,8 +21,8 @@ public class GHCreateRepositoryBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHCreateRepositoryBuilder description(String description) {
|
public GHCreateRepositoryBuilder description(String description) {
|
||||||
this.builder.with("description",description);
|
this.builder.with("description",description);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHCreateRepositoryBuilder homepage(URL homepage) {
|
public GHCreateRepositoryBuilder homepage(URL homepage) {
|
||||||
@@ -74,6 +74,30 @@ public class GHCreateRepositoryBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow or disallow squash-merging pull requests.
|
||||||
|
*/
|
||||||
|
public GHCreateRepositoryBuilder allowSquashMerge(boolean b) {
|
||||||
|
this.builder.with("allow_squash_merge",b);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow or disallow merging pull requests with a merge commit.
|
||||||
|
*/
|
||||||
|
public GHCreateRepositoryBuilder allowMergeCommit(boolean b) {
|
||||||
|
this.builder.with("allow_merge_commit",b);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow or disallow rebase-merging pull requests.
|
||||||
|
*/
|
||||||
|
public GHCreateRepositoryBuilder allowRebaseMerge(boolean b) {
|
||||||
|
this.builder.with("allow_rebase_merge",b);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a default .gitignore
|
* Creates a default .gitignore
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,140 @@ public abstract class GHEventPayload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A review was added to a pull request
|
||||||
|
*
|
||||||
|
* @see <a href="https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent">authoritative source</a>
|
||||||
|
*/
|
||||||
|
public static class PullRequestReview extends GHEventPayload {
|
||||||
|
private String action;
|
||||||
|
private GHPullRequestReview review;
|
||||||
|
private GHPullRequest pull_request;
|
||||||
|
private GHRepository repository;
|
||||||
|
|
||||||
|
public String getAction() {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestReview getReview() {
|
||||||
|
return review;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequest getPullRequest() {
|
||||||
|
return pull_request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRepository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void wrapUp(GitHub root) {
|
||||||
|
super.wrapUp(root);
|
||||||
|
if (review==null)
|
||||||
|
throw new IllegalStateException("Expected pull_request_review payload, but got something else. Maybe we've got another type of event?");
|
||||||
|
|
||||||
|
review.wrapUp(pull_request);
|
||||||
|
|
||||||
|
if (repository!=null) {
|
||||||
|
repository.wrap(root);
|
||||||
|
pull_request.wrapUp(repository);
|
||||||
|
} else {
|
||||||
|
pull_request.wrapUp(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A review comment was added to a pull request
|
||||||
|
*
|
||||||
|
* @see <a href="https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent">authoritative source</a>
|
||||||
|
*/
|
||||||
|
public static class PullRequestReviewComment extends GHEventPayload {
|
||||||
|
private String action;
|
||||||
|
private GHPullRequestReviewComment comment;
|
||||||
|
private GHPullRequest pull_request;
|
||||||
|
private GHRepository repository;
|
||||||
|
|
||||||
|
public String getAction() {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestReviewComment getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequest getPullRequest() {
|
||||||
|
return pull_request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHRepository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void wrapUp(GitHub root) {
|
||||||
|
super.wrapUp(root);
|
||||||
|
if (comment==null)
|
||||||
|
throw new IllegalStateException("Expected pull_request_review_comment payload, but got something else. Maybe we've got another type of event?");
|
||||||
|
|
||||||
|
comment.wrapUp(pull_request);
|
||||||
|
|
||||||
|
if (repository!=null) {
|
||||||
|
repository.wrap(root);
|
||||||
|
pull_request.wrapUp(repository);
|
||||||
|
} else {
|
||||||
|
pull_request.wrapUp(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* A comment was added to an issue
|
||||||
*
|
*
|
||||||
@@ -627,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.
|
* A repository was created, deleted, made public, or made private.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class GHGist extends GHObject {
|
|||||||
* Used when caller obtains {@link GHGist} without knowing its owner.
|
* Used when caller obtains {@link GHGist} without knowing its owner.
|
||||||
* A partially constructed owner object is interned.
|
* A partially constructed owner object is interned.
|
||||||
*/
|
*/
|
||||||
/*package*/ GHGist wrapUp(GitHub root) throws IOException {
|
/*package*/ GHGist wrapUp(GitHub root) {
|
||||||
this.owner = root.getUser(owner);
|
this.owner = root.getUser(owner);
|
||||||
this.root = root;
|
this.root = root;
|
||||||
wrapUp();
|
wrapUp();
|
||||||
@@ -144,12 +144,8 @@ public class GHGist extends GHObject {
|
|||||||
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class, pageSize)) {
|
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHGist[] page) {
|
protected void wrapUp(GHGist[] page) {
|
||||||
try {
|
for (GHGist c : page)
|
||||||
for (GHGist c : page)
|
c.wrapUp(root);
|
||||||
c.wrapUp(root);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -49,6 +48,8 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
* @see GHIssueSearchBuilder
|
* @see GHIssueSearchBuilder
|
||||||
*/
|
*/
|
||||||
public class GHIssue extends GHObject implements Reactable{
|
public class GHIssue extends GHObject implements Reactable{
|
||||||
|
private static final String ASSIGNEES = "assignees";
|
||||||
|
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
@@ -203,6 +204,10 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
edit("body",body);
|
edit("body",body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMilestone(GHMilestone milestone) throws IOException {
|
||||||
|
edit("milestone",milestone.getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
public void assignTo(GHUser user) throws IOException {
|
public void assignTo(GHUser user) throws IOException {
|
||||||
setAssignees(user);
|
setAssignees(user);
|
||||||
}
|
}
|
||||||
@@ -264,8 +269,7 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addAssignees(Collection<GHUser> assignees) throws IOException {
|
public void addAssignees(Collection<GHUser> assignees) throws IOException {
|
||||||
List<String> names = toLogins(assignees);
|
root.retrieve().method("POST").withLogins(ASSIGNEES,assignees).to(getIssuesApiRoute()+"/assignees",this);
|
||||||
root.retrieve().method("POST").with("assignees",names).to(getIssuesApiRoute()+"/assignees",this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAssignees(GHUser... assignees) throws IOException {
|
public void setAssignees(GHUser... assignees) throws IOException {
|
||||||
@@ -273,7 +277,7 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAssignees(Collection<GHUser> assignees) throws IOException {
|
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 {
|
public void removeAssignees(GHUser... assignees) throws IOException {
|
||||||
@@ -281,16 +285,7 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
|
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
|
||||||
List<String> names = toLogins(assignees);
|
root.retrieve().method("DELETE").withLogins(ASSIGNEES,assignees).inBody().to(getIssuesApiRoute()+"/assignees",this);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
|
|||||||
@@ -32,11 +32,13 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
* Comment to the issue
|
* Comment to the issue
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHIssue#comment(String)
|
||||||
|
* @see GHIssue#listComments()
|
||||||
*/
|
*/
|
||||||
public class GHIssueComment extends GHObject implements Reactable {
|
public class GHIssueComment extends GHObject implements Reactable {
|
||||||
GHIssue owner;
|
GHIssue owner;
|
||||||
|
|
||||||
private String body, gravatar_id;
|
private String body, gravatar_id, html_url, author_association;
|
||||||
private GHUser user; // not fully populated. beware.
|
private GHUser user; // not fully populated. beware.
|
||||||
|
|
||||||
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
/*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());
|
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated This object has no HTML URL.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public URL getHtmlUrl() {
|
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;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSH public key.
|
* SSH public key.
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
|
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||||
import org.apache.commons.lang.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
import javax.annotation.CheckForNull;
|
||||||
import java.io.IOException;
|
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()}
|
* You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()}
|
||||||
* to finally createa repository.
|
* to finally createa repository.
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder createRepository(String name) throws IOException {
|
public GHCreateRepositoryBuilder createRepository(String name) {
|
||||||
return new GHCreateRepositoryBuilder(root,"/orgs/"+login+"/repos",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) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
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
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
@@ -277,7 +277,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
}.withPageSize(pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public abstract class GHPerson extends GHObject {
|
|||||||
if (created_at!=null) {
|
if (created_at!=null) {
|
||||||
return; // already populated
|
return; // already populated
|
||||||
}
|
}
|
||||||
if (root.isOffline()) {
|
if (root == null || root.isOffline()) {
|
||||||
return; // cannot populate, will have to live with what we have
|
return; // cannot populate, will have to live with what we have
|
||||||
}
|
}
|
||||||
root.retrieve().to(url, this);
|
root.retrieve().to(url, this);
|
||||||
@@ -81,7 +81,7 @@ public abstract class GHPerson extends GHObject {
|
|||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
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
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : 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) {
|
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
||||||
return new Iterable<List<GHRepository>>() {
|
return new Iterable<List<GHRepository>>() {
|
||||||
public Iterator<List<GHRepository>> iterator() {
|
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>>() {
|
return new Iterator<List<GHRepository>>() {
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
|
|||||||
@@ -26,23 +26,23 @@ package org.kohsuke.github;
|
|||||||
import javax.annotation.CheckForNull;
|
import javax.annotation.CheckForNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pull request.
|
* A pull request.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#getPullRequest(int)
|
* @see GHRepository#getPullRequest(int)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public class GHPullRequest extends GHIssue {
|
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 String patch_url, diff_url, issue_url;
|
||||||
private GHCommitPointer base;
|
private GHCommitPointer base;
|
||||||
private String merged_at;
|
private String merged_at;
|
||||||
@@ -91,7 +91,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
public URL getPatchUrl() {
|
public URL getPatchUrl() {
|
||||||
return GitHub.parseURL(patch_url);
|
return GitHub.parseURL(patch_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL of the patch file.
|
* The URL of the patch file.
|
||||||
* like https://github.com/jenkinsci/jenkins/pull/100.patch
|
* like https://github.com/jenkinsci/jenkins/pull/100.patch
|
||||||
@@ -114,7 +114,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
public GHCommitPointer getHead() {
|
public GHCommitPointer getHead() {
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Date getIssueUpdatedAt() throws IOException {
|
public Date getIssueUpdatedAt() throws IOException {
|
||||||
return super.getUpdatedAt();
|
return super.getUpdatedAt();
|
||||||
@@ -182,8 +182,17 @@ public class GHPullRequest extends GHIssue {
|
|||||||
return maintainer_can_modify;
|
return maintainer_can_modify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this PR mergeable?
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* null if the state has not been determined yet, for example when a PR is newly created.
|
||||||
|
* If this method is called on an instance whose mergeable state is not yet known,
|
||||||
|
* API call is made to retrieve the latest state.
|
||||||
|
*/
|
||||||
public Boolean getMergeable() throws IOException {
|
public Boolean getMergeable() throws IOException {
|
||||||
populate();
|
if (mergeable==null)
|
||||||
|
refresh();
|
||||||
return mergeable;
|
return mergeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +226,13 @@ public class GHPullRequest extends GHIssue {
|
|||||||
*/
|
*/
|
||||||
private void populate() throws IOException {
|
private void populate() throws IOException {
|
||||||
if (mergeable_state!=null) return; // already populated
|
if (mergeable_state!=null) return; // already populated
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repopulates this object.
|
||||||
|
*/
|
||||||
|
public void refresh() throws IOException {
|
||||||
if (root.isOffline()) {
|
if (root.isOffline()) {
|
||||||
return; // cannot populate, will have to live with what we have
|
return; // cannot populate, will have to live with what we have
|
||||||
}
|
}
|
||||||
@@ -246,7 +262,6 @@ public class GHPullRequest extends GHIssue {
|
|||||||
return new PagedIterable<GHPullRequestReview>() {
|
return new PagedIterable<GHPullRequestReview>() {
|
||||||
public PagedIterator<GHPullRequestReview> _iterator(int pageSize) {
|
public PagedIterator<GHPullRequestReview> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHPullRequestReview>(root.retrieve()
|
return new PagedIterator<GHPullRequestReview>(root.retrieve()
|
||||||
.withPreview(BLACK_CAT)
|
|
||||||
.asIterator(String.format("%s/reviews", getApiRoute()),
|
.asIterator(String.format("%s/reviews", getApiRoute()),
|
||||||
GHPullRequestReview[].class, pageSize)) {
|
GHPullRequestReview[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
@@ -266,7 +281,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
||||||
return new PagedIterable<GHPullRequestReviewComment>() {
|
return new PagedIterable<GHPullRequestReviewComment>() {
|
||||||
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHPullRequestReviewComment>(root.retrieve().asIterator(getApiRoute() + "/comments",
|
return new PagedIterator<GHPullRequestReviewComment>(root.retrieve().asIterator(getApiRoute() + COMMENTS_ACTION,
|
||||||
GHPullRequestReviewComment[].class, pageSize)) {
|
GHPullRequestReviewComment[].class, pageSize)) {
|
||||||
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
||||||
for (GHPullRequestReviewComment c : page)
|
for (GHPullRequestReviewComment c : page)
|
||||||
@@ -296,32 +311,30 @@ public class GHPullRequest extends GHIssue {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
/**
|
||||||
@Deprecated
|
* @deprecated
|
||||||
|
* Use {@link #createReview()}
|
||||||
|
*/
|
||||||
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
|
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
|
||||||
GHPullRequestReviewComment... comments)
|
GHPullRequestReviewComment... comments) throws IOException {
|
||||||
throws IOException {
|
|
||||||
return createReview(body, event, Arrays.asList(comments));
|
return createReview(body, event, Arrays.asList(comments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
/**
|
||||||
@Deprecated
|
* @deprecated
|
||||||
|
* Use {@link #createReview()}
|
||||||
|
*/
|
||||||
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
|
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
|
||||||
List<GHPullRequestReviewComment> comments)
|
List<GHPullRequestReviewComment> comments) throws IOException {
|
||||||
throws IOException {
|
GHPullRequestReviewBuilder b = createReview().body(body);
|
||||||
// if (event == null) {
|
|
||||||
// event = GHPullRequestReviewState.PENDING;
|
|
||||||
// }
|
|
||||||
List<DraftReviewComment> draftComments = new ArrayList<DraftReviewComment>(comments.size());
|
|
||||||
for (GHPullRequestReviewComment c : comments) {
|
for (GHPullRequestReviewComment c : comments) {
|
||||||
draftComments.add(new DraftReviewComment(c.getBody(), c.getPath(), c.getPosition()));
|
b.comment(c.getBody(), c.getPath(), c.getPosition());
|
||||||
}
|
}
|
||||||
return new Requester(root).method("POST")
|
return b.create();
|
||||||
.with("body", body)
|
}
|
||||||
//.with("event", event.name())
|
|
||||||
._with("comments", draftComments)
|
public GHPullRequestReviewBuilder createReview() {
|
||||||
.withPreview(BLACK_CAT)
|
return new GHPullRequestReviewBuilder(this);
|
||||||
.to(getApiRoute() + "/reviews", GHPullRequestReview.class).wrapUp(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException {
|
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException {
|
||||||
@@ -330,9 +343,15 @@ public class GHPullRequest extends GHIssue {
|
|||||||
.with("commit_id", sha)
|
.with("commit_id", sha)
|
||||||
.with("path", path)
|
.with("path", path)
|
||||||
.with("position", position)
|
.with("position", position)
|
||||||
.to(getApiRoute() + "/comments", GHPullRequestReviewComment.class).wrapUp(this);
|
.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.
|
* Merge this pull request.
|
||||||
*
|
*
|
||||||
@@ -371,42 +390,18 @@ public class GHPullRequest extends GHIssue {
|
|||||||
*/
|
*/
|
||||||
public void merge(String msg, String sha, MergeMethod method) throws IOException {
|
public void merge(String msg, String sha, MergeMethod method) throws IOException {
|
||||||
new Requester(root).method("PUT")
|
new Requester(root).method("PUT")
|
||||||
.with("commit_message",msg)
|
.with("commit_message", msg)
|
||||||
.with("sha",sha)
|
.with("sha", sha)
|
||||||
.with("merge_method",method)
|
.with("merge_method", method)
|
||||||
.to(getApiRoute()+"/merge");
|
.to(getApiRoute() + "/merge");
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MergeMethod{ MERGE, SQUASH, REBASE }
|
public enum MergeMethod{ MERGE, SQUASH, REBASE }
|
||||||
|
|
||||||
private void fetchIssue() throws IOException {
|
private void fetchIssue() throws IOException {
|
||||||
if (!fetchedIssueDetails) {
|
if (!fetchedIssueDetails) {
|
||||||
new Requester(root).to(getIssuesApiRoute(), this);
|
new Requester(root).method("GET").to(getIssuesApiRoute(), this);
|
||||||
fetchedIssueDetails = true;
|
fetchedIssueDetails = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DraftReviewComment {
|
|
||||||
private String body;
|
|
||||||
private String path;
|
|
||||||
private int position;
|
|
||||||
|
|
||||||
public DraftReviewComment(String body, String path, int position) {
|
|
||||||
this.body = body;
|
|
||||||
this.path = path;
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPosition() {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class GHPullRequestFileDetail {
|
|||||||
String raw_url;
|
String raw_url;
|
||||||
String contents_url;
|
String contents_url;
|
||||||
String patch;
|
String patch;
|
||||||
|
String previous_filename;
|
||||||
|
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
@@ -83,4 +84,9 @@ public class GHPullRequestFileDetail {
|
|||||||
public String getPatch() {
|
public String getPatch() {
|
||||||
return patch;
|
return patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPreviousFilename()
|
||||||
|
{
|
||||||
|
return previous_filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Review to the pull request
|
* Review to a pull request.
|
||||||
*
|
*
|
||||||
* @see GHPullRequest#listReviews()
|
* @see GHPullRequest#listReviews()
|
||||||
* @see GHPullRequest#createReview(String, GHPullRequestReviewState, GHPullRequestReviewComment...)
|
* @see GHPullRequestReviewBuilder
|
||||||
*/
|
*/
|
||||||
|
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
|
||||||
public class GHPullRequestReview extends GHObject {
|
public class GHPullRequestReview extends GHObject {
|
||||||
GHPullRequest owner;
|
GHPullRequest owner;
|
||||||
|
|
||||||
@@ -72,6 +74,7 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
return commit_id;
|
return commit_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckForNull
|
||||||
public GHPullRequestReviewState getState() {
|
public GHPullRequestReviewState getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -85,41 +88,41 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
return owner.getApiRoute()+"/reviews/"+id;
|
return owner.getApiRoute()+"/reviews/"+id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Former preview method that changed when it got public. Left here for backward compatibility.
|
||||||
|
* Use {@link #submit(String, GHPullRequestReviewEvent)}
|
||||||
|
*/
|
||||||
|
public void submit(String body, GHPullRequestReviewState state) throws IOException {
|
||||||
|
submit(body,state.toEvent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the comment.
|
* Updates the comment.
|
||||||
*/
|
*/
|
||||||
@Preview
|
public void submit(String body, GHPullRequestReviewEvent event) throws IOException {
|
||||||
@Deprecated
|
|
||||||
public void submit(String body, GHPullRequestReviewState event) throws IOException {
|
|
||||||
new Requester(owner.root).method("POST")
|
new Requester(owner.root).method("POST")
|
||||||
.with("body", body)
|
.with("body", body)
|
||||||
.with("event", event.action())
|
.with("event", event.action())
|
||||||
.withPreview("application/vnd.github.black-cat-preview+json")
|
|
||||||
.to(getApiRoute()+"/events",this);
|
.to(getApiRoute()+"/events",this);
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.state = event;
|
this.state = event.toState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this review.
|
* Deletes this review.
|
||||||
*/
|
*/
|
||||||
@Preview
|
|
||||||
@Deprecated
|
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).method("DELETE")
|
new Requester(owner.root).method("DELETE")
|
||||||
.withPreview(BLACK_CAT)
|
|
||||||
.to(getApiRoute());
|
.to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismisses this review.
|
* Dismisses this review.
|
||||||
*/
|
*/
|
||||||
@Preview
|
|
||||||
@Deprecated
|
|
||||||
public void dismiss(String message) throws IOException {
|
public void dismiss(String message) throws IOException {
|
||||||
new Requester(owner.root).method("PUT")
|
new Requester(owner.root).method("PUT")
|
||||||
.with("message", message)
|
.with("message", message)
|
||||||
.withPreview(BLACK_CAT)
|
|
||||||
.to(getApiRoute()+"/dismissals");
|
.to(getApiRoute()+"/dismissals");
|
||||||
state = GHPullRequestReviewState.DISMISSED;
|
state = GHPullRequestReviewState.DISMISSED;
|
||||||
}
|
}
|
||||||
@@ -127,14 +130,11 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
/**
|
/**
|
||||||
* Obtains all the review comments associated with this pull request review.
|
* Obtains all the review comments associated with this pull request review.
|
||||||
*/
|
*/
|
||||||
@Preview
|
|
||||||
@Deprecated
|
|
||||||
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
||||||
return new PagedIterable<GHPullRequestReviewComment>() {
|
return new PagedIterable<GHPullRequestReviewComment>() {
|
||||||
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHPullRequestReviewComment>(
|
return new PagedIterator<GHPullRequestReviewComment>(
|
||||||
owner.root.retrieve()
|
owner.root.retrieve()
|
||||||
.withPreview(BLACK_CAT)
|
|
||||||
.asIterator(getApiRoute() + "/comments",
|
.asIterator(getApiRoute() + "/comments",
|
||||||
GHPullRequestReviewComment[].class, pageSize)) {
|
GHPullRequestReviewComment[].class, pageSize)) {
|
||||||
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
||||||
@@ -145,5 +145,4 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds up a creation of new {@link GHPullRequestReview}.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHPullRequest#createReview()
|
||||||
|
*/
|
||||||
|
public class GHPullRequestReviewBuilder {
|
||||||
|
private final GHPullRequest pr;
|
||||||
|
private final Requester builder;
|
||||||
|
private final List<DraftReviewComment> comments = new ArrayList<DraftReviewComment>();
|
||||||
|
|
||||||
|
/*package*/ GHPullRequestReviewBuilder(GHPullRequest pr) {
|
||||||
|
this.pr = pr;
|
||||||
|
this.builder = new Requester(pr.root);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event,
|
||||||
|
// List<GHPullRequestReviewComment> comments) throws IOException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The SHA of the commit that needs a review. Not using the latest commit SHA may render your review comment outdated if a subsequent commit modifies the line you specify as the position. Defaults to the most recent commit in the pull request when you do not specify a value.
|
||||||
|
*/
|
||||||
|
public GHPullRequestReviewBuilder commitId(String commitId) {
|
||||||
|
builder.with("commit_id",commitId);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required when using REQUEST_CHANGES or COMMENT for the event parameter. The body text of the pull request review.
|
||||||
|
*/
|
||||||
|
public GHPullRequestReviewBuilder body(String body) {
|
||||||
|
builder.with("body",body);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(String, GHPullRequestReviewEvent) submit the pull request review} when you are ready.
|
||||||
|
*/
|
||||||
|
public GHPullRequestReviewBuilder event(GHPullRequestReviewEvent event) {
|
||||||
|
builder.with("event",event.action());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param body The relative path to the file that necessitates a review comment.
|
||||||
|
* @param path The position in the diff where you want to add a review comment. Note this value is not the same as the line number in the file. For help finding the position value, read the note below.
|
||||||
|
* @param position Text of the review comment.
|
||||||
|
*/
|
||||||
|
public GHPullRequestReviewBuilder comment(String body, String path, int position) {
|
||||||
|
comments.add(new DraftReviewComment(body,path,position));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestReview create() throws IOException {
|
||||||
|
return builder.method("POST")._with("comments",comments)
|
||||||
|
.to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class)
|
||||||
|
.wrapUp(pr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DraftReviewComment {
|
||||||
|
private String body;
|
||||||
|
private String path;
|
||||||
|
private int position;
|
||||||
|
|
||||||
|
DraftReviewComment(String body, String path, int position) {
|
||||||
|
this.body = body;
|
||||||
|
this.path = path;
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.*;
|
import static org.kohsuke.github.Previews.*;
|
||||||
|
|
||||||
@@ -41,9 +42,15 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
private String body;
|
private String body;
|
||||||
private GHUser user;
|
private GHUser user;
|
||||||
private String path;
|
private String path;
|
||||||
private int position;
|
private int position = -1;
|
||||||
private int originalPosition;
|
private int original_position = -1;
|
||||||
|
private long in_reply_to_id = -1L;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* You should be using {@link GHPullRequestReviewBuilder#comment(String, String, int)}
|
||||||
|
*/
|
||||||
public static GHPullRequestReviewComment draft(String body, String path, int position) {
|
public static GHPullRequestReviewComment draft(String body, String path, int position) {
|
||||||
GHPullRequestReviewComment result = new GHPullRequestReviewComment();
|
GHPullRequestReviewComment result = new GHPullRequestReviewComment();
|
||||||
result.body = body;
|
result.body = body;
|
||||||
@@ -82,12 +89,18 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckForNull
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOriginalPosition() {
|
public int getOriginalPosition() {
|
||||||
return originalPosition;
|
return original_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CheckForNull
|
||||||
|
public long getInReplyToId() {
|
||||||
|
return in_reply_to_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,6 +127,17 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new comment that replies to this comment.
|
||||||
|
*/
|
||||||
|
public GHPullRequestReviewComment reply(String body) throws IOException {
|
||||||
|
return new Requester(owner.root).method("POST")
|
||||||
|
.with("body", body)
|
||||||
|
.with("in_reply_to", getId())
|
||||||
|
.to(getApiRoute() + "/comments", GHPullRequestReviewComment.class)
|
||||||
|
.wrapUp(owner);
|
||||||
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview @Deprecated
|
||||||
public GHReaction createReaction(ReactionContent content) throws IOException {
|
public GHReaction createReaction(ReactionContent content) throws IOException {
|
||||||
return new Requester(owner.root)
|
return new Requester(owner.root)
|
||||||
@@ -126,7 +150,7 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
public PagedIterable<GHReaction> listReactions() {
|
public PagedIterable<GHReaction> listReactions() {
|
||||||
return new PagedIterable<GHReaction>() {
|
return new PagedIterable<GHReaction>() {
|
||||||
public PagedIterator<GHReaction> _iterator(int pageSize) {
|
public PagedIterator<GHReaction> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHReaction>(owner.root.retrieve().withPreview(SQUIRREL_GIRL).asIterator(getApiRoute()+"/reactions", GHReaction[].class, pageSize)) {
|
return new PagedIterator<GHReaction>(owner.root.retrieve().withPreview(SQUIRREL_GIRL).asIterator(getApiRoute() + "/reactions", GHReaction[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHReaction[] page) {
|
protected void wrapUp(GHReaction[] page) {
|
||||||
for (GHReaction c : page)
|
for (GHReaction c : page)
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Eric Maupin
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action to perform on {@link GHPullRequestReview}.
|
||||||
|
*/
|
||||||
|
public enum GHPullRequestReviewEvent {
|
||||||
|
PENDING,
|
||||||
|
APPROVE,
|
||||||
|
REQUEST_CHANGES,
|
||||||
|
COMMENT;
|
||||||
|
|
||||||
|
/*package*/ String action() {
|
||||||
|
return this==PENDING ? null : name();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a {@link GHPullRequestReview} is submitted with this event, it should transition to this state.
|
||||||
|
*/
|
||||||
|
/*package*/ GHPullRequestReviewState toState() {
|
||||||
|
switch (this) {
|
||||||
|
case PENDING: return GHPullRequestReviewState.PENDING;
|
||||||
|
case APPROVE: return GHPullRequestReviewState.APPROVED;
|
||||||
|
case REQUEST_CHANGES: return GHPullRequestReviewState.CHANGES_REQUESTED;
|
||||||
|
case COMMENT: return GHPullRequestReviewState.COMMENTED;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,39 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current state of {@link GHPullRequestReview}
|
||||||
|
*/
|
||||||
public enum GHPullRequestReviewState {
|
public enum GHPullRequestReviewState {
|
||||||
PENDING(null),
|
PENDING,
|
||||||
APPROVED("APPROVE"),
|
APPROVED,
|
||||||
REQUEST_CHANGES("REQUEST_CHANGES"),
|
CHANGES_REQUESTED,
|
||||||
COMMENTED("COMMENT"),
|
/**
|
||||||
DISMISSED(null);
|
* @deprecated
|
||||||
|
* This was the thing when this API was in preview, but it changed when it became public.
|
||||||
|
* Use {@link #CHANGES_REQUESTED}. Left here for compatibility.
|
||||||
|
*/
|
||||||
|
REQUEST_CHANGES,
|
||||||
|
COMMENTED,
|
||||||
|
DISMISSED;
|
||||||
|
|
||||||
private final String _action;
|
/**
|
||||||
|
* @deprecated
|
||||||
GHPullRequestReviewState(String action) {
|
* This was an internal method accidentally exposed.
|
||||||
_action = action;
|
* Left here for compatibility.
|
||||||
|
*/
|
||||||
|
public String action() {
|
||||||
|
GHPullRequestReviewEvent e = toEvent();
|
||||||
|
return e==null ? null : e.action();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String action() {
|
/*package*/ GHPullRequestReviewEvent toEvent() {
|
||||||
return _action;
|
switch (this) {
|
||||||
|
case PENDING: return GHPullRequestReviewEvent.PENDING;
|
||||||
|
case APPROVED: return GHPullRequestReviewEvent.APPROVE;
|
||||||
|
case CHANGES_REQUESTED: return GHPullRequestReviewEvent.REQUEST_CHANGES;
|
||||||
|
case REQUEST_CHANGES: return GHPullRequestReviewEvent.REQUEST_CHANGES;
|
||||||
|
case COMMENTED: return GHPullRequestReviewEvent.COMMENT;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -125,12 +126,21 @@ public class GHRelease extends GHObject {
|
|||||||
* handling of the HTTP requests to github's API.
|
* handling of the HTTP requests to github's API.
|
||||||
*/
|
*/
|
||||||
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
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);
|
Requester builder = new Requester(owner.root);
|
||||||
|
|
||||||
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
|
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)
|
return builder.contentType(contentType)
|
||||||
.with(new FileInputStream(file))
|
.with(stream)
|
||||||
.to(url, GHAsset.class).wrap(this);
|
.to(url, GHAsset.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -35,7 +34,6 @@ 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.net.URL;
|
import java.net.URL;
|
||||||
import java.util.AbstractSet;
|
import java.util.AbstractSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -173,6 +171,14 @@ public class GHRepository extends GHObject {
|
|||||||
* Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git"
|
* Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git"
|
||||||
* This URL is read-only.
|
* This URL is read-only.
|
||||||
*/
|
*/
|
||||||
|
public String getHttpTransportUrl() {
|
||||||
|
return clone_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Typo of {@link #getHttpTransportUrl()}
|
||||||
|
*/
|
||||||
public String gitHttpTransportUrl() {
|
public String gitHttpTransportUrl() {
|
||||||
return clone_url;
|
return clone_url;
|
||||||
}
|
}
|
||||||
@@ -302,6 +308,22 @@ public class GHRepository extends GHObject {
|
|||||||
public List<GHRelease> getReleases() throws IOException {
|
public List<GHRelease> getReleases() throws IOException {
|
||||||
return listReleases().asList();
|
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 {
|
public GHRelease getLatestRelease() throws IOException {
|
||||||
try {
|
try {
|
||||||
@@ -807,7 +829,9 @@ public class GHRepository extends GHObject {
|
|||||||
public PagedIterator<GHRef> _iterator(int pageSize) {
|
public PagedIterator<GHRef> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
|
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
|
||||||
protected void wrapUp(GHRef[] page) {
|
protected void wrapUp(GHRef[] page) {
|
||||||
// no-op
|
for(GHRef p: page) {
|
||||||
|
p.wrap(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1129,6 +1153,22 @@ public class GHRepository extends GHObject {
|
|||||||
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
|
.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.)
|
* Lists all the subscribers (aka watchers.)
|
||||||
*
|
*
|
||||||
@@ -1298,7 +1338,7 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public Map<String,GHBranch> getBranches() throws IOException {
|
public Map<String,GHBranch> getBranches() throws IOException {
|
||||||
Map<String,GHBranch> r = new TreeMap<String,GHBranch>();
|
Map<String,GHBranch> r = new TreeMap<String,GHBranch>();
|
||||||
for (GHBranch p : root.retrieve().withPreview(LOKI).to(getApiTailUrl("branches"), GHBranch[].class)) {
|
for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) {
|
||||||
p.wrap(this);
|
p.wrap(this);
|
||||||
r.put(p.getName(),p);
|
r.put(p.getName(),p);
|
||||||
}
|
}
|
||||||
@@ -1306,7 +1346,7 @@ public class GHRepository extends GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHBranch getBranch(String name) throws IOException {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1386,41 +1426,43 @@ public class GHRepository extends GHObject {
|
|||||||
return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this);
|
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 {
|
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 {
|
public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException {
|
||||||
final byte[] payload;
|
return createContent().content(content).message(commitMessage).path(path).branch(branch).commit();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@link #createContent()}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException {
|
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 {
|
public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch) throws IOException {
|
||||||
Requester requester = new Requester(root)
|
return createContent().content(contentBytes).message(commitMessage).path(path).branch(branch).commit();
|
||||||
.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestone createMilestone(String title, String description) throws IOException {
|
public GHMilestone createMilestone(String title, String description) throws IOException {
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ public class GHRepositorySearchBuilder extends GHSearchBuilder<GHRepository> {
|
|||||||
return q("stars:"+v);
|
return q("stars:"+v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHRepositorySearchBuilder topic(String v) {
|
||||||
|
return q("topic:"+v);
|
||||||
|
}
|
||||||
|
|
||||||
public GHRepositorySearchBuilder order(GHDirection v) {
|
public GHRepositorySearchBuilder order(GHDirection v) {
|
||||||
req.with("order",v);
|
req.with("order",v);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -18,6 +18,18 @@ public class GHTeam {
|
|||||||
|
|
||||||
protected /*final*/ GHOrganization org;
|
protected /*final*/ GHOrganization org;
|
||||||
|
|
||||||
|
/** Member's role in a team */
|
||||||
|
public enum Role {
|
||||||
|
/**
|
||||||
|
* A normal member of the team
|
||||||
|
*/
|
||||||
|
MEMBER,
|
||||||
|
/**
|
||||||
|
* Able to add/remove other team members, promote other team members to team maintainer, and edit the team's name and description.
|
||||||
|
*/
|
||||||
|
MAINTAINER
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ GHTeam wrapUp(GHOrganization owner) {
|
/*package*/ GHTeam wrapUp(GHOrganization owner) {
|
||||||
this.org = owner;
|
this.org = owner;
|
||||||
return this;
|
return this;
|
||||||
@@ -116,6 +128,22 @@ public class GHTeam {
|
|||||||
org.root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null);
|
org.root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a member to the team
|
||||||
|
*
|
||||||
|
* The user will be invited to the organization if required.
|
||||||
|
*
|
||||||
|
* @param user github user
|
||||||
|
* @param role role for the new member
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void add(GHUser user, Role role) throws IOException {
|
||||||
|
org.root.retrieve().method("PUT")
|
||||||
|
.with("role", role.name())
|
||||||
|
.to(api("/memberships/" + user.getLogin()), null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a member to the team.
|
* Removes a member to the team.
|
||||||
*/
|
*/
|
||||||
@@ -129,7 +157,7 @@ public class GHTeam {
|
|||||||
|
|
||||||
public void add(GHRepository r, GHOrganization.Permission permission) throws IOException {
|
public void add(GHRepository r, GHOrganization.Permission permission) throws IOException {
|
||||||
org.root.retrieve().method("PUT")
|
org.root.retrieve().method("PUT")
|
||||||
.with("permission",permission)
|
.with("permission", permission)
|
||||||
.to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
|
.to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +173,7 @@ public class GHTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String api(String tail) {
|
private String api(String tail) {
|
||||||
return "/teams/"+id+tail;
|
return "/teams/" + id + tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHOrganization getOrganization() {
|
public GHOrganization getOrganization() {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std;
|
import com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std;
|
||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
@@ -48,7 +49,6 @@ 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.HashSet;
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -424,6 +424,9 @@ public class GitHub {
|
|||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets {@link GHOrganization} specified by name.
|
||||||
|
*/
|
||||||
public GHOrganization getOrganization(String name) throws IOException {
|
public GHOrganization getOrganization(String name) throws IOException {
|
||||||
GHOrganization o = orgs.get(name);
|
GHOrganization o = orgs.get(name);
|
||||||
if (o==null) {
|
if (o==null) {
|
||||||
@@ -433,6 +436,35 @@ public class GitHub {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of all organizations.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHOrganization> listOrganizations() {
|
||||||
|
return listOrganizations(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of all organizations starting after the organization identifier specified by 'since'.
|
||||||
|
*
|
||||||
|
* @see <a href="https://developer.github.com/v3/orgs/#parameters">List All Orgs - Parameters</a>
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHOrganization> listOrganizations(final String since) {
|
||||||
|
return new PagedIterable<GHOrganization>() {
|
||||||
|
@Override
|
||||||
|
public PagedIterator<GHOrganization> _iterator(int pageSize) {
|
||||||
|
System.out.println("page size: " + pageSize);
|
||||||
|
return new PagedIterator<GHOrganization>(retrieve().with("since",since)
|
||||||
|
.asIterator("/organizations", GHOrganization[].class, pageSize)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHOrganization[] page) {
|
||||||
|
for (GHOrganization c : page)
|
||||||
|
c.wrapUp(GitHub.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
|
* Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
|
||||||
*
|
*
|
||||||
@@ -498,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.
|
* This method returns a shallowly populated organizations.
|
||||||
@@ -878,6 +919,7 @@ public class GitHub {
|
|||||||
static {
|
static {
|
||||||
MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY));
|
MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY));
|
||||||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
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";
|
/* package */ static final String GITHUB_URL = "https://api.github.com";
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ package org.kohsuke.github;
|
|||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
/*package*/ class Previews {
|
/*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 DRAX = "application/vnd.github.drax-preview+json";
|
||||||
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
|
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
|
||||||
static final String CLOAK = "application/vnd.github.cloak-preview";
|
static final String CLOAK = "application/vnd.github.cloak-preview";
|
||||||
static final String BLACK_CAT = "application/vnd.github.black-cat-preview+json";
|
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 {
|
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(parseWaitTime(uc));
|
Thread.sleep(parseWaitTime(uc));
|
||||||
} catch (InterruptedException _) {
|
} catch (InterruptedException x) {
|
||||||
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
|
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ package org.kohsuke.github;
|
|||||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import org.apache.commons.io.IOUtils;
|
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.CheckForNull;
|
||||||
import javax.annotation.WillClose;
|
import javax.annotation.WillClose;
|
||||||
@@ -54,16 +54,17 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.logging.Level.*;
|
import static java.util.logging.Level.FINE;
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
import static java.util.logging.Level.FINEST;
|
||||||
import static org.kohsuke.github.GitHub.*;
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||||
|
import static org.kohsuke.github.GitHub.MAPPER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder pattern for making HTTP call and parsing its output.
|
* A builder pattern for making HTTP call and parsing its output.
|
||||||
@@ -134,6 +135,10 @@ class Requester {
|
|||||||
return _with(key, value);
|
return _with(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Requester with(String key, long value) {
|
||||||
|
return _with(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
public Requester with(String key, Integer value) {
|
public Requester with(String key, Integer value) {
|
||||||
if (value!=null)
|
if (value!=null)
|
||||||
_with(key, value);
|
_with(key, value);
|
||||||
@@ -164,6 +169,14 @@ class Requester {
|
|||||||
return _with(key, value);
|
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) {
|
public Requester with(String key, Map<String, String> value) {
|
||||||
return _with(key, value);
|
return _with(key, value);
|
||||||
}
|
}
|
||||||
@@ -452,7 +465,7 @@ class Requester {
|
|||||||
try {
|
try {
|
||||||
return new PagingIterator<T>(type, tailApiUrl, root.getApiURL(s.toString()));
|
return new PagingIterator<T>(type, tailApiUrl, root.getApiURL(s.toString()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error(e);
|
throw new GHException("Unable to build github Api URL",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +526,7 @@ class Requester {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error(e);
|
throw new GHException("Failed to retrieve "+url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,25 @@
|
|||||||
package org.kohsuke.github.extras;
|
package org.kohsuke.github.extras;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.ConnectionSpec;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import com.squareup.okhttp.OkHttpClient;
|
||||||
import com.squareup.okhttp.OkUrlFactory;
|
import com.squareup.okhttp.OkUrlFactory;
|
||||||
|
|
||||||
import org.kohsuke.github.HttpConnector;
|
import org.kohsuke.github.HttpConnector;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
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}.
|
* {@link HttpConnector} for {@link OkHttpClient}.
|
||||||
*
|
*
|
||||||
@@ -23,10 +35,33 @@ public class OkHttpConnector implements HttpConnector {
|
|||||||
private final OkUrlFactory urlFactory;
|
private final OkUrlFactory urlFactory;
|
||||||
|
|
||||||
public OkHttpConnector(OkUrlFactory urlFactory) {
|
public OkHttpConnector(OkUrlFactory urlFactory) {
|
||||||
|
urlFactory.client().setSslSocketFactory(TlsSocketFactory());
|
||||||
|
urlFactory.client().setConnectionSpecs(TlsConnectionSpecs());
|
||||||
this.urlFactory = urlFactory;
|
this.urlFactory = urlFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpURLConnection connect(URL url) throws IOException {
|
public HttpURLConnection connect(URL url) throws IOException {
|
||||||
return urlFactory.open(url);
|
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
|
@Test
|
||||||
public void testMembership() throws Exception {
|
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"));
|
System.out.println(members.contains("kohsuke"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
|||||||
branch = repo.getBranch(BRANCH);
|
branch = repo.getBranch(BRANCH);
|
||||||
|
|
||||||
if (branch.isProtected()) {
|
if (branch.isProtected()) {
|
||||||
|
GHBranchProtection protection = branch.getProtection();
|
||||||
|
if (protection.getRequiredSignatures()) {
|
||||||
|
protection.disableSignedCommits();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse(protection.getRequiredSignatures());
|
||||||
branch.disableProtection();
|
branch.disableProtection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +53,7 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
|||||||
.requireBranchIsUpToDate()
|
.requireBranchIsUpToDate()
|
||||||
.requireCodeOwnReviews()
|
.requireCodeOwnReviews()
|
||||||
.dismissStaleReviews()
|
.dismissStaleReviews()
|
||||||
|
.requiredReviewers(2)
|
||||||
.includeAdmins()
|
.includeAdmins()
|
||||||
.enable();
|
.enable();
|
||||||
|
|
||||||
@@ -59,6 +66,7 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
|||||||
assertNotNull(requiredReviews);
|
assertNotNull(requiredReviews);
|
||||||
assertTrue(requiredReviews.isDismissStaleReviews());
|
assertTrue(requiredReviews.isDismissStaleReviews());
|
||||||
assertTrue(requiredReviews.isRequireCodeOwnerReviews());
|
assertTrue(requiredReviews.isRequireCodeOwnerReviews());
|
||||||
|
assertEquals(2, requiredReviews.getRequiredReviewers());
|
||||||
|
|
||||||
EnforceAdmins enforceAdmins = protection.getEnforceAdmins();
|
EnforceAdmins enforceAdmins = protection.getEnforceAdmins();
|
||||||
assertNotNull(enforceAdmins);
|
assertNotNull(enforceAdmins);
|
||||||
@@ -79,4 +87,17 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase {
|
|||||||
|
|
||||||
assertNotNull(protection.getRequiredReviews());
|
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
|
@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();
|
||||||
|
|
||||||
assertNotNull(created.getCommit());
|
assertNotNull(created.getCommit());
|
||||||
|
|||||||
@@ -120,9 +120,19 @@ public class GHEventPayloadTest {
|
|||||||
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO implement support classes and write test
|
@Test
|
||||||
// @Test
|
public void issues() throws Exception {
|
||||||
// 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
|
// TODO implement support classes and write test
|
||||||
// @Test
|
// @Test
|
||||||
@@ -187,13 +197,61 @@ public class GHEventPayloadTest {
|
|||||||
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO implement support classes and write test
|
@Test
|
||||||
// @Test
|
public void pull_request_review() throws Exception {
|
||||||
// public void pull_request_review() throws Exception {}
|
GHEventPayload.PullRequestReview event =
|
||||||
|
GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.PullRequestReview.class);
|
||||||
|
assertThat(event.getAction(), is("submitted"));
|
||||||
|
|
||||||
|
assertThat(event.getReview().getId(), is(2626884L));
|
||||||
|
assertThat(event.getReview().getBody(), is("Looks great!\n"));
|
||||||
|
assertThat(event.getReview().getState(), is(GHPullRequestReviewState.APPROVED));
|
||||||
|
|
||||||
|
assertThat(event.getPullRequest().getNumber(), is(8));
|
||||||
|
assertThat(event.getPullRequest().getTitle(), is("Add a README description"));
|
||||||
|
assertThat(event.getPullRequest().getBody(), is("Just a few more details"));
|
||||||
|
assertThat(event.getPullRequest().getUser().getLogin(), is("skalnik"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getUser().getLogin(), is("skalnik"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getRef(), is("patch-2"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getLabel(), is("skalnik:patch-2"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getSha(), is("b7a1f9c27caa4e03c14a88feb56e2d4f7500aa63"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getUser().getLogin(), is("baxterthehacker"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getRef(), is("master"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getLabel(), is("baxterthehacker:master"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getSha(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b"));
|
||||||
|
|
||||||
|
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
|
||||||
// @Test
|
public void pull_request_review_comment() throws Exception {
|
||||||
// public void pull_request_review_comment() throws Exception {}
|
GHEventPayload.PullRequestReviewComment event =
|
||||||
|
GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.PullRequestReviewComment.class);
|
||||||
|
assertThat(event.getAction(), is("created"));
|
||||||
|
|
||||||
|
assertThat(event.getComment().getBody(), is("Maybe you should use more emojji on this line."));
|
||||||
|
|
||||||
|
assertThat(event.getPullRequest().getNumber(), is(1));
|
||||||
|
assertThat(event.getPullRequest().getTitle(), is("Update the README with new information"));
|
||||||
|
assertThat(event.getPullRequest().getBody(), is("This is a pretty simple change that we need to pull into master."));
|
||||||
|
assertThat(event.getPullRequest().getUser().getLogin(), is("baxterthehacker"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getUser().getLogin(), is("baxterthehacker"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getRef(), is("changes"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getLabel(), is("baxterthehacker:changes"));
|
||||||
|
assertThat(event.getPullRequest().getHead().getSha(), is("0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getUser().getLogin(), is("baxterthehacker"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getRef(), is("master"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getLabel(), is("baxterthehacker:master"));
|
||||||
|
assertThat(event.getPullRequest().getBase().getSha(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b"));
|
||||||
|
|
||||||
|
assertThat(event.getRepository().getName(), is("public-repo"));
|
||||||
|
assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker"));
|
||||||
|
|
||||||
|
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void push() throws Exception {
|
public void push() throws Exception {
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -155,4 +158,16 @@ public class GitHubTest {
|
|||||||
System.out.println(u.getName());
|
System.out.println(u.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getOrgs() throws IOException {
|
||||||
|
GitHub hub = GitHub.connect();
|
||||||
|
int iterations = 10;
|
||||||
|
Set<Long> orgIds = new HashSet<Long>();
|
||||||
|
for (GHOrganization org : Iterables.limit(hub.listOrganizations().withPageSize(2), iterations)) {
|
||||||
|
orgIds.add(org.getId());
|
||||||
|
System.out.println(org.getName());
|
||||||
|
}
|
||||||
|
assertThat(orgIds.size(), equalTo(iterations));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
@@ -33,9 +32,10 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
|||||||
public void testPullRequestReviews() throws Exception {
|
public void testPullRequestReviews() throws Exception {
|
||||||
String name = rnd.next();
|
String name = rnd.next();
|
||||||
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
|
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
|
||||||
GHPullRequestReview draftReview = p.createReview("Some draft review", null,
|
GHPullRequestReview draftReview = p.createReview()
|
||||||
GHPullRequestReviewComment.draft("Some niggle", "changelog.html", 1)
|
.body("Some draft review")
|
||||||
);
|
.comment("Some niggle", "changelog.html", 1)
|
||||||
|
.create();
|
||||||
assertThat(draftReview.getState(), is(GHPullRequestReviewState.PENDING));
|
assertThat(draftReview.getState(), is(GHPullRequestReviewState.PENDING));
|
||||||
assertThat(draftReview.getBody(), is("Some draft review"));
|
assertThat(draftReview.getBody(), is("Some draft review"));
|
||||||
assertThat(draftReview.getCommitId(), notNullValue());
|
assertThat(draftReview.getCommitId(), notNullValue());
|
||||||
@@ -45,15 +45,16 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
|||||||
assertThat(review.getState(), is(GHPullRequestReviewState.PENDING));
|
assertThat(review.getState(), is(GHPullRequestReviewState.PENDING));
|
||||||
assertThat(review.getBody(), is("Some draft review"));
|
assertThat(review.getBody(), is("Some draft review"));
|
||||||
assertThat(review.getCommitId(), notNullValue());
|
assertThat(review.getCommitId(), notNullValue());
|
||||||
review.submit("Some review comment", GHPullRequestReviewState.COMMENTED);
|
draftReview.submit("Some review comment", GHPullRequestReviewEvent.COMMENT);
|
||||||
List<GHPullRequestReviewComment> comments = review.listReviewComments().asList();
|
List<GHPullRequestReviewComment> comments = review.listReviewComments().asList();
|
||||||
assertEquals(1, comments.size());
|
assertEquals(1, comments.size());
|
||||||
GHPullRequestReviewComment comment = comments.get(0);
|
GHPullRequestReviewComment comment = comments.get(0);
|
||||||
assertEquals("Some niggle", comment.getBody());
|
assertEquals("Some niggle", comment.getBody());
|
||||||
review = p.createReview("Some new review", null,
|
draftReview = p.createReview()
|
||||||
GHPullRequestReviewComment.draft("Some niggle", "changelog.html", 1)
|
.body("Some new review")
|
||||||
);
|
.comment("Some niggle", "changelog.html", 1)
|
||||||
review.delete();
|
.create();
|
||||||
|
draftReview.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -104,6 +105,7 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
|||||||
String name = rnd.next();
|
String name = rnd.next();
|
||||||
GHRef masterRef = getRepository().getRef("heads/master");
|
GHRef masterRef = getRepository().getRef("heads/master");
|
||||||
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
|
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
|
||||||
|
|
||||||
getRepository().createContent(name, name, name, name);
|
getRepository().createContent(name, name, name, name);
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
|
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
|
||||||
@@ -111,6 +113,27 @@ public class PullRequestTest extends AbstractGitHubApiTestBase {
|
|||||||
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
|
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
|
||||||
branchRef.delete();
|
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
|
@Test
|
||||||
// Requires push access to the test repo to pass
|
// 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 {
|
private GHRepository getRepository() throws IOException {
|
||||||
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"user": {
|
"user": {
|
||||||
"login": "baxterthehacker",
|
"login": "baxterthehacker",
|
||||||
"id": 6752317,
|
"id": 6752317,
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
|
"avatar_url": "https://avatars3.githubusercontent.com/u/6752317?v=4",
|
||||||
"gravatar_id": "",
|
"gravatar_id": "",
|
||||||
"url": "https://api.github.com/users/baxterthehacker",
|
"url": "https://api.github.com/users/baxterthehacker",
|
||||||
"html_url": "https://github.com/baxterthehacker",
|
"html_url": "https://github.com/baxterthehacker",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"type": "User",
|
"type": "User",
|
||||||
"site_admin": false
|
"site_admin": false
|
||||||
},
|
},
|
||||||
"body": "Looks great!",
|
"body": "Looks great!\n",
|
||||||
"submitted_at": "2016-10-03T23:39:09Z",
|
"state": "APPROVED",
|
||||||
"state": "approved",
|
|
||||||
"html_url": "https://github.com/baxterthehacker/public-repo/pull/8#pullrequestreview-2626884",
|
"html_url": "https://github.com/baxterthehacker/public-repo/pull/8#pullrequestreview-2626884",
|
||||||
"pull_request_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/8",
|
"pull_request_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/8",
|
||||||
|
"author_association": "OWNER",
|
||||||
"_links": {
|
"_links": {
|
||||||
"html": {
|
"html": {
|
||||||
"href": "https://github.com/baxterthehacker/public-repo/pull/8#pullrequestreview-2626884"
|
"href": "https://github.com/baxterthehacker/public-repo/pull/8#pullrequestreview-2626884"
|
||||||
@@ -33,7 +33,9 @@
|
|||||||
"pull_request": {
|
"pull_request": {
|
||||||
"href": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/8"
|
"href": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/8"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"submitted_at": "2016-10-03T23:39:09Z",
|
||||||
|
"commit_id": "b7a1f9c27caa4e03c14a88feb56e2d4f7500aa63"
|
||||||
},
|
},
|
||||||
"pull_request": {
|
"pull_request": {
|
||||||
"url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/8",
|
"url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/8",
|
||||||
|
|||||||
Reference in New Issue
Block a user