Skip to content

Commit

Permalink
Merge pull request #615 from alexanderrtaylor/BranchMissing
Browse files Browse the repository at this point in the history
Branch missing
  • Loading branch information
bitwiseman committed Nov 19, 2019
2 parents da11702 + cbd06ee commit d2ce7c1
Show file tree
Hide file tree
Showing 33 changed files with 863 additions and 133 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/kohsuke/github/DeleteToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
/**
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", justification = "Being constructed by JSON deserialization")
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
justification = "Being constructed by JSON deserialization")
class DeleteToken {
public String delete_token;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
@Preview
@Deprecated
public GHAppInstallationToken create() throws IOException {
return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class)
return builder.method("POST")
.withPreview(MACHINE_MAN)
.to(apiUrlTail, GHAppInstallationToken.class)
.wrapUp(root);
}

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.kohsuke.github;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonMappingException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import java.util.Objects;

import static org.kohsuke.github.Previews.*;

Expand All @@ -28,6 +30,12 @@ public class GHBranch {
private boolean protection;
private String protection_url;

@JsonCreator
GHBranch(@JsonProperty(value = "name", required = true) String name) throws Exception {
Objects.requireNonNull(name);
this.name = name;
}

/**
* The type Commit.
*/
Expand Down
50 changes: 44 additions & 6 deletions src/main/java/org/kohsuke/github/GHEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,50 @@
* @see <a href="https://developer.github.com/v3/activity/events/types/">Event type reference</a>
*/
public enum GHEvent {
COMMIT_COMMENT, CREATE, DELETE, DEPLOYMENT, DEPLOYMENT_STATUS, DOWNLOAD, FOLLOW, FORK, FORK_APPLY, GIST, GOLLUM, INSTALLATION, INSTALLATION_REPOSITORIES, INTEGRATION_INSTALLATION_REPOSITORIES, CHECK_SUITE, ISSUE_COMMENT, ISSUES, LABEL, MARKETPLACE_PURCHASE, MEMBER, MEMBERSHIP, MILESTONE, ORGANIZATION, ORG_BLOCK, PAGE_BUILD, PROJECT_CARD, PROJECT_COLUMN, PROJECT, PUBLIC, PULL_REQUEST, PULL_REQUEST_REVIEW, PULL_REQUEST_REVIEW_COMMENT, PUSH, RELEASE, REPOSITORY, // only
// valid
// for
// org
// hooks
STATUS, TEAM, TEAM_ADD, WATCH, PING,
COMMIT_COMMENT,
CREATE,
DELETE,
DEPLOYMENT,
DEPLOYMENT_STATUS,
DOWNLOAD,
FOLLOW,
FORK,
FORK_APPLY,
GIST,
GOLLUM,
INSTALLATION,
INSTALLATION_REPOSITORIES,
INTEGRATION_INSTALLATION_REPOSITORIES,
CHECK_SUITE,
ISSUE_COMMENT,
ISSUES,
LABEL,
MARKETPLACE_PURCHASE,
MEMBER,
MEMBERSHIP,
MILESTONE,
ORGANIZATION,
ORG_BLOCK,
PAGE_BUILD,
PROJECT_CARD,
PROJECT_COLUMN,
PROJECT,
PUBLIC,
PULL_REQUEST,
PULL_REQUEST_REVIEW,
PULL_REQUEST_REVIEW_COMMENT,
PUSH,
RELEASE,
REPOSITORY, // only
// valid
// for
// org
// hooks
STATUS,
TEAM,
TEAM_ADD,
WATCH,
PING,
/**
* Special event type that means "every possible event"
*/
Expand Down
44 changes: 28 additions & 16 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Collection<GHLabel> getLabels() throws IOException {
if (labels == null) {
return Collections.emptyList();
}
return Collections.<GHLabel> unmodifiableList(labels);
return Collections.<GHLabel>unmodifiableList(labels);
}

/**
Expand Down Expand Up @@ -231,8 +231,8 @@ public void unlock() throws IOException {
*/
@WithBridgeMethods(void.class)
public GHIssueComment comment(String message) throws IOException {
GHIssueComment r = new Requester(root).with("body", message).to(getIssuesApiRoute() + "/comments",
GHIssueComment.class);
GHIssueComment r = new Requester(root).with("body", message)
.to(getIssuesApiRoute() + "/comments", GHIssueComment.class);
return r.wrapUp(this);
}

Expand Down Expand Up @@ -443,22 +443,27 @@ public List<GHIssueComment> getComments() throws IOException {
* the io exception
*/
public PagedIterable<GHIssueComment> listComments() throws IOException {
return root.retrieve().asPagedIterable(getIssuesApiRoute() + "/comments", GHIssueComment[].class,
item -> item.wrapUp(GHIssue.this));
return root.retrieve()
.asPagedIterable(getIssuesApiRoute() + "/comments",
GHIssueComment[].class,
item -> item.wrapUp(GHIssue.this));
}

@Preview
@Deprecated
public GHReaction createReaction(ReactionContent content) throws IOException {
return new Requester(owner.root).withPreview(SQUIRREL_GIRL).with("content", content.getContent())
.to(getApiRoute() + "/reactions", GHReaction.class).wrap(root);
return new Requester(owner.root).withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
.to(getApiRoute() + "/reactions", GHReaction.class)
.wrap(root);
}

@Preview
@Deprecated
public PagedIterable<GHReaction> listReactions() {
return owner.root.retrieve().withPreview(SQUIRREL_GIRL).asPagedIterable(getApiRoute() + "/reactions",
GHReaction[].class, item -> item.wrap(owner.root));
return owner.root.retrieve()
.withPreview(SQUIRREL_GIRL)
.asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root));
}

/**
Expand All @@ -482,8 +487,10 @@ public void addAssignees(GHUser... assignees) throws IOException {
* the io exception
*/
public void addAssignees(Collection<GHUser> assignees) throws IOException {
root.retrieve().method("POST").with(ASSIGNEES, getLogins(assignees)).to(getIssuesApiRoute() + "/assignees",
this);
root.retrieve()
.method("POST")
.with(ASSIGNEES, getLogins(assignees))
.to(getIssuesApiRoute() + "/assignees", this);
}

/**
Expand Down Expand Up @@ -531,7 +538,10 @@ public void removeAssignees(GHUser... assignees) throws IOException {
* the io exception
*/
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
root.retrieve().method("DELETE").with(ASSIGNEES, getLogins(assignees)).inBody()
root.retrieve()
.method("DELETE")
.with(ASSIGNEES, getLogins(assignees))
.inBody()
.to(getIssuesApiRoute() + "/assignees", this);
}

Expand Down Expand Up @@ -645,8 +655,8 @@ public GHMilestone getMilestone() {
/**
* The type PullRequest.
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD",
"UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD" },
justification = "JSON API")
public static class PullRequest {
private String diff_url, patch_url, html_url;

Expand Down Expand Up @@ -694,7 +704,9 @@ protected static List<String> getLogins(Collection<GHUser> users) {
* the io exception
*/
public PagedIterable<GHIssueEvent> listEvents() throws IOException {
return root.retrieve().asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)),
GHIssueEvent[].class, item -> item.wrapUp(GHIssue.this));
return root.retrieve()
.asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)),
GHIssueEvent[].class,
item -> item.wrapUp(GHIssue.this));
}
}
44 changes: 30 additions & 14 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ public void refresh() throws IOException {
* @return the paged iterable
*/
public PagedIterable<GHPullRequestFileDetail> listFiles() {
return root.retrieve().asPagedIterable(String.format("%s/files", getApiRoute()),
GHPullRequestFileDetail[].class, null);
return root.retrieve()
.asPagedIterable(String.format("%s/files", getApiRoute()), GHPullRequestFileDetail[].class, null);
}

/**
Expand All @@ -402,8 +402,10 @@ public PagedIterable<GHPullRequestFileDetail> listFiles() {
* @return the paged iterable
*/
public PagedIterable<GHPullRequestReview> listReviews() {
return root.retrieve().asPagedIterable(String.format("%s/reviews", getApiRoute()), GHPullRequestReview[].class,
item -> item.wrapUp(GHPullRequest.this));
return root.retrieve()
.asPagedIterable(String.format("%s/reviews", getApiRoute()),
GHPullRequestReview[].class,
item -> item.wrapUp(GHPullRequest.this));
}

/**
Expand All @@ -414,8 +416,10 @@ public PagedIterable<GHPullRequestReview> listReviews() {
* the io exception
*/
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
return root.retrieve().asPagedIterable(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment[].class,
item -> item.wrapUp(GHPullRequest.this));
return root.retrieve()
.asPagedIterable(getApiRoute() + COMMENTS_ACTION,
GHPullRequestReviewComment[].class,
item -> item.wrapUp(GHPullRequest.this));
}

/**
Expand All @@ -424,8 +428,10 @@ public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOE
* @return the paged iterable
*/
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
return root.retrieve().asPagedIterable(String.format("%s/commits", getApiRoute()),
GHPullRequestCommitDetail[].class, item -> item.wrapUp(GHPullRequest.this));
return root.retrieve()
.asPagedIterable(String.format("%s/commits", getApiRoute()),
GHPullRequestCommitDetail[].class,
item -> item.wrapUp(GHPullRequest.this));
}

/**
Expand All @@ -442,7 +448,8 @@ public PagedIterable<GHPullRequestCommitDetail> listCommits() {
* the io exception
* @deprecated Use {@link #createReview()}
*/
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
public GHPullRequestReview createReview(String body,
@CheckForNull GHPullRequestReviewState event,
GHPullRequestReviewComment... comments) throws IOException {
return createReview(body, event, Arrays.asList(comments));
}
Expand All @@ -461,7 +468,8 @@ public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequest
* the io exception
* @deprecated Use {@link #createReview()}
*/
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
public GHPullRequestReview createReview(String body,
@CheckForNull GHPullRequestReviewState event,
List<GHPullRequestReviewComment> comments) throws IOException {
GHPullRequestReviewBuilder b = createReview().body(body);
for (GHPullRequestReviewComment c : comments) {
Expand Down Expand Up @@ -496,8 +504,12 @@ public GHPullRequestReviewBuilder createReview() {
*/
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position)
throws IOException {
return new Requester(root).method("POST").with("body", body).with("commit_id", sha).with("path", path)
.with("position", position).to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class)
return new Requester(root).method("POST")
.with("body", body)
.with("commit_id", sha)
.with("path", path)
.with("position", position)
.to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class)
.wrapUp(this);
}

Expand All @@ -510,7 +522,8 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S
* the io exception
*/
public void requestReviewers(List<GHUser> reviewers) throws IOException {
new Requester(root).method("POST").with("reviewers", getLogins(reviewers))
new Requester(root).method("POST")
.with("reviewers", getLogins(reviewers))
.to(getApiRoute() + REQUEST_REVIEWERS);
}

Expand Down Expand Up @@ -575,7 +588,10 @@ public void merge(String msg, String sha) throws IOException {
* the io exception
*/
public void merge(String msg, String sha, MergeMethod method) throws IOException {
new Requester(root).method("PUT").with("commit_message", msg).with("sha", sha).with("merge_method", method)
new Requester(root).method("PUT")
.with("commit_message", msg)
.with("sha", sha)
.with("merge_method", method)
.to(getApiRoute() + "/merge");
}

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,9 @@ private void findNextURL() throws MalformedURLException {

private void setupConnection(URL url) throws IOException {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "GitHub API request [" + (root.login == null ? "anonymous" : root.login) + "]: " + method
+ " " + url.toString());
LOGGER.log(FINE,
"GitHub API request [" + (root.login == null ? "anonymous" : root.login) + "]: " + method + " "
+ url.toString());
}
uc = root.getConnector().connect(url);

Expand Down Expand Up @@ -811,7 +812,7 @@ private <T> T parse(Class<T> type, T instance, int timeouts) throws IOException
throw (IOException) new IOException("Failed to deserialize " + data).initCause(e);
}
if (instance != null) {
return setResponseHeaders(MAPPER.readerForUpdating(instance).<T> readValue(data));
return setResponseHeaders(MAPPER.readerForUpdating(instance).<T>readValue(data));
}
return null;
} catch (FileNotFoundException e) {
Expand Down Expand Up @@ -872,8 +873,10 @@ void handleApiError(IOException e) throws IOException {
// likely to be a network exception (e.g. SSLHandshakeException),
// uc.getResponseCode() and any other getter on the response will cause an exception
if (LOGGER.isLoggable(FINE))
LOGGER.log(FINE, "Silently ignore exception retrieving response code for '" + uc.getURL() + "'"
+ " handling exception " + e, e);
LOGGER.log(FINE,
"Silently ignore exception retrieving response code for '" + uc.getURL() + "'"
+ " handling exception " + e,
e);
throw e;
}
InputStream es = wrapStream(uc.getErrorStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,10 @@ public static class GHMetaGettersFinalCreator implements GHMetaExample {

@JsonCreator
private GHMetaGettersFinalCreator(@Nonnull @JsonProperty("hooks") List<String> hooks,
@Nonnull @JsonProperty("git") List<String> git, @Nonnull @JsonProperty("web") List<String> web,
@Nonnull @JsonProperty("api") List<String> api, @Nonnull @JsonProperty("pages") List<String> pages,
@Nonnull @JsonProperty("git") List<String> git,
@Nonnull @JsonProperty("web") List<String> web,
@Nonnull @JsonProperty("api") List<String> api,
@Nonnull @JsonProperty("pages") List<String> pages,
@Nonnull @JsonProperty("importer") List<String> importer,
@JsonProperty("verifiable_password_authentication") boolean verifiablePasswordAuthentication) {
this.verifiablePasswordAuthentication = verifiablePasswordAuthentication;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/kohsuke/HookApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static void main(String[] args) throws Exception {
public void doIndex(StaplerRequest req) throws IOException {
String str = req.getParameter("payload");
// System.out.println(str);
GHEventPayload.PullRequest o = GitHub.connect().parseEventPayload(new StringReader(str),
GHEventPayload.PullRequest.class);
GHEventPayload.PullRequest o = GitHub.connect()
.parseEventPayload(new StringReader(str), GHEventPayload.PullRequest.class);
// System.out.println(o);
}
}
6 changes: 4 additions & 2 deletions src/test/java/org/kohsuke/github/GHAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
protected GitHubBuilder getGitHubBuilder() {
return super.getGitHubBuilder()
// ensure that only JWT will be used against the tests below
.withPassword(null, null).withJwtToken("bogus");
.withPassword(null, null)
.withJwtToken("bogus");
}

@Test
Expand Down Expand Up @@ -101,7 +102,8 @@ public void createToken() throws IOException {
permissions.put("metadata", GHPermissionType.READ);

GHAppInstallationToken installationToken = installation.createToken(permissions)
.repositoryIds(Arrays.asList((long) 111111111)).create();
.repositoryIds(Arrays.asList((long) 111111111))
.create();

assertThat(installationToken.getToken(), is("bogus"));
assertThat(installation.getPermissions(), is(permissions));
Expand Down
Loading

0 comments on commit d2ce7c1

Please sign in to comment.