From 37d7cfaaf20a33ab30bd0c0a841be06f40dbb7eb Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Thu, 14 Nov 2019 18:16:56 -0800 Subject: [PATCH 1/3] Clean up Requester interface a bit --- .../github/GHAppCreateTokenBuilder.java | 11 +- src/main/java/org/kohsuke/github/GHAsset.java | 2 +- .../org/kohsuke/github/GHCommitBuilder.java | 6 +- .../org/kohsuke/github/GHGistBuilder.java | 2 +- .../org/kohsuke/github/GHGistUpdater.java | 2 +- src/main/java/org/kohsuke/github/GHHooks.java | 4 +- src/main/java/org/kohsuke/github/GHIssue.java | 19 ++- .../java/org/kohsuke/github/GHMilestone.java | 2 +- .../java/org/kohsuke/github/GHProject.java | 2 +- .../org/kohsuke/github/GHProjectCard.java | 2 +- .../org/kohsuke/github/GHProjectColumn.java | 2 +- .../org/kohsuke/github/GHPullRequest.java | 3 +- .../github/GHPullRequestReviewBuilder.java | 2 +- .../org/kohsuke/github/GHTreeBuilder.java | 2 +- .../java/org/kohsuke/github/Requester.java | 125 +++--------------- 15 files changed, 55 insertions(+), 131 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 4570cae5b8..43291820b7 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,7 +24,7 @@ public class GHAppCreateTokenBuilder { this.root = root; this.apiUrlTail = apiUrlTail; this.builder = new Requester(root); - this.builder.withPermissions("permissions", permissions); + withPermissions(builder, permissions); } /** @@ -58,4 +59,12 @@ public GHAppInstallationToken create() throws IOException { .wrapUp(root); } + private static Requester withPermissions(Requester builder, Map value) { + Map retMap = new HashMap(); + for (Map.Entry entry : value.entrySet()) { + retMap.put(entry.getKey(), Requester.transformEnum(entry.getValue())); + } + return builder.with("permissions", retMap); + } + } diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index cd7001d25d..0003c9703d 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() { } private void edit(String key, Object value) throws IOException { - new Requester(root)._with(key, value).method("PATCH").to(getApiRoute()); + new Requester(root).with(key, value).method("PATCH").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 0b8c0fff27..71335ee02a 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -85,7 +85,7 @@ public GHCommitBuilder parent(String parent) { * @return the gh commit builder */ public GHCommitBuilder author(String name, String email, Date date) { - req._with("author", new UserInfo(name, email, date)); + req.with("author", new UserInfo(name, email, date)); return this; } @@ -101,7 +101,7 @@ public GHCommitBuilder author(String name, String email, Date date) { * @return the gh commit builder */ public GHCommitBuilder committer(String name, String email, Date date) { - req._with("committer", new UserInfo(name, email, date)); + req.with("committer", new UserInfo(name, email, date)); return this; } @@ -117,7 +117,7 @@ private String getApiTail() { * the io exception */ public GHCommit create() throws IOException { - req._with("parents", parents); + req.with("parents", parents); return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index 5b2fbb9cb3..b0d572038e 100644 --- a/src/main/java/org/kohsuke/github/GHGistBuilder.java +++ b/src/main/java/org/kohsuke/github/GHGistBuilder.java @@ -72,7 +72,7 @@ public GHGistBuilder file(String fileName, String content) { * if Gist cannot be created. */ public GHGist create() throws IOException { - req._with("files", files); + req.with("files", files); return req.to("/gists", GHGist.class).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index fd9db2a654..af5a4876a1 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -95,7 +95,7 @@ public GHGistUpdater description(String desc) { * the io exception */ public GHGist update() throws IOException { - builder._with("files", files); + builder.with("files", files); return builder.method("PATCH").to(base.getApiTailUrl(""), GHGist.class).wrap(base.owner); } } diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 2d2d9af48c..b4742dc87c 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -74,8 +74,8 @@ public GHHook createHook(String name, Map config, Collection assignees) throws IOException { - root.retrieve().method("POST").withLogins(ASSIGNEES, assignees).to(getIssuesApiRoute() + "/assignees", this); + root.retrieve().method("POST").with(ASSIGNEES, getLogins(assignees)).to(getIssuesApiRoute() + "/assignees", + this); } /** @@ -506,7 +507,7 @@ public void setAssignees(GHUser... assignees) throws IOException { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - new Requester(root).withLogins(ASSIGNEES, assignees).method("PATCH").to(getIssuesApiRoute()); + new Requester(root).with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute()); } /** @@ -530,7 +531,7 @@ public void removeAssignees(GHUser... assignees) throws IOException { * the io exception */ public void removeAssignees(Collection assignees) throws IOException { - root.retrieve().method("DELETE").withLogins(ASSIGNEES, assignees).inBody() + root.retrieve().method("DELETE").with(ASSIGNEES, getLogins(assignees)).inBody() .to(getIssuesApiRoute() + "/assignees", this); } @@ -677,6 +678,14 @@ public URL getUrl() { } } + protected static List getLogins(Collection users) { + List names = new ArrayList(users.size()); + for (GHUser a : users) { + names.add(a.getLogin()); + } + return names; + } + /** * Lists events for this issue. See https://developer.github.com/v3/issues/events/ * diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index fe127fbf29..2126869cbb 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -159,7 +159,7 @@ public void delete() throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root)._with(key, value).method("PATCH").to(getApiRoute()); + new Requester(root).with(key, value).method("PATCH").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index c822f68957..d0e222c005 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -176,7 +176,7 @@ public GHProject wrap(GitHub root) { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute()); + new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index e7cbcbf3f7..2ed518fcce 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -198,7 +198,7 @@ public void setArchived(boolean archived) throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute()); + new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index ac956a5ee8..2c62e1e9ad 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -106,7 +106,7 @@ public void setName(String name) throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute()); + new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 0ff047b9e3..831309b883 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -510,7 +510,8 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S * the io exception */ public void requestReviewers(List reviewers) throws IOException { - new Requester(root).method("POST").withLogins("reviewers", reviewers).to(getApiRoute() + REQUEST_REVIEWERS); + new Requester(root).method("POST").with("reviewers", getLogins(reviewers)) + .to(getApiRoute() + REQUEST_REVIEWERS); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index 80a54cf583..6d1bfd4f82 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -89,7 +89,7 @@ public GHPullRequestReviewBuilder comment(String body, String path, int position * the io exception */ public GHPullRequestReview create() throws IOException { - return builder.method("POST")._with("comments", comments) + return builder.method("POST").with("comments", comments) .to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class).wrapUp(pr); } diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index d6c81b9308..68ccfcb73a 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -120,7 +120,7 @@ private String getApiTail() { * the io exception */ public GHTree create() throws IOException { - req._with("tree", treeEntries); + req.with("tree", treeEntries); return req.method("POST").to(getApiTail(), GHTree.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index fcb8f44a0b..1a86bf407c 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -46,6 +46,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -60,9 +61,7 @@ import java.util.zip.GZIPInputStream; import static java.util.Arrays.asList; -import static java.util.logging.Level.FINE; -import static java.util.logging.Level.FINEST; -import static java.util.logging.Level.INFO; +import static java.util.logging.Level.*; import static org.apache.commons.lang3.StringUtils.defaultString; import static org.kohsuke.github.GitHub.MAPPER; @@ -131,22 +130,10 @@ public Requester withHeader(String name, String value) { return this; } - Requester withPreview(String name) { + public Requester withPreview(String name) { return withHeader("Accept", name); } - /** - * Makes a request with authentication credential. - * - * @return the requester - */ - @Deprecated - public Requester withCredential() { - // keeping it inline with retrieveWithAuth not to enforce the check - // root.requireCredential(); - return this; - } - /** * With requester. * @@ -157,7 +144,7 @@ public Requester withCredential() { * @return the requester */ public Requester with(String key, int value) { - return _with(key, value); + return with(key, (Object) value); } /** @@ -170,22 +157,7 @@ public Requester with(String key, int value) { * @return the requester */ public Requester with(String key, long value) { - return _with(key, value); - } - - /** - * With requester. - * - * @param key - * the key - * @param value - * the value - * @return the requester - */ - public Requester with(String key, Integer value) { - if (value != null) - _with(key, value); - return this; + return with(key, (Object) value); } /** @@ -198,20 +170,7 @@ public Requester with(String key, Integer value) { * @return the requester */ public Requester with(String key, boolean value) { - return _with(key, value); - } - - /** - * With requester. - * - * @param key - * the key - * @param value - * the value - * @return the requester - */ - public Requester with(String key, Boolean value) { - return _with(key, value); + return with(key, (Object) value); } /** @@ -225,7 +184,7 @@ public Requester with(String key, Boolean value) { */ public Requester with(String key, Enum e) { if (e == null) - return _with(key, null); + return with(key, (Object) null); return with(key, transformEnum(e)); } @@ -239,7 +198,7 @@ public Requester with(String key, Enum e) { * @return the requester */ public Requester with(String key, String value) { - return _with(key, value); + return with(key, (Object) value); } /** @@ -252,24 +211,7 @@ public Requester with(String key, String value) { * @return the requester */ public Requester with(String key, Collection value) { - return _with(key, value); - } - - /** - * With logins requester. - * - * @param key - * the key - * @param users - * the users - * @return the requester - */ - public Requester withLogins(String key, Collection users) { - List names = new ArrayList(users.size()); - for (GHUser a : users) { - names.add(a.getLogin()); - } - return with(key, names); + return with(key, (Object) value); } /** @@ -282,24 +224,7 @@ public Requester withLogins(String key, Collection users) { * @return the requester */ public Requester with(String key, Map value) { - return _with(key, value); - } - - /** - * With permissions requester. - * - * @param key - * the key - * @param value - * the value - * @return the requester - */ - public Requester withPermissions(String key, Map value) { - Map retMap = new HashMap(); - for (Map.Entry entry : value.entrySet()) { - retMap.put(entry.getKey(), transformEnum(entry.getValue())); - } - return _with(key, retMap); + return with(key, (Object) value); } /** @@ -337,7 +262,7 @@ public Requester withNullable(String key, Object value) { * the value * @return the requester */ - public Requester _with(String key, Object value) { + public Requester with(String key, Object value) { if (value != null) { args.add(new Entry(key, value)); } @@ -360,7 +285,7 @@ public Requester set(String key, Object value) { return this; } } - return _with(key, value); + return with(key, value); } /** @@ -392,7 +317,7 @@ public Requester contentType(String contentType) { * Normally whether parameters go as query parameters or a body depends on the HTTP verb in use, but this method * forces the parameters to be sent as a body. */ - Requester inBody() { + public Requester inBody() { forceBody = true; return this; } @@ -406,7 +331,7 @@ Requester inBody() { * the io exception */ public void to(String tailApiUrl) throws IOException { - to(tailApiUrl, null); + _to(tailApiUrl, null, null); } /** @@ -443,26 +368,6 @@ public T to(String tailApiUrl, T existingInstance) throws IOException { return _to(tailApiUrl, null, existingInstance); } - /** - * Short for {@code method(method).to(tailApiUrl,type)} - * - * @param - * the type parameter - * @param tailApiUrl - * the tail api url - * @param type - * the type - * @param method - * the method - * @return the t - * @throws IOException - * the io exception - */ - @Deprecated - public T to(String tailApiUrl, Class type, String method) throws IOException { - return method(method).to(tailApiUrl, type); - } - @SuppressFBWarnings("SBSC_USE_STRINGBUFFER_CONCATENATION") private T _to(String tailApiUrl, Class type, T instance) throws IOException { if (!isMethodWithBody() && !args.isEmpty()) { @@ -1017,7 +922,7 @@ void handleApiError(IOException e) throws IOException { * Enum to be transformed * @return a String containing the value of a Github constant */ - private String transformEnum(Enum en) { + static String transformEnum(Enum en) { // by convention Java constant names are upper cases, but github uses // lower-case constants. GitHub also uses '-', which in Java we always // replace by '_' From f262bf7cdbd367ef1c989448521456258e6b4562 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Fri, 15 Nov 2019 13:48:48 -0800 Subject: [PATCH 2/3] Commit default format --- pom.xml | 3 + src/main/resources/eclipse/formatter.xml | 362 +++++++++++++++++++++++ 2 files changed, 365 insertions(+) create mode 100644 src/main/resources/eclipse/formatter.xml diff --git a/pom.xml b/pom.xml index e3eeb736b6..e572980cf5 100644 --- a/pom.xml +++ b/pom.xml @@ -175,6 +175,9 @@ ${formatter-maven-plugin.goal} + + eclipse/formatter.xml + diff --git a/src/main/resources/eclipse/formatter.xml b/src/main/resources/eclipse/formatter.xml new file mode 100644 index 0000000000..976c8fe99b --- /dev/null +++ b/src/main/resources/eclipse/formatter.xml @@ -0,0 +1,362 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From da11702f6815f658014f33ce724f0cd2e4501081 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Fri, 15 Nov 2019 15:18:07 -0800 Subject: [PATCH 3/3] Modify formatting to columnize Turns out I do care about formatting a little. We have a lot of builders and chained methods. I think it is easier to follow long chains when lined up veritcally. --- pom.xml | 2 +- src/main/java/org/kohsuke/github/GHApp.java | 26 +- .../org/kohsuke/github/GHAuthorization.java | 4 +- .../java/org/kohsuke/github/GHBranch.java | 22 +- .../kohsuke/github/GHBranchProtection.java | 6 +- .../github/GHBranchProtectionBuilder.java | 15 +- .../java/org/kohsuke/github/GHCommit.java | 23 +- .../org/kohsuke/github/GHCommitComment.java | 15 +- .../java/org/kohsuke/github/GHCompare.java | 4 +- .../java/org/kohsuke/github/GHContent.java | 11 +- src/main/java/org/kohsuke/github/GHEmail.java | 6 +- .../java/org/kohsuke/github/GHEventInfo.java | 18 +- .../org/kohsuke/github/GHEventPayload.java | 51 ++-- src/main/java/org/kohsuke/github/GHHook.java | 4 +- src/main/java/org/kohsuke/github/GHHooks.java | 7 +- .../java/org/kohsuke/github/GHInvitation.java | 6 +- .../org/kohsuke/github/GHIssueBuilder.java | 6 +- .../org/kohsuke/github/GHIssueComment.java | 11 +- .../java/org/kohsuke/github/GHIssueEvent.java | 5 +- src/main/java/org/kohsuke/github/GHLabel.java | 18 +- .../java/org/kohsuke/github/GHLicense.java | 4 +- .../java/org/kohsuke/github/GHMyself.java | 11 +- .../kohsuke/github/GHNotificationStream.java | 4 +- .../java/org/kohsuke/github/GHObject.java | 4 +- .../org/kohsuke/github/GHOrganization.java | 50 +++- .../java/org/kohsuke/github/GHPerson.java | 4 +- .../java/org/kohsuke/github/GHProject.java | 15 +- .../org/kohsuke/github/GHProjectColumn.java | 22 +- .../github/GHPullRequestCommitDetail.java | 6 +- .../github/GHPullRequestQueryBuilder.java | 4 +- .../kohsuke/github/GHPullRequestReview.java | 10 +- .../github/GHPullRequestReviewBuilder.java | 6 +- .../github/GHPullRequestReviewComment.java | 18 +- .../github/GHPullRequestReviewEvent.java | 16 +- .../github/GHPullRequestReviewState.java | 28 ++- .../java/org/kohsuke/github/GHRateLimit.java | 10 +- src/main/java/org/kohsuke/github/GHRef.java | 5 +- .../java/org/kohsuke/github/GHRelease.java | 4 +- .../org/kohsuke/github/GHReleaseUpdater.java | 3 +- .../java/org/kohsuke/github/GHRepository.java | 228 ++++++++++++------ .../github/GHRepositoryStatistics.java | 25 +- src/main/java/org/kohsuke/github/GHTag.java | 4 +- .../java/org/kohsuke/github/GHTagObject.java | 4 +- src/main/java/org/kohsuke/github/GHTeam.java | 4 +- .../java/org/kohsuke/github/GHThread.java | 11 +- src/main/java/org/kohsuke/github/GHUser.java | 12 +- src/main/java/org/kohsuke/github/GitHub.java | 45 ++-- .../org/kohsuke/github/GitHubBuilder.java | 17 +- src/main/java/org/kohsuke/github/GitUser.java | 4 +- .../kohsuke/github/PagedSearchIterable.java | 6 +- .../extras/okhttp3/ObsoleteUrlFactory.java | 30 ++- src/main/resources/eclipse/formatter.xml | 21 ++ .../github/AbstractGitHubWireMockTest.java | 7 +- src/test/java/org/kohsuke/github/AppTest.java | 76 ++++-- .../org/kohsuke/github/GHRateLimitTest.java | 33 ++- .../java/org/kohsuke/github/GistTest.java | 8 +- .../kohsuke/github/GitHubConnectionTest.java | 4 +- .../org/kohsuke/github/GitHubStaticTest.java | 12 +- .../java/org/kohsuke/github/GitHubTest.java | 14 +- .../org/kohsuke/github/Github2faTest.java | 8 +- .../github/extras/OkHttpConnectorTest.java | 15 +- 61 files changed, 710 insertions(+), 362 deletions(-) diff --git a/pom.xml b/pom.xml index e572980cf5..7b3feb66a4 100644 --- a/pom.xml +++ b/pom.xml @@ -176,7 +176,7 @@ ${formatter-maven-plugin.goal} - eclipse/formatter.xml + src/main/resources/eclipse/formatter.xml diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 6c587ce083..a7fb74feed 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -183,8 +183,9 @@ GHApp wrapUp(GitHub root) { @Preview @Deprecated public PagedIterable listInstallations() { - return root.retrieve().withPreview(MACHINE_MAN).asPagedIterable("/app/installations", GHAppInstallation[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .withPreview(MACHINE_MAN) + .asPagedIterable("/app/installations", GHAppInstallation[].class, item -> item.wrapUp(root)); } /** @@ -202,8 +203,10 @@ public PagedIterable listInstallations() { @Preview @Deprecated public GHAppInstallation getInstallationById(long id) throws IOException { - return root.retrieve().withPreview(MACHINE_MAN) - .to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root); + return root.retrieve() + .withPreview(MACHINE_MAN) + .to(String.format("/app/installations/%d", id), GHAppInstallation.class) + .wrapUp(root); } /** @@ -222,8 +225,10 @@ public GHAppInstallation getInstallationById(long id) throws IOException { @Preview @Deprecated public GHAppInstallation getInstallationByOrganization(String name) throws IOException { - return root.retrieve().withPreview(MACHINE_MAN) - .to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root); + return root.retrieve() + .withPreview(MACHINE_MAN) + .to(String.format("/orgs/%s/installation", name), GHAppInstallation.class) + .wrapUp(root); } /** @@ -244,7 +249,8 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc @Preview @Deprecated public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { - return root.retrieve().withPreview(MACHINE_MAN) + return root.retrieve() + .withPreview(MACHINE_MAN) .to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class) .wrapUp(root); } @@ -264,8 +270,10 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re @Preview @Deprecated public GHAppInstallation getInstallationByUser(String name) throws IOException { - return root.retrieve().withPreview(MACHINE_MAN) - .to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root); + return root.retrieve() + .withPreview(MACHINE_MAN) + .to(String.format("/users/%s/installation", name), GHAppInstallation.class) + .wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHAuthorization.java b/src/main/java/org/kohsuke/github/GHAuthorization.java index 1cc469c98f..26b5f3d51b 100644 --- a/src/main/java/org/kohsuke/github/GHAuthorization.java +++ b/src/main/java/org/kohsuke/github/GHAuthorization.java @@ -158,8 +158,8 @@ GHAuthorization wrap(GitHub root) { return this; } - @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") private static class App { private String url; private String name; diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 19df9ed043..771cfa6175 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -14,8 +14,10 @@ * * @author Yusuke Kokubo */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", - "URF_UNREAD_FIELD" }, justification = "JSON API") +@SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "URF_UNREAD_FIELD" }, + justification = "JSON API") public class GHBranch { private GitHub root; private GHRepository owner; @@ -141,13 +143,15 @@ public GHBranchProtectionBuilder enableProtection() { @Deprecated public void enableProtection(EnforcementLevel level, Collection contexts) throws IOException { switch (level) { - case OFF: - disableProtection(); - break; - case NON_ADMINS: - case EVERYONE: - enableProtection().addRequiredChecks(contexts).includeAdmins(level == EnforcementLevel.EVERYONE).enable(); - break; + case OFF : + disableProtection(); + break; + case NON_ADMINS : + case EVERYONE : + enableProtection().addRequiredChecks(contexts) + .includeAdmins(level == EnforcementLevel.EVERYONE) + .enable(); + break; } } diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index e9b8b1861d..80a5e7bb4e 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -11,8 +11,10 @@ /** * The type GHBranchProtection. */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", - "URF_UNREAD_FIELD" }, justification = "JSON API") +@SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "URF_UNREAD_FIELD" }, + justification = "JSON API") public class GHBranchProtection { private static final String REQUIRE_SIGNATURES_URI = "/required_signatures"; diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index 33db4aa935..c94020b306 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -19,8 +19,10 @@ * * @see GHBranch#enableProtection() GHBranch#enableProtection() */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", - "URF_UNREAD_FIELD" }, justification = "JSON API") +@SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "URF_UNREAD_FIELD" }, + justification = "JSON API") public class GHBranchProtectionBuilder { private final GHBranch branch; @@ -86,10 +88,13 @@ public GHBranchProtectionBuilder dismissStaleReviews(boolean v) { * the io exception */ public GHBranchProtection enable() throws IOException { - return requester().method("PUT").withNullable("required_status_checks", statusChecks) - .withNullable("required_pull_request_reviews", prReviews).withNullable("restrictions", restrictions) + return requester().method("PUT") + .withNullable("required_status_checks", statusChecks) + .withNullable("required_pull_request_reviews", prReviews) + .withNullable("restrictions", restrictions) .withNullable("enforce_admins", enforceAdmins) - .to(branch.getProtectionUrl().toString(), GHBranchProtection.class).wrap(branch); + .to(branch.getProtectionUrl().toString(), GHBranchProtection.class) + .wrap(branch); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 5f381bfc95..b1e7b7dc06 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -27,8 +27,10 @@ public class GHCommit { /** * Short summary of this commit. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "UWF_UNWRITTEN_FIELD" }, + justification = "JSON API") public static class ShortInfo { private GHAuthor author; private GHAuthor committer; @@ -167,7 +169,8 @@ public String getStatus() { * * @return Full path in the repository. */ - @SuppressFBWarnings(value = "NM_CONFUSING", justification = "It's a part of the library's API and cannot be renamed") + @SuppressFBWarnings(value = "NM_CONFUSING", + justification = "It's a part of the library's API and cannot be renamed") public String getFileName() { return filename; } @@ -344,7 +347,7 @@ public String getSHA1() { */ public List getFiles() throws IOException { populate(); - return files != null ? Collections.unmodifiableList(files) : Collections. emptyList(); + return files != null ? Collections.unmodifiableList(files) : Collections.emptyList(); } /** @@ -438,9 +441,11 @@ private GHUser resolveUser(User author) throws IOException { * @return {@link PagedIterable} with all the commit comments in this repository. */ public PagedIterable listComments() { - return owner.root.retrieve().asPagedIterable( - String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), - GHCommitComment[].class, item -> item.wrap(owner)); + return owner.root.retrieve() + .asPagedIterable( + String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), + GHCommitComment[].class, + item -> item.wrap(owner)); } /** @@ -461,7 +466,9 @@ public PagedIterable listComments() { * if comment is not created */ public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException { - GHCommitComment r = new Requester(owner.root).with("body", body).with("path", path).with("line", line) + GHCommitComment r = new Requester(owner.root).with("body", body) + .with("path", path) + .with("line", line) .with("position", position) .to(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment.class); diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index 9ee1843a71..e53e8607f0 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -16,8 +16,8 @@ * @see GHCommit#createComment(String, String, Integer, Integer) GHCommit#createComment(String, String, Integer, * Integer) */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GHCommitComment extends GHObject implements Reactable { private GHRepository owner; @@ -120,15 +120,18 @@ public void update(String body) throws IOException { @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL).with("content", content.getContent()) - .to(getApiTail() + "/reactions", GHReaction.class).wrap(owner.root); + return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + .with("content", content.getContent()) + .to(getApiTail() + "/reactions", GHReaction.class) + .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve().withPreview(SQUIRREL_GIRL).asPagedIterable(getApiTail() + "/reactions", - GHReaction[].class, item -> item.wrap(owner.root)); + return owner.root.retrieve() + .withPreview(SQUIRREL_GIRL) + .asPagedIterable(getApiTail() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHCompare.java b/src/main/java/org/kohsuke/github/GHCompare.java index d01cb67340..430e9fc46f 100644 --- a/src/main/java/org/kohsuke/github/GHCompare.java +++ b/src/main/java/org/kohsuke/github/GHCompare.java @@ -163,8 +163,8 @@ public GHCompare wrap(GHRepository owner) { * Compare commits had a child commit element with additional details we want to capture. This extenstion of * GHCommit provides that. */ - @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 Commit extends GHCommit { private InnerCommit commit; diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 41429b6d23..86f5a4aadc 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -306,8 +306,11 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa throws IOException { String encodedContent = Base64.encodeBase64String(newContentBytes); - Requester requester = new Requester(root).with("path", path).with("message", commitMessage).with("sha", sha) - .with("content", encodedContent).method("PUT"); + Requester requester = new Requester(root).with("path", path) + .with("message", commitMessage) + .with("sha", sha) + .with("content", encodedContent) + .method("PUT"); if (branch != null) { requester.with("branch", branch); @@ -347,7 +350,9 @@ public GHContentUpdateResponse delete(String message) throws IOException { * the io exception */ public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException { - Requester requester = new Requester(root).with("path", path).with("message", commitMessage).with("sha", sha) + Requester requester = new Requester(root).with("path", path) + .with("message", commitMessage) + .with("sha", sha) .method("DELETE"); if (branch != null) { diff --git a/src/main/java/org/kohsuke/github/GHEmail.java b/src/main/java/org/kohsuke/github/GHEmail.java index 796aa3aaed..e1b892f007 100644 --- a/src/main/java/org/kohsuke/github/GHEmail.java +++ b/src/main/java/org/kohsuke/github/GHEmail.java @@ -30,8 +30,10 @@ * * @author Kelly Campbell */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", - "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD" }, justification = "JSON API") +@SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD" }, + justification = "JSON API") public class GHEmail { protected String email; diff --git a/src/main/java/org/kohsuke/github/GHEventInfo.java b/src/main/java/org/kohsuke/github/GHEventInfo.java index 830ab3f809..de150e2823 100644 --- a/src/main/java/org/kohsuke/github/GHEventInfo.java +++ b/src/main/java/org/kohsuke/github/GHEventInfo.java @@ -30,8 +30,10 @@ public class GHEventInfo { /** * Inside the event JSON model, GitHub uses a slightly different format. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", + "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, + justification = "JSON API") public static class GHEventRepository { @SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now") private long id; @@ -86,8 +88,8 @@ public Date getCreatedAt() { * @throws IOException * on error */ - @SuppressFBWarnings(value = { - "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "The field comes from JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, + justification = "The field comes from JSON deserialization") public GHRepository getRepository() throws IOException { return root.getRepository(repo.name); } @@ -99,8 +101,8 @@ public GHRepository getRepository() throws IOException { * @throws IOException * on error */ - @SuppressFBWarnings(value = { - "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "The field comes from JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, + justification = "The field comes from JSON deserialization") public GHUser getActor() throws IOException { return root.getUser(actor.getLogin()); } @@ -123,8 +125,8 @@ public String getActorLogin() throws IOException { * @throws IOException * the io exception */ - @SuppressFBWarnings(value = { - "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "The field comes from JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, + justification = "The field comes from JSON deserialization") public GHOrganization getOrganization() throws IOException { return (org == null || org.getLogin() == null) ? null : root.getOrganization(org.getLogin()); } diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 4806f56261..ddf0b17e13 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -53,8 +53,9 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public static class PullRequest extends GHEventPayload { private String action; private int number; @@ -251,8 +252,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @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; @@ -323,8 +324,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class IssueComment extends GHEventPayload { private String action; private GHIssueComment comment; @@ -416,8 +417,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class CommitComment extends GHEventPayload { private String action; private GHCommitComment comment; @@ -486,8 +487,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class Create extends GHEventPayload { private String ref; @JsonProperty("ref_type") @@ -570,8 +571,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class Delete extends GHEventPayload { private String ref; @JsonProperty("ref_type") @@ -631,8 +632,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class Deployment extends GHEventPayload { private GHDeployment deployment; private GHRepository repository; @@ -691,8 +692,8 @@ void wrapUp(GitHub root) { * @see authoritative * source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class DeploymentStatus extends GHEventPayload { @JsonProperty("deployment_status") private GHDeploymentStatus deploymentStatus; @@ -772,8 +773,8 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class Fork extends GHEventPayload { private GHRepository forkee; private GHRepository repository; @@ -924,8 +925,9 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", - "UUF_UNUSED_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings( + value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD" }, + justification = "Constructed by JSON deserialization") public static class Push extends GHEventPayload { private String head, before; private boolean created, deleted, forced; @@ -1196,8 +1198,8 @@ public List getModified() { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", - "NP_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @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; @@ -1265,8 +1267,9 @@ void wrapUp(GitHub root) { * * @see authoritative source */ - @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", - "UWF_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + @SuppressFBWarnings( + value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD" }, + justification = "Constructed by JSON deserialization") public static class Repository extends GHEventPayload { private String action; private GHRepository repository; diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index 4b56fb1c44..a88c9a372c 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -15,8 +15,8 @@ * * @author Kohsuke Kawaguchi */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public abstract class GHHook extends GHObject { String name; List events; diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index b4742dc87c..7f99de7a77 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -74,8 +74,11 @@ public GHHook createHook(String name, Map config, Collection 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)); } private String getApiRoute() { diff --git a/src/main/java/org/kohsuke/github/GHIssueEvent.java b/src/main/java/org/kohsuke/github/GHIssueEvent.java index f74ce20ea7..83c2204042 100644 --- a/src/main/java/org/kohsuke/github/GHIssueEvent.java +++ b/src/main/java/org/kohsuke/github/GHIssueEvent.java @@ -124,7 +124,10 @@ GHIssueEvent wrapUp(GHIssue parent) { @Override public String toString() { - return String.format("Issue %d was %s by %s on %s", getIssue().getNumber(), getEvent(), getActor().getLogin(), + return String.format("Issue %d was %s by %s on %s", + getIssue().getNumber(), + getEvent(), + getActor().getLogin(), getCreatedAt().toString()); } } diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 608902cecf..7c6bc38a81 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -81,8 +81,13 @@ public void delete() throws IOException { * the io exception */ public void setColor(String newColor) throws IOException { - repo.root.retrieve().method("PATCH").withPreview(SYMMETRA).with("name", name).with("color", newColor) - .with("description", description).to(url); + repo.root.retrieve() + .method("PATCH") + .withPreview(SYMMETRA) + .with("name", name) + .with("color", newColor) + .with("description", description) + .to(url); } /** @@ -96,8 +101,13 @@ public void setColor(String newColor) throws IOException { @Preview @Deprecated public void setDescription(String newDescription) throws IOException { - repo.root.retrieve().method("PATCH").withPreview(SYMMETRA).with("name", name).with("color", color) - .with("description", newDescription).to(url); + repo.root.retrieve() + .method("PATCH") + .withPreview(SYMMETRA) + .with("name", name) + .with("color", color) + .with("description", newDescription) + .to(url); } static Collection toNames(Collection labels) { diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java index e05a934b2e..e7c4cff56d 100644 --- a/src/main/java/org/kohsuke/github/GHLicense.java +++ b/src/main/java/org/kohsuke/github/GHLicense.java @@ -41,8 +41,8 @@ * @see https://developer.github.com/v3/licenses/ */ @SuppressWarnings({ "UnusedDeclaration" }) -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GHLicense extends GHObject { @SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // root is set before the object is returned to the app diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index d728d7ed81..0d16f77d4b 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -175,8 +175,10 @@ public PagedIterable listRepositories(final int pageSize) { * @return the paged iterable */ public PagedIterable listRepositories(final int pageSize, final RepositoryListFilter repoType) { - return root.retrieve().with("type", repoType) - .asPagedIterable("/user/repos", GHRepository[].class, item -> item.wrap(root)).withPageSize(pageSize); + return root.retrieve() + .with("type", repoType) + .asPagedIterable("/user/repos", GHRepository[].class, item -> item.wrap(root)) + .withPageSize(pageSize); } /** @@ -206,8 +208,9 @@ public PagedIterable listOrgMemberships() { * @return the paged iterable */ public PagedIterable listOrgMemberships(final GHMembership.State state) { - return root.retrieve().with("state", state).asPagedIterable("/user/memberships/orgs", GHMembership[].class, - item -> item.wrap(root)); + return root.retrieve() + .with("state", state) + .asPagedIterable("/user/memberships/orgs", GHMembership[].class, item -> item.wrap(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 71dd0a3de2..9d62480651 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -101,7 +101,9 @@ public GHNotificationStream nonBlocking(boolean v) { */ public Iterator iterator() { // capture the configuration setting here - final Requester req = new Requester(root).method("GET").with("all", all).with("participating", participating) + final Requester req = new Requester(root).method("GET") + .with("all", all) + .with("participating", participating) .with("since", since); return new Iterator() { diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 8c657ea69e..a2893c2e12 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -16,8 +16,8 @@ /** * Most (all?) domain objects in GitHub seems to have these 4 properties. */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public abstract class GHObject { /** * Capture response HTTP headers on the state object. diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 3ed363d3e2..c7edefdb41 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -39,7 +39,10 @@ GHOrganization wrapUp(GitHub root) { * the io exception * @deprecated Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect. */ - public GHRepository createRepository(String name, String description, String homepage, String team, + public GHRepository createRepository(String name, + String description, + String homepage, + String team, boolean isPublic) throws IOException { GHTeam t = getTeams().get(team); if (t == null) @@ -65,11 +68,17 @@ public GHRepository createRepository(String name, String description, String hom * the io exception * @deprecated Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect. */ - public GHRepository createRepository(String name, String description, String homepage, GHTeam team, + public GHRepository createRepository(String name, + String description, + String homepage, + GHTeam team, boolean isPublic) throws IOException { if (team == null) throw new IllegalArgumentException("Invalid team"); - return createRepository(name).description(description).homepage(homepage).private_(!isPublic).team(team) + return createRepository(name).description(description) + .homepage(homepage) + .private_(!isPublic) + .team(team) .create(); } @@ -111,8 +120,10 @@ public Map getTeams() throws IOException { * the io exception */ public PagedIterable listTeams() throws IOException { - return root.retrieve().asPagedIterable(String.format("/orgs/%s/teams", login), GHTeam[].class, - item -> item.wrapUp(GHOrganization.this)); + return root.retrieve() + .asPagedIterable(String.format("/orgs/%s/teams", login), + GHTeam[].class, + item -> item.wrapUp(GHOrganization.this)); } /** @@ -171,7 +182,9 @@ public enum Role { * "https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership">documentation */ public void add(GHUser user, Role role) throws IOException { - root.retrieve().method("PUT").with("role", role.name().toLowerCase()) + root.retrieve() + .method("PUT") + .with("role", role.name().toLowerCase()) .to("/orgs/" + login + "/memberships/" + user.getLogin()); } @@ -285,8 +298,10 @@ public PagedIterable listMembersWithFilter(String filter) throws IOExcep private PagedIterable listMembers(final String suffix, final String filter) throws IOException { String filterParams = (filter == null) ? "" : ("?filter=" + filter); - return root.retrieve().asPagedIterable(String.format("/orgs/%s/%s%s", login, suffix, filterParams), - GHUser[].class, item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(String.format("/orgs/%s/%s%s", login, suffix, filterParams), + GHUser[].class, + item -> item.wrapUp(root)); } /** @@ -311,7 +326,9 @@ public void conceal(GHUser u) throws IOException { * the io exception */ public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { - return root.retrieve().withPreview(INERTIA).with("state", status) + return root.retrieve() + .withPreview(INERTIA) + .with("state", status) .asPagedIterable(String.format("/orgs/%s/projects", login), GHProject[].class, item -> item.wrap(root)); } @@ -338,8 +355,13 @@ public PagedIterable listProjects() throws IOException { * the io exception */ public GHProject createProject(String name, String body) throws IOException { - return root.retrieve().method("POST").withPreview(INERTIA).with("name", name).with("body", body) - .to(String.format("/orgs/%s/projects", login), GHProject.class).wrap(root); + return root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with("name", name) + .with("body", body) + .to(String.format("/orgs/%s/projects", login), GHProject.class) + .wrap(root); } /** @@ -430,8 +452,10 @@ public List getPullRequests() throws IOException { * Lists events performed by a user (this includes private events if the caller is authenticated. */ public PagedIterable listEvents() throws IOException { - return root.retrieve().asPagedIterable(String.format("/orgs/%s/events", login), GHEventInfo[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(String.format("/orgs/%s/events", login), + GHEventInfo[].class, + item -> item.wrapUp(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index ffc69ba416..286e97e6f3 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -112,8 +112,8 @@ public PagedIterable listRepositories(final int pageSize) { public synchronized Iterable> iterateRepositories(final int pageSize) { return new Iterable>() { public Iterator> iterator() { - final Iterator pager = root.retrieve().asIterator("/users/" + login + "/repos", - GHRepository[].class, pageSize); + final Iterator pager = root.retrieve() + .asIterator("/users/" + login + "/repos", GHRepository[].class, pageSize); return new Iterator>() { public boolean hasNext() { diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index d0e222c005..03807b795c 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -282,8 +282,11 @@ public void delete() throws IOException { */ public PagedIterable listColumns() throws IOException { final GHProject project = this; - return root.retrieve().withPreview(INERTIA).asPagedIterable(String.format("/projects/%d/columns", id), - GHProjectColumn[].class, item -> item.wrap(project)); + return root.retrieve() + .withPreview(INERTIA) + .asPagedIterable(String.format("/projects/%d/columns", id), + GHProjectColumn[].class, + item -> item.wrap(project)); } /** @@ -296,7 +299,11 @@ public PagedIterable listColumns() throws IOException { * the io exception */ public GHProjectColumn createColumn(String name) throws IOException { - return root.retrieve().method("POST").withPreview(INERTIA).with("name", name) - .to(String.format("/projects/%d/columns", id), GHProjectColumn.class).wrap(this); + return root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with("name", name) + .to(String.format("/projects/%d/columns", id), GHProjectColumn.class) + .wrap(this); } } \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index 2c62e1e9ad..b93f709c36 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -137,8 +137,11 @@ public void delete() throws IOException { */ public PagedIterable listCards() throws IOException { final GHProjectColumn column = this; - return root.retrieve().withPreview(INERTIA).asPagedIterable(String.format("/projects/columns/%d/cards", id), - GHProjectCard[].class, item -> item.wrap(column)); + return root.retrieve() + .withPreview(INERTIA) + .asPagedIterable(String.format("/projects/columns/%d/cards", id), + GHProjectCard[].class, + item -> item.wrap(column)); } /** @@ -151,8 +154,12 @@ public PagedIterable listCards() throws IOException { * the io exception */ public GHProjectCard createCard(String note) throws IOException { - return root.retrieve().method("POST").withPreview(INERTIA).with("note", note) - .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class).wrap(this); + return root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with("note", note) + .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class) + .wrap(this); } /** @@ -165,9 +172,12 @@ public GHProjectCard createCard(String note) throws IOException { * the io exception */ public GHProjectCard createCard(GHIssue issue) throws IOException { - return root.retrieve().method("POST").withPreview(INERTIA) + return root.retrieve() + .method("POST") + .withPreview(INERTIA) .with("content_type", issue instanceof GHPullRequest ? "PullRequest" : "Issue") .with("content_id", issue.getId()) - .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class).wrap(this); + .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class) + .wrap(this); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java index 77528ee99e..b80902c553 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java @@ -34,8 +34,10 @@ * @author Luca Milanesio * @see GHPullRequest#listCommits() GHPullRequest#listCommits() */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", - "URF_UNREAD_FIELD" }, justification = "JSON API") +@SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "URF_UNREAD_FIELD" }, + justification = "JSON API") public class GHPullRequestCommitDetail { private GHPullRequest owner; diff --git a/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java index 787503d438..d19d88e27e 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java @@ -88,7 +88,7 @@ public GHPullRequestQueryBuilder direction(GHDirection d) { @Override public PagedIterable list() { - return req.withPreview(SHADOW_CAT).asPagedIterable(repo.getApiTailUrl("pulls"), GHPullRequest[].class, - item -> item.wrapUp(repo)); + return req.withPreview(SHADOW_CAT) + .asPagedIterable(repo.getApiTailUrl("pulls"), GHPullRequest[].class, item -> item.wrapUp(repo)); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index ecf8a51cf3..6dc1ee359d 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -159,7 +159,9 @@ public void submit(String body, GHPullRequestReviewState state) throws IOExcepti * the io exception */ public void submit(String body, GHPullRequestReviewEvent event) throws IOException { - new Requester(owner.root).method("POST").with("body", body).with("event", event.action()) + new Requester(owner.root).method("POST") + .with("body", body) + .with("event", event.action()) .to(getApiRoute() + "/events", this); this.body = body; this.state = event.toState(); @@ -196,7 +198,9 @@ public void dismiss(String message) throws IOException { * the io exception */ public PagedIterable listReviewComments() throws IOException { - return owner.root.retrieve().asPagedIterable(getApiRoute() + "/comments", GHPullRequestReviewComment[].class, - item -> item.wrapUp(owner)); + return owner.root.retrieve() + .asPagedIterable(getApiRoute() + "/comments", + GHPullRequestReviewComment[].class, + item -> item.wrapUp(owner)); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index 6d1bfd4f82..cf0bf2171d 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -89,8 +89,10 @@ public GHPullRequestReviewBuilder comment(String body, String path, int position * the io exception */ public GHPullRequestReview create() throws IOException { - return builder.method("POST").with("comments", comments) - .to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class).wrapUp(pr); + return builder.method("POST") + .with("comments", comments) + .to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class) + .wrapUp(pr); } private static class DraftReviewComment { diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 108747112e..e1e6a1cf72 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -186,21 +186,27 @@ public void delete() throws IOException { * the io exception */ 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); + return new Requester(owner.root).method("POST") + .with("body", body) + .with("in_reply_to", getId()) + .to(getApiRoute() + "/comments", GHPullRequestReviewComment.class) + .wrapUp(owner); } @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(owner.root); + return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + .with("content", content.getContent()) + .to(getApiRoute() + "/reactions", GHReaction.class) + .wrap(owner.root); } @Preview @Deprecated public PagedIterable 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)); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java index 3bcea3311f..0d4e681c38 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java @@ -38,14 +38,14 @@ String action() { */ 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; + 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(); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java index 7403992bb5..3055cff233 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java @@ -4,12 +4,16 @@ * Current state of {@link GHPullRequestReview} */ public enum GHPullRequestReviewState { - PENDING, APPROVED, CHANGES_REQUESTED, + PENDING, + APPROVED, + CHANGES_REQUESTED, /** * @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; + REQUEST_CHANGES, + COMMENTED, + DISMISSED; /** * Action string. @@ -24,16 +28,16 @@ public String action() { GHPullRequestReviewEvent toEvent() { 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; + 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; } diff --git a/src/main/java/org/kohsuke/github/GHRateLimit.java b/src/main/java/org/kohsuke/github/GHRateLimit.java index 251b54fa3e..08e2cfa539 100644 --- a/src/main/java/org/kohsuke/github/GHRateLimit.java +++ b/src/main/java/org/kohsuke/github/GHRateLimit.java @@ -60,7 +60,9 @@ public class GHRateLimit { private final Record integrationManifest; static GHRateLimit Unknown() { - return new GHRateLimit(new UnknownLimitRecord(), new UnknownLimitRecord(), new UnknownLimitRecord(), + return new GHRateLimit(new UnknownLimitRecord(), + new UnknownLimitRecord(), + new UnknownLimitRecord(), new UnknownLimitRecord()); } @@ -69,7 +71,8 @@ static GHRateLimit fromHeaderRecord(Record header) { } @JsonCreator - GHRateLimit(@Nonnull @JsonProperty("core") Record core, @Nonnull @JsonProperty("search") Record search, + GHRateLimit(@Nonnull @JsonProperty("core") Record core, + @Nonnull @JsonProperty("search") Record search, @Nonnull @JsonProperty("graphql") Record graphql, @Nonnull @JsonProperty("integration_manifest") Record integrationManifest) { this.core = core; @@ -266,7 +269,8 @@ public static class Record { * the reset epoch seconds */ @JsonCreator - public Record(@JsonProperty("limit") int limit, @JsonProperty("remaining") int remaining, + public Record(@JsonProperty("limit") int limit, + @JsonProperty("remaining") int remaining, @JsonProperty("reset") long resetEpochSeconds) { this(limit, remaining, resetEpochSeconds, null); } diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 529eacc3c2..c450aae080 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -94,8 +94,9 @@ static GHRef[] wrap(GHRef[] in, GitHub root) { /** * The type GHObject. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public static class GHObject { private String type, sha, url; diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 5f5ed2aed0..796cecf73a 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -241,7 +241,9 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { Requester builder = new Requester(owner.root); - String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", owner.getApiTailUrl(""), getId(), + String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", + owner.getApiTailUrl(""), + getId(), filename); return builder.contentType(contentType).with(stream).to(url, GHAsset.class).wrap(this); } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index 7f4b1c6f59..3c52eb0864 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -99,7 +99,8 @@ public GHReleaseUpdater prerelease(boolean prerelease) { * the io exception */ public GHRelease update() throws IOException { - return builder.method("PATCH").to(base.owner.getApiTailUrl("releases/" + base.id), GHRelease.class) + return builder.method("PATCH") + .to(base.owner.getApiTailUrl("releases/" + base.id), GHRelease.class) .wrap(base.owner); } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index e6dd1e715f..7588034288 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -67,8 +67,8 @@ * @author Kohsuke Kawaguchi */ @SuppressWarnings({ "UnusedDeclaration" }) -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GHRepository extends GHObject { /* package almost final */ GitHub root; @@ -142,11 +142,13 @@ public PagedIterable getDeploymentStatuses(final int id) thr * @return the paged iterable */ public PagedIterable listDeployments(String sha, String ref, String task, String environment) { - List params = Arrays.asList(getParam("sha", sha), getParam("ref", ref), getParam("task", task), + List params = Arrays.asList(getParam("sha", sha), + getParam("ref", ref), + getParam("task", task), getParam("environment", environment)); final String deploymentsUrl = getApiTailUrl("deployments") + "?" + join(params, "&"); - return root.retrieve().asPagedIterable(deploymentsUrl, GHDeployment[].class, - item -> item.wrap(GHRepository.this)); + return root.retrieve() + .asPagedIterable(deploymentsUrl, GHDeployment[].class, item -> item.wrap(GHRepository.this)); } /** @@ -390,7 +392,8 @@ public List getIssues(GHIssueState state) throws IOException { * the io exception */ public List getIssues(GHIssueState state, GHMilestone milestone) throws IOException { - return Arrays.asList(GHIssue.wrap(root.retrieve().with("state", state) + return Arrays.asList(GHIssue.wrap(root.retrieve() + .with("state", state) .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()) .to(getApiTailUrl("issues"), GHIssue[].class), this)); } @@ -403,8 +406,9 @@ public List getIssues(GHIssueState state, GHMilestone milestone) throws * @return the paged iterable */ public PagedIterable listIssues(final GHIssueState state) { - return root.retrieve().with("state", state).asPagedIterable(getApiTailUrl("issues"), GHIssue[].class, - item -> item.wrap(GHRepository.this)); + return root.retrieve() + .with("state", state) + .asPagedIterable(getApiTailUrl("issues"), GHIssue[].class, item -> item.wrap(GHRepository.this)); } /** @@ -431,8 +435,11 @@ public GHReleaseBuilder createRelease(String tag) { * the io exception */ public GHRef createRef(String name, String sha) throws IOException { - return new Requester(root).with("ref", name).with("sha", sha).method("POST") - .to(getApiTailUrl("git/refs"), GHRef.class).wrap(root); + return new Requester(root).with("ref", name) + .with("sha", sha) + .method("POST") + .to(getApiTailUrl("git/refs"), GHRef.class) + .wrap(root); } /** @@ -504,8 +511,8 @@ public GHRelease getLatestRelease() throws IOException { * the io exception */ public PagedIterable listReleases() throws IOException { - return root.retrieve().asPagedIterable(getApiTailUrl("releases"), GHRelease[].class, - item -> item.wrap(GHRepository.this)); + return root.retrieve() + .asPagedIterable(getApiTailUrl("releases"), GHRelease[].class, item -> item.wrap(GHRepository.this)); } /** @@ -516,8 +523,8 @@ public PagedIterable listReleases() throws IOException { * the io exception */ public PagedIterable listTags() throws IOException { - return root.retrieve().asPagedIterable(getApiTailUrl("tags"), GHTag[].class, - item -> item.wrap(GHRepository.this)); + return root.retrieve() + .asPagedIterable(getApiTailUrl("tags"), GHTag[].class, item -> item.wrap(GHRepository.this)); } /** @@ -802,8 +809,8 @@ public Set getCollaboratorNames() throws IOException { * the io exception */ public GHPermissionType getPermission(String user) throws IOException { - GHPermission perm = root.retrieve().to(getApiTailUrl("collaborators/" + user + "/permission"), - GHPermission.class); + GHPermission perm = root.retrieve() + .to(getApiTailUrl("collaborators/" + user + "/permission"), GHPermission.class); perm.wrapUp(root); return perm.getPermissionType(); } @@ -829,8 +836,9 @@ public GHPermissionType getPermission(GHUser u) throws IOException { * the io exception */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(new HashSet(Arrays.asList(GHTeam.wrapUp( - root.retrieve().to(getApiTailUrl("teams"), GHTeam[].class), root.getOrganization(getOwnerName()))))); + return Collections.unmodifiableSet(new HashSet( + Arrays.asList(GHTeam.wrapUp(root.retrieve().to(getApiTailUrl("teams"), GHTeam[].class), + root.getOrganization(getOwnerName()))))); } /** @@ -898,7 +906,10 @@ private void modifyCollaborators(Collection users, String method) throws public void setEmailServiceHook(String address) throws IOException { Map config = new HashMap(); config.put("address", address); - new Requester(root).method("POST").with("name", "email").with("config", config).with("active", true) + new Requester(root).method("POST") + .with("name", "email") + .with("config", config) + .with("active", true) .to(getApiTailUrl("hooks")); } @@ -1107,8 +1118,9 @@ public PagedIterable listForks() { * @return the paged iterable */ public PagedIterable listForks(final ForkSort sort) { - return root.retrieve().with("sort", sort).asPagedIterable(getApiTailUrl("forks"), GHRepository[].class, - item -> item.wrap(root)); + return root.retrieve() + .with("sort", sort) + .asPagedIterable(getApiTailUrl("forks"), GHRepository[].class, item -> item.wrap(root)); } /** @@ -1171,7 +1183,9 @@ public GHRepository forkTo(GHOrganization org) throws IOException { * the io exception */ public GHPullRequest getPullRequest(int i) throws IOException { - return root.retrieve().withPreview(SHADOW_CAT).to(getApiTailUrl("pulls/" + i), GHPullRequest.class) + return root.retrieve() + .withPreview(SHADOW_CAT) + .to(getApiTailUrl("pulls/" + i), GHPullRequest.class) .wrapUp(this); } @@ -1250,7 +1264,10 @@ public GHPullRequest createPullRequest(String title, String head, String base, S * @throws IOException * the io exception */ - public GHPullRequest createPullRequest(String title, String head, String base, String body, + public GHPullRequest createPullRequest(String title, + String head, + String base, + String body, boolean maintainerCanModify) throws IOException { return createPullRequest(title, head, base, body, maintainerCanModify, false); } @@ -1276,11 +1293,21 @@ public GHPullRequest createPullRequest(String title, String head, String base, S * @throws IOException * the io exception */ - public GHPullRequest createPullRequest(String title, String head, String base, String body, - boolean maintainerCanModify, boolean draft) throws IOException { - return new Requester(root).withPreview(SHADOW_CAT).with("title", title).with("head", head).with("base", base) - .with("body", body).with("maintainer_can_modify", maintainerCanModify).with("draft", draft) - .to(getApiTailUrl("pulls"), GHPullRequest.class).wrapUp(this); + public GHPullRequest createPullRequest(String title, + String head, + String base, + String body, + boolean maintainerCanModify, + boolean draft) throws IOException { + return new Requester(root).withPreview(SHADOW_CAT) + .with("title", title) + .with("head", head) + .with("base", base) + .with("body", body) + .with("maintainer_can_modify", maintainerCanModify) + .with("draft", draft) + .to(getApiTailUrl("pulls"), GHPullRequest.class) + .wrapUp(this); } /** @@ -1321,8 +1348,8 @@ public GHHook getHook(int id) throws IOException { * on failure communicating with GitHub */ public GHCompare getCompare(String id1, String id2) throws IOException { - GHCompare compare = root.retrieve().to(getApiTailUrl(String.format("compare/%s...%s", id1, id2)), - GHCompare.class); + GHCompare compare = root.retrieve() + .to(getApiTailUrl(String.format("compare/%s...%s", id1, id2)), GHCompare.class); return compare.wrap(this); } @@ -1381,7 +1408,8 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { */ public GHRef[] getRefs() throws IOException { return GHRef.wrap( - root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), root); + root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), + root); } /** @@ -1406,8 +1434,10 @@ public PagedIterable listRefs() throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef[] getRefs(String refType) throws IOException { - return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), - GHRef[].class), root); + return GHRef.wrap( + root.retrieve() + .to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class), + root); } /** @@ -1439,7 +1469,8 @@ public GHRef getRef(String refName) throws IOException { // URLEncoder.encode()? // OTOH, '/' need no escaping refName = refName.replaceAll("#", "%23"); - return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refName), GHRef.class) + return root.retrieve() + .to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refName), GHRef.class) .wrap(root); } @@ -1553,7 +1584,8 @@ public InputStream readBlob(String blobSha) throws IOException { public GHCommit getCommit(String sha1) throws IOException { GHCommit c = commits.get(sha1); if (c == null) { - c = root.retrieve().to(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1), GHCommit.class) + c = root.retrieve() + .to(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1), GHCommit.class) .wrapUp(this); commits.put(sha1, c); } @@ -1575,8 +1607,10 @@ public GHCommitBuilder createCommit() { * @return the paged iterable */ public PagedIterable listCommits() { - return root.retrieve().asPagedIterable(String.format("/repos/%s/%s/commits", getOwnerName(), name), - GHCommit[].class, item -> item.wrapUp(GHRepository.this)); + return root.retrieve() + .asPagedIterable(String.format("/repos/%s/%s/commits", getOwnerName(), name), + GHCommit[].class, + item -> item.wrapUp(GHRepository.this)); } /** @@ -1594,8 +1628,10 @@ public GHCommitQueryBuilder queryCommits() { * @return the paged iterable */ public PagedIterable listCommitComments() { - return root.retrieve().asPagedIterable(String.format("/repos/%s/%s/comments", getOwnerName(), name), - GHCommitComment[].class, item -> item.wrap(GHRepository.this)); + return root.retrieve() + .asPagedIterable(String.format("/repos/%s/%s/comments", getOwnerName(), name), + GHCommitComment[].class, + item -> item.wrap(GHRepository.this)); } /** @@ -1641,8 +1677,10 @@ private GHContentWithLicense getLicenseContent_() throws IOException { * the io exception */ public PagedIterable listCommitStatuses(final String sha1) throws IOException { - return root.retrieve().asPagedIterable(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1), - GHCommitStatus[].class, item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1), + GHCommitStatus[].class, + item -> item.wrapUp(root)); } /** @@ -1676,9 +1714,14 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException { * @throws IOException * the io exception */ - public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, + public GHCommitStatus createCommitStatus(String sha1, + GHCommitState state, + String targetUrl, + String description, String context) throws IOException { - return new Requester(root).with("state", state).with("target_url", targetUrl).with("description", description) + return new Requester(root).with("state", state) + .with("target_url", targetUrl) + .with("description", description) .with("context", context) .to(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1), GHCommitStatus.class) .wrapUp(root); @@ -1714,8 +1757,10 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin * the io exception */ public PagedIterable listEvents() throws IOException { - return root.retrieve().asPagedIterable(String.format("/repos/%s/%s/events", getOwnerName(), name), - GHEventInfo[].class, item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(String.format("/repos/%s/%s/events", getOwnerName(), name), + GHEventInfo[].class, + item -> item.wrapUp(root)); } /** @@ -1728,8 +1773,9 @@ public PagedIterable listEvents() throws IOException { * the io exception */ public PagedIterable listLabels() throws IOException { - return root.retrieve().withPreview(SYMMETRA).asPagedIterable(getApiTailUrl("labels"), GHLabel[].class, - item -> item.wrapUp(GHRepository.this)); + return root.retrieve() + .withPreview(SYMMETRA) + .asPagedIterable(getApiTailUrl("labels"), GHLabel[].class, item -> item.wrapUp(GHRepository.this)); } /** @@ -1776,8 +1822,14 @@ public GHLabel createLabel(String name, String color) throws IOException { @Preview @Deprecated public GHLabel createLabel(String name, String color, String description) throws IOException { - return root.retrieve().method("POST").withPreview(SYMMETRA).with("name", name).with("color", color) - .with("description", description).to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this); + return root.retrieve() + .method("POST") + .withPreview(SYMMETRA) + .with("name", name) + .with("color", color) + .with("description", description) + .to(getApiTailUrl("labels"), GHLabel.class) + .wrapUp(this); } /** @@ -1786,8 +1838,10 @@ public GHLabel createLabel(String name, String color, String description) throws * @return the paged iterable */ public PagedIterable listInvitations() { - return root.retrieve().asPagedIterable(String.format("/repos/%s/%s/invitations", getOwnerName(), name), - GHInvitation[].class, item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(String.format("/repos/%s/%s/invitations", getOwnerName(), name), + GHInvitation[].class, + item -> item.wrapUp(root)); } /** @@ -1818,8 +1872,11 @@ public PagedIterable listStargazers() { * @return the paged iterable */ public PagedIterable listStargazers2() { - return root.retrieve().withPreview("application/vnd.github.v3.star+json").asPagedIterable( - getApiTailUrl("stargazers"), GHStargazer[].class, item -> item.wrapUp(GHRepository.this)); + return root.retrieve() + .withPreview("application/vnd.github.v3.star+json") + .asPagedIterable(getApiTailUrl("stargazers"), + GHStargazer[].class, + item -> item.wrapUp(GHRepository.this)); } private PagedIterable listUsers(final String suffix) { @@ -1890,7 +1947,8 @@ public GHHook createWebHook(URL url) throws IOException { * @return the post commit hooks * @deprecated Use {@link #getHooks()} and {@link #createHook(String, Map, Collection, boolean)} */ - @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", justification = "It causes a performance degradation, but we have already exposed it to the API") + @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", + justification = "It causes a performance degradation, but we have already exposed it to the API") public Set getPostCommitHooks() { return postCommitHooks; } @@ -1898,7 +1956,8 @@ public Set getPostCommitHooks() { /** * Live set view of the post-commit hook. */ - @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", justification = "It causes a performance degradation, but we have already exposed it to the API") + @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", + justification = "It causes a performance degradation, but we have already exposed it to the API") @SkipFromToString private final Set postCommitHooks = new AbstractSet() { private List getPostCommitHooks() { @@ -2032,8 +2091,11 @@ public Map getMilestones() throws IOException { * @return the paged iterable */ public PagedIterable listMilestones(final GHIssueState state) { - return root.retrieve().with("state", state).asPagedIterable(getApiTailUrl("milestones"), GHMilestone[].class, - item -> item.wrap(GHRepository.this)); + return root.retrieve() + .with("state", state) + .asPagedIterable(getApiTailUrl("milestones"), + GHMilestone[].class, + item -> item.wrap(GHRepository.this)); } /** @@ -2237,8 +2299,11 @@ public GHContentUpdateResponse createContent(byte[] contentBytes, String commitM * the io exception */ public GHMilestone createMilestone(String title, String description) throws IOException { - return new Requester(root).with("title", title).with("description", description).method("POST") - .to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this); + return new Requester(root).with("title", title) + .with("description", description) + .method("POST") + .to(getApiTailUrl("milestones"), GHMilestone.class) + .wrap(this); } /** @@ -2253,8 +2318,11 @@ public GHMilestone createMilestone(String title, String description) throws IOEx * the io exception */ public GHDeployKey addDeployKey(String title, String key) throws IOException { - return new Requester(root).with("title", title).with("key", key).method("POST") - .to(getApiTailUrl("keys"), GHDeployKey.class).wrap(this); + return new Requester(root).with("title", title) + .with("key", key) + .method("POST") + .to(getApiTailUrl("keys"), GHDeployKey.class) + .wrap(this); } @@ -2320,8 +2388,11 @@ public GHRepository getParent() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return new Requester(root).with("subscribed", subscribed).with("ignored", ignored).method("PUT") - .to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this); + return new Requester(root).with("subscribed", subscribed) + .with("ignored", ignored) + .method("PUT") + .to(getApiTailUrl("subscription"), GHSubscription.class) + .wrapUp(this); } /** @@ -2347,8 +2418,8 @@ public GHSubscription getSubscription() throws IOException { * the io exception */ public PagedIterable listContributors() throws IOException { - return root.retrieve().asPagedIterable(getApiTailUrl("contributors"), Contributor[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(getApiTailUrl("contributors"), Contributor[].class, item -> item.wrapUp(root)); } /** @@ -2402,8 +2473,13 @@ public GHRepositoryStatistics getStatistics() { * the io exception */ public GHProject createProject(String name, String body) throws IOException { - return root.retrieve().method("POST").withPreview(INERTIA).with("name", name).with("body", body) - .to(getApiTailUrl("projects"), GHProject.class).wrap(this); + return root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with("name", name) + .with("body", body) + .to(getApiTailUrl("projects"), GHProject.class) + .wrap(this); } /** @@ -2416,8 +2492,10 @@ public GHProject createProject(String name, String body) throws IOException { * the io exception */ public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { - return root.retrieve().withPreview(INERTIA).with("state", status).asPagedIterable(getApiTailUrl("projects"), - GHProject[].class, item -> item.wrap(GHRepository.this)); + return root.retrieve() + .withPreview(INERTIA) + .with("state", status) + .asPagedIterable(getApiTailUrl("projects"), GHProject[].class, item -> item.wrap(GHRepository.this)); } /** @@ -2446,10 +2524,10 @@ public PagedIterable listProjects() throws IOException { * @see GitHub#renderMarkdown(String) GitHub#renderMarkdown(String) */ public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException { - return new InputStreamReader( - new Requester(root).with("text", text).with("mode", mode == null ? null : mode.toString()) - .with("context", getFullName()).asStream("/markdown"), - "UTF-8"); + return new InputStreamReader(new Requester(root).with("text", text) + .with("mode", mode == null ? null : mode.toString()) + .with("context", getFullName()) + .asStream("/markdown"), "UTF-8"); } /** @@ -2514,8 +2592,8 @@ String getApiTailUrl(String tail) { * the io exception */ public PagedIterable listIssueEvents() throws IOException { - return root.retrieve().asPagedIterable(getApiTailUrl("issues/events"), GHIssueEvent[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(getApiTailUrl("issues/events"), GHIssueEvent[].class, item -> item.wrapUp(root)); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 41f43ec4f7..6edeb733cf 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -86,15 +86,17 @@ public PagedIterable getContributorStats(boolean waitTillReady * This gets the actual statistics from the server. Returns null if they are still being cached. */ private PagedIterable getContributorStatsImpl() throws IOException { - return root.retrieve().asPagedIterable(getApiTailUrl("contributors"), ContributorStats[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(getApiTailUrl("contributors"), ContributorStats[].class, item -> item.wrapUp(root)); } /** * The type ContributorStats. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "URF_UNREAD_FIELD" }, + justification = "JSON API") public static class ContributorStats extends GHObject { /* package almost final */ private GitHub root; private GHUser author; @@ -172,8 +174,10 @@ public String toString() { /** * The type Week. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", + "URF_UNREAD_FIELD" }, + justification = "JSON API") public static class Week { private long w; @@ -238,15 +242,16 @@ ContributorStats wrapUp(GitHub root) { * the io exception */ public PagedIterable getCommitActivity() throws IOException { - return root.retrieve().asPagedIterable(getApiTailUrl("commit_activity"), CommitActivity[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(getApiTailUrl("commit_activity"), CommitActivity[].class, item -> item.wrapUp(root)); } /** * The type CommitActivity. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") + @SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public static class CommitActivity extends GHObject { /* package almost final */ private GitHub root; private List days; diff --git a/src/main/java/org/kohsuke/github/GHTag.java b/src/main/java/org/kohsuke/github/GHTag.java index 8281af2eaf..3832199253 100644 --- a/src/main/java/org/kohsuke/github/GHTag.java +++ b/src/main/java/org/kohsuke/github/GHTag.java @@ -7,8 +7,8 @@ * * @see GHRepository#listTags() GHRepository#listTags() */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GHTag { private GHRepository owner; private GitHub root; diff --git a/src/main/java/org/kohsuke/github/GHTagObject.java b/src/main/java/org/kohsuke/github/GHTagObject.java index e880e8e47c..4c0234e202 100644 --- a/src/main/java/org/kohsuke/github/GHTagObject.java +++ b/src/main/java/org/kohsuke/github/GHTagObject.java @@ -7,8 +7,8 @@ * * @see GHRepository#getTagObject(String) GHRepository#getTagObject(String) */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GHTagObject { private GHRepository owner; private GitHub root; diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 9e3c0612c5..9254817b91 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -243,7 +243,9 @@ public void add(GHRepository r) throws IOException { * the io exception */ public void add(GHRepository r, GHOrganization.Permission permission) throws IOException { - root.retrieve().method("PUT").with("permission", permission) + root.retrieve() + .method("PUT") + .with("permission", permission) .to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null); } diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 240c4084f6..52b942512b 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -14,8 +14,8 @@ * @see documentation * @see GHNotificationStream */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GHThread extends GHObject { private GitHub root; private GHRepository repository; @@ -176,8 +176,11 @@ public void markAsRead() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return new Requester(root).with("subscribed", subscribed).with("ignored", ignored).method("PUT") - .to(subscription_url, GHSubscription.class).wrapUp(root); + return new Requester(root).with("subscribed", subscribed) + .with("ignored", ignored) + .method("PUT") + .to(subscription_url, GHSubscription.class) + .wrapUp(root); } /** diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 332721be5c..73cdfea9bd 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -197,8 +197,10 @@ public GHPersonSet getOrganizations() throws IOException { * Lists events performed by a user (this includes private events if the caller is authenticated. */ public PagedIterable listEvents() throws IOException { - return root.retrieve().asPagedIterable(String.format("/users/%s/events", login), GHEventInfo[].class, - item -> item.wrapUp(root)); + return root.retrieve() + .asPagedIterable(String.format("/users/%s/events", login), + GHEventInfo[].class, + item -> item.wrapUp(root)); } /** @@ -209,8 +211,10 @@ public PagedIterable listEvents() throws IOException { * the io exception */ public PagedIterable listGists() throws IOException { - return root.retrieve().asPagedIterable(String.format("/users/%s/gists", login), GHGist[].class, - item -> item.wrapUp(GHUser.this)); + return root.retrieve() + .asPagedIterable(String.format("/users/%s/gists", login), + GHGist[].class, + item -> item.wrapUp(GHUser.this)); } @Override diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 78b9885c0e..a6918e4b63 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -128,9 +128,14 @@ public class GitHub { * @param connector * HttpConnector to use. Pass null to use default connector. */ - GitHub(String apiUrl, String login, String oauthAccessToken, String jwtToken, String password, - HttpConnector connector, RateLimitHandler rateLimitHandler, AbuseLimitHandler abuseLimitHandler) - throws IOException { + GitHub(String apiUrl, + String login, + String oauthAccessToken, + String jwtToken, + String password, + HttpConnector connector, + RateLimitHandler rateLimitHandler, + AbuseLimitHandler abuseLimitHandler) throws IOException { if (apiUrl.endsWith("/")) apiUrl = apiUrl.substring(0, apiUrl.length() - 1); // normalize this.apiUrl = apiUrl; @@ -345,7 +350,8 @@ public static GitHub connectToEnterpriseAnonymously(String apiUrl) throws IOExce */ public static GitHub offline() { try { - return new GitHubBuilder().withEndpoint("https://api.github.invalid").withConnector(HttpConnector.OFFLINE) + return new GitHubBuilder().withEndpoint("https://api.github.invalid") + .withConnector(HttpConnector.OFFLINE) .build(); } catch (IOException e) { throw new IllegalStateException("The offline implementation constructor should not connect", e); @@ -624,8 +630,8 @@ public PagedIterable listOrganizations() { * @see List All Orgs - Parameters */ public PagedIterable listOrganizations(final String since) { - return retrieve().with("since", since).asPagedIterable("/organizations", GHOrganization[].class, - item -> item.wrapUp(GitHub.this)); + return retrieve().with("since", since) + .asPagedIterable("/organizations", GHOrganization[].class, item -> item.wrapUp(GitHub.this)); } /** @@ -949,8 +955,9 @@ public GHAuthorization createToken(Collection scope, String note, String return createToken(scope, note, noteUrl); } catch (GHOTPRequiredException ex) { String OTPstring = OTP.get(); - Requester requester = new Requester(this).with("scopes", scope).with("note", note).with("note_url", - noteUrl); + Requester requester = new Requester(this).with("scopes", scope) + .with("note", note) + .with("note_url", noteUrl); // Add the OTP from the user requester.setHeader("x-github-otp", OTPstring); return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); @@ -976,10 +983,15 @@ public GHAuthorization createToken(Collection scope, String note, String * @see docs */ - public GHAuthorization createOrGetAuth(String clientId, String clientSecret, List scopes, String note, + public GHAuthorization createOrGetAuth(String clientId, + String clientSecret, + List scopes, + String note, String note_url) throws IOException { - Requester requester = new Requester(this).with("client_secret", clientSecret).with("scopes", scopes) - .with("note", note).with("note_url", note_url); + Requester requester = new Requester(this).with("client_secret", clientSecret) + .with("scopes", scopes) + .with("note", note) + .with("note_url", note_url); return requester.method("PUT").to("/authorizations/clients/" + clientId, GHAuthorization.class); } @@ -1029,8 +1041,8 @@ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String acces * authorization */ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { - return retrieve().method("POST").to("/applications/" + clientId + "/tokens/" + accessToken, - GHAuthorization.class); + return retrieve().method("POST") + .to("/applications/" + clientId + "/tokens/" + accessToken, GHAuthorization.class); } /** @@ -1306,8 +1318,8 @@ public PagedIterable listAllPublicRepositories() { * @see documentation */ public PagedIterable listAllPublicRepositories(final String since) { - return retrieve().with("since", since).asPagedIterable("/repositories", GHRepository[].class, - item -> item.wrap(GitHub.this)); + return retrieve().with("since", since) + .asPagedIterable("/repositories", GHRepository[].class, item -> item.wrap(GitHub.this)); } /** @@ -1326,7 +1338,8 @@ public PagedIterable listAllPublicRepositories(final String since) */ public Reader renderMarkdown(String text) throws IOException { return new InputStreamReader(new Requester(this).with(new ByteArrayInputStream(text.getBytes("UTF-8"))) - .contentType("text/plain;charset=UTF-8").asStream("/markdown/raw"), "UTF-8"); + .contentType("text/plain;charset=UTF-8") + .asStream("/markdown/raw"), "UTF-8"); } static URL parseURL(String s) { diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index 3fe8cb7ec1..63f0877d9e 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -90,7 +90,8 @@ static GitHubBuilder fromCredentials() throws IOException { * @deprecated Use {@link #fromEnvironment()} to pick up standard set of environment variables, so that different * clients of this library will all recognize one consistent set of coordinates. */ - public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, + public static GitHubBuilder fromEnvironment(String loginVariableName, + String passwordVariableName, String oauthVariableName) throws IOException { return fromEnvironment(loginVariableName, passwordVariableName, oauthVariableName, ""); } @@ -118,8 +119,10 @@ private static void loadIfSet(String envName, Properties p, String propName) { * @deprecated Use {@link #fromEnvironment()} to pick up standard set of environment variables, so that different * clients of this library will all recognize one consistent set of coordinates. */ - public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, - String oauthVariableName, String endpointVariableName) throws IOException { + public static GitHubBuilder fromEnvironment(String loginVariableName, + String passwordVariableName, + String oauthVariableName, + String endpointVariableName) throws IOException { Properties env = new Properties(); loadIfSet(loginVariableName, env, "login"); loadIfSet(passwordVariableName, env, "password"); @@ -355,7 +358,13 @@ public HttpURLConnection connect(URL url) throws IOException { * the io exception */ public GitHub build() throws IOException { - return new GitHub(endpoint, user, oauthToken, jwtToken, password, connector, rateLimitHandler, + return new GitHub(endpoint, + user, + oauthToken, + jwtToken, + password, + connector, + rateLimitHandler, abuseLimitHandler); } diff --git a/src/main/java/org/kohsuke/github/GitUser.java b/src/main/java/org/kohsuke/github/GitUser.java index 8c32ae6ded..6a887b5802 100644 --- a/src/main/java/org/kohsuke/github/GitUser.java +++ b/src/main/java/org/kohsuke/github/GitUser.java @@ -12,8 +12,8 @@ * * @author Kohsuke Kawaguchi */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "NP_UNWRITTEN_FIELD" }, justification = "JSON API") +@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, + justification = "JSON API") public class GitUser { private String name, email, date; diff --git a/src/main/java/org/kohsuke/github/PagedSearchIterable.java b/src/main/java/org/kohsuke/github/PagedSearchIterable.java index d79b743320..4e3b846508 100644 --- a/src/main/java/org/kohsuke/github/PagedSearchIterable.java +++ b/src/main/java/org/kohsuke/github/PagedSearchIterable.java @@ -11,8 +11,10 @@ * the type parameter * @author Kohsuke Kawaguchi */ -@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", - "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "Constructed by JSON API") +@SuppressFBWarnings( + value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", + "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, + justification = "Constructed by JSON API") public abstract class PagedSearchIterable extends PagedIterable { private final GitHub root; diff --git a/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java b/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java index 39fca925da..3c453ed119 100644 --- a/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java +++ b/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java @@ -263,7 +263,8 @@ static String responseSourceHeader(Response response) { if (networkResponse == null) { return response.cacheResponse() == null ? "NONE" : "CACHE " + response.code(); } else { - return response.cacheResponse() == null ? "NETWORK " + response.code() + return response.cacheResponse() == null + ? "NETWORK " + response.code() : "CONDITIONAL_CACHE " + networkResponse.code(); } } @@ -414,8 +415,10 @@ Headers getHeaders() throws IOException { if (responseHeaders == null) { Response response = getResponse(true); Headers headers = response.headers(); - responseHeaders = headers.newBuilder().add(SELECTED_PROTOCOL, response.protocol().toString()) - .add(RESPONSE_SOURCE, responseSourceHeader(response)).build(); + responseHeaders = headers.newBuilder() + .add(SELECTED_PROTOCOL, response.protocol().toString()) + .add(RESPONSE_SOURCE, responseSourceHeader(response)) + .build(); } return responseHeaders; } @@ -471,7 +474,8 @@ public Map> getRequestProperties() { return toMultimap(requestHeaders.build(), null); } - @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Good request will have body") + @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", + justification = "Good request will have body") @Override public InputStream getInputStream() throws IOException { if (!doInput) { @@ -503,7 +507,8 @@ public OutputStream getOutputStream() throws IOException { return requestBody.outputStream; } - @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "usingProxy() handles this") + @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", + justification = "usingProxy() handles this") @Override public Permission getPermission() { URL url = getURL(); @@ -604,7 +609,9 @@ private Call buildCall() throws IOException { throw malformedUrl; } - Request request = new Request.Builder().url(url).headers(requestHeaders.build()).method(method, requestBody) + Request request = new Request.Builder().url(url) + .headers(requestHeaders.build()) + .method(method, requestBody) .build(); OkHttpClient.Builder clientBuilder = client.newBuilder(); @@ -787,7 +794,8 @@ public void proceed() { } } - @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "If we get here there is a connection and request.body() is checked") + @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", + justification = "If we get here there is a connection and request.body() is checked") @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); @@ -843,7 +851,7 @@ void initOutputStream(BufferedSink sink, long expectedContentLength) { @Override public void write(int b) throws IOException { - write(new byte[] { (byte) b }, 0, 1); + write(new byte[]{ (byte) b }, 0, 1); } @Override @@ -929,8 +937,10 @@ public Request prepareToSendRequest(Request request) throws IOException { outputStream.close(); contentLength = buffer.size(); - return request.newBuilder().removeHeader("Transfer-Encoding") - .header("Content-Length", Long.toString(buffer.size())).build(); + return request.newBuilder() + .removeHeader("Transfer-Encoding") + .header("Content-Length", Long.toString(buffer.size())) + .build(); } @Override diff --git a/src/main/resources/eclipse/formatter.xml b/src/main/resources/eclipse/formatter.xml index 976c8fe99b..2e5dcc607f 100644 --- a/src/main/resources/eclipse/formatter.xml +++ b/src/main/resources/eclipse/formatter.xml @@ -1,5 +1,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java index 39abf6a36d..966057c8ec 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java @@ -165,9 +165,12 @@ protected GHRepository getTempRepository(String name) throws IOException { if (mockGitHub.isUseProxy()) { cleanupRepository(fullName); - GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).createRepository(name) + GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG) + .createRepository(name) .description("A test repository for testing the github-api project: " + name) - .homepage("http://github-api.kohsuke.org/").autoInit(true).create(); + .homepage("http://github-api.kohsuke.org/") + .autoInit(true) + .create(); try { Thread.sleep(3000); } catch (InterruptedException e) { diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 6fba815f70..64edd87280 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -34,8 +34,10 @@ public void testRepoCRUD() throws Exception { cleanupUserRepository("github-api-test-rename"); cleanupUserRepository(targetName); - GHRepository r = gitHub.createRepository("github-api-test-rename", "a test repository", - "http://github-api.kohsuke.org/", true); + GHRepository r = gitHub.createRepository("github-api-test-rename", + "a test repository", + "http://github-api.kohsuke.org/", + true); assertThat(r.hasIssues(), is(true)); r.enableIssueTracker(false); @@ -49,8 +51,11 @@ public void testRepoCRUD() throws Exception { public void testRepositoryWithAutoInitializationCRUD() throws Exception { String name = "github-api-test-autoinit"; cleanupUserRepository(name); - GHRepository r = gitHub.createRepository(name).description("a test repository for auto init") - .homepage("http://github-api.kohsuke.org/").autoInit(true).create(); + GHRepository r = gitHub.createRepository(name) + .description("a test repository for auto init") + .homepage("http://github-api.kohsuke.org/") + .autoInit(true) + .create(); r.enableIssueTracker(false); r.enableDownloads(false); r.enableWiki(false); @@ -91,8 +96,13 @@ public void testCreateIssue() throws IOException { GHUser u = getUser(); GHRepository repository = getTestRepository(); GHMilestone milestone = repository.createMilestone("Test Milestone Title3", "Test Milestone"); - GHIssue o = repository.createIssue("testing").body("this is body").assignee(u).label("bug").label("question") - .milestone(milestone).create(); + GHIssue o = repository.createIssue("testing") + .body("this is body") + .assignee(u) + .label("bug") + .label("question") + .milestone(milestone) + .create(); assertNotNull(o); o.close(); } @@ -101,7 +111,9 @@ public void testCreateIssue() throws IOException { public void testCreateAndListDeployments() throws IOException { GHRepository repository = getTestRepository(); GHDeployment deployment = repository.createDeployment("master") - .payload("{\"user\":\"atmos\",\"room_id\":123456}").description("question").environment("unittest") + .payload("{\"user\":\"atmos\",\"room_id\":123456}") + .description("question") + .environment("unittest") .create(); assertNotNull(deployment.getCreator()); assertNotNull(deployment.getId()); @@ -117,10 +129,14 @@ public void testCreateAndListDeployments() throws IOException { @Test public void testGetDeploymentStatuses() throws IOException { GHRepository repository = getTestRepository(); - GHDeployment deployment = repository.createDeployment("master").description("question") - .payload("{\"user\":\"atmos\",\"room_id\":123456}").create(); + GHDeployment deployment = repository.createDeployment("master") + .description("question") + .payload("{\"user\":\"atmos\",\"room_id\":123456}") + .create(); GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.SUCCESS) - .description("success").targetUrl("http://www.github.com").create(); + .description("success") + .targetUrl("http://www.github.com") + .create(); Iterable deploymentStatuses = deployment.listStatuses(); assertNotNull(deploymentStatuses); assertEquals(1, Iterables.size(deploymentStatuses)); @@ -129,7 +145,8 @@ public void testGetDeploymentStatuses() throws IOException { @Test public void testGetIssues() throws Exception { - List closedIssues = gitHub.getOrganization("github-api").getRepository("github-api") + List closedIssues = gitHub.getOrganization("github-api") + .getRepository("github-api") .getIssues(GHIssueState.CLOSED); // prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues assertTrue(closedIssues.size() > 150); @@ -150,11 +167,20 @@ public void testListIssues() throws IOException { GHIssue unhomed = null; GHIssue homed = null; try { - unhomed = repository.createIssue("testing").body("this is body").assignee(u).label("bug").label("question") + unhomed = repository.createIssue("testing") + .body("this is body") + .assignee(u) + .label("bug") + .label("question") .create(); assertEquals(unhomed.getNumber(), repository.getIssues(GHIssueState.OPEN, null).get(0).getNumber()); - homed = repository.createIssue("testing").body("this is body").assignee(u).label("bug").label("question") - .milestone(milestone).create(); + homed = repository.createIssue("testing") + .body("this is body") + .assignee(u) + .label("bug") + .label("question") + .milestone(milestone) + .create(); assertEquals(homed.getNumber(), repository.getIssues(GHIssueState.OPEN, milestone).get(0).getNumber()); } finally { if (unhomed != null) { @@ -306,7 +332,8 @@ public void testGetTeamsForRepo() throws Exception { @Test public void testMembership() throws Exception { - Set members = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("jenkins") + Set members = gitHub.getOrganization(GITHUB_API_TEST_ORG) + .getRepository("jenkins") .getCollaboratorNames(); // System.out.println(members.contains("kohsuke")); } @@ -344,7 +371,8 @@ public void testOrgTeamBySlug() throws Exception { @Test public void testCommit() throws Exception { - GHCommit commit = gitHub.getUser("jenkinsci").getRepository("jenkins") + GHCommit commit = gitHub.getUser("jenkinsci") + .getRepository("jenkins") .getCommit("08c1c9970af4d609ae754fbe803e06186e3206f7"); assertEquals(1, commit.getParents().size()); assertEquals(1, commit.getFiles().size()); @@ -374,8 +402,13 @@ public void testListCommits() throws Exception { public void testQueryCommits() throws Exception { List sha1 = new ArrayList(); - for (GHCommit c : gitHub.getUser("jenkinsci").getRepository("jenkins").queryCommits() - .since(new Date(1199174400000L)).until(1201852800000L).path("pom.xml").list()) { + for (GHCommit c : gitHub.getUser("jenkinsci") + .getRepository("jenkins") + .queryCommits() + .since(new Date(1199174400000L)) + .until(1201852800000L) + .path("pom.xml") + .list()) { // System.out.println(c.getSHA1()); sha1.add(c.getSHA1()); } @@ -403,7 +436,8 @@ public void testCommitComment() throws Exception { @Test public void testCreateCommitComment() throws Exception { - GHCommit commit = gitHub.getUser("kohsuke").getRepository("sandbox-ant") + GHCommit commit = gitHub.getUser("kohsuke") + .getRepository("sandbox-ant") .getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000"); GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)"); // System.out.println(c); @@ -679,8 +713,8 @@ public boolean apply(GHDeployKey deployKey) { public void testCommitStatusContext() throws IOException { GHRepository myRepository = getTestRepository(); GHRef masterRef = myRepository.getRef("heads/master"); - GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), - GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context"); + GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject() + .getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context"); assertEquals("test/context", commitStatus.getContext()); } diff --git a/src/test/java/org/kohsuke/github/GHRateLimitTest.java b/src/test/java/org/kohsuke/github/GHRateLimitTest.java index 9ad89e7cbe..bf7e49f1a3 100644 --- a/src/test/java/org/kohsuke/github/GHRateLimitTest.java +++ b/src/test/java/org/kohsuke/github/GHRateLimitTest.java @@ -336,15 +336,18 @@ private void executeExpirationTest() throws Exception { rateLimit = gitHub.rateLimit(); assertThat(rateLimit, notNullValue()); - assertThat("rateLimit() selects header instance when not expired, does not ask server", rateLimit, + assertThat("rateLimit() selects header instance when not expired, does not ask server", + rateLimit, sameInstance(headerRateLimit)); // Nothing changes still valid Thread.sleep(1000); - assertThat("rateLimit() selects header instance when not expired, does not ask server", gitHub.rateLimit(), + assertThat("rateLimit() selects header instance when not expired, does not ask server", + gitHub.rateLimit(), sameInstance(headerRateLimit)); - assertThat("rateLimit() selects header instance when not expired, does not ask server", gitHub.lastRateLimit(), + assertThat("rateLimit() selects header instance when not expired, does not ask server", + gitHub.lastRateLimit(), sameInstance(headerRateLimit)); assertThat(mockGitHub.getRequestCount(), equalTo(1)); @@ -355,12 +358,15 @@ private void executeExpirationTest() throws Exception { assertThat("Header instance has expired", gitHub.lastRateLimit().isExpired(), is(true)); assertThat("rateLimit() will ask server when header instance expires and it has not called getRateLimit() yet", - gitHub.rateLimit(), not(sameInstance(rateLimit))); + gitHub.rateLimit(), + not(sameInstance(rateLimit))); assertThat("lastRateLimit() (header instance) is populated as part of internal call to getRateLimit()", - gitHub.lastRateLimit(), not(sameInstance(rateLimit))); + gitHub.lastRateLimit(), + not(sameInstance(rateLimit))); - assertThat("After request, rateLimit() selects header instance since it has been refreshed", gitHub.rateLimit(), + assertThat("After request, rateLimit() selects header instance since it has been refreshed", + gitHub.rateLimit(), sameInstance(gitHub.lastRateLimit())); headerRateLimit = gitHub.lastRateLimit(); @@ -375,10 +381,12 @@ private void executeExpirationTest() throws Exception { // Using custom data to have a header instance that expires before the queried instance assertThat( "if header instance expires but queried instance is valid, ratelimit() uses it without asking server", - gitHub.rateLimit(), not(sameInstance(gitHub.lastRateLimit()))); + gitHub.rateLimit(), + not(sameInstance(gitHub.lastRateLimit()))); assertThat("ratelimit() should almost never return a return a GHRateLimit that is already expired", - gitHub.rateLimit().isExpired(), is(false)); + gitHub.rateLimit().isExpired(), + is(false)); assertThat("Header instance hasn't been reloaded", gitHub.lastRateLimit(), sameInstance(headerRateLimit)); assertThat("Header instance has expired", gitHub.lastRateLimit().isExpired(), is(true)); @@ -390,12 +398,15 @@ private void executeExpirationTest() throws Exception { headerRateLimit = gitHub.rateLimit(); - assertThat("rateLimit() has asked server for new information", gitHub.rateLimit(), + assertThat("rateLimit() has asked server for new information", + gitHub.rateLimit(), not(sameInstance(rateLimit))); - assertThat("rateLimit() has asked server for new information", gitHub.lastRateLimit(), + assertThat("rateLimit() has asked server for new information", + gitHub.lastRateLimit(), not(sameInstance(rateLimit))); - assertThat("rateLimit() selects header instance when not expired, does not ask server", gitHub.rateLimit(), + assertThat("rateLimit() selects header instance when not expired, does not ask server", + gitHub.rateLimit(), sameInstance((gitHub.lastRateLimit()))); assertThat(mockGitHub.getRequestCount(), equalTo(3)); diff --git a/src/test/java/org/kohsuke/github/GistTest.java b/src/test/java/org/kohsuke/github/GistTest.java index b2987f4f13..ed11bc5284 100644 --- a/src/test/java/org/kohsuke/github/GistTest.java +++ b/src/test/java/org/kohsuke/github/GistTest.java @@ -15,8 +15,12 @@ public class GistTest extends AbstractGitHubWireMockTest { @Test public void lifecycleTest() throws Exception { // CRUD operation - GHGist gist = gitHub.createGist().public_(false).description("Test Gist").file("abc.txt", "abc") - .file("def.txt", "def").create(); + GHGist gist = gitHub.createGist() + .public_(false) + .description("Test Gist") + .file("abc.txt", "abc") + .file("def.txt", "def") + .create(); assertThat(gist.getCreatedAt(), is(notNullValue())); diff --git a/src/test/java/org/kohsuke/github/GitHubConnectionTest.java b/src/test/java/org/kohsuke/github/GitHubConnectionTest.java index 6f5c7b7159..5e244da3bf 100644 --- a/src/test/java/org/kohsuke/github/GitHubConnectionTest.java +++ b/src/test/java/org/kohsuke/github/GitHubConnectionTest.java @@ -78,8 +78,8 @@ public void testGitHubBuilderFromCustomEnvironment() throws IOException { setupEnvironment(props); - GitHubBuilder builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", - "customEndpoint"); + GitHubBuilder builder = GitHubBuilder + .fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint"); assertEquals("bogusLogin", builder.user); assertEquals("bogusOauth", builder.oauthToken); diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 101b04646b..83bed2f043 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -98,7 +98,8 @@ public void testGitHubRateLimitShouldReplaceRateLimit() throws Exception { assertThat("Unknown should not replace worst record", GitHub.shouldReplace(unknown1, recordWorst), is(false)); assertThat("Earlier record should replace later worst", GitHub.shouldReplace(record0, recordWorst), is(true)); - assertThat("Later worst record should not replace earlier", GitHub.shouldReplace(recordWorst, record0), + assertThat("Later worst record should not replace earlier", + GitHub.shouldReplace(recordWorst, record0), is(false)); assertThat("Equivalent record should not replace", GitHub.shouldReplace(record0, record00), is(false)); @@ -109,14 +110,17 @@ public void testGitHubRateLimitShouldReplaceRateLimit() throws Exception { assertThat("Higher limit record should not replace lower", GitHub.shouldReplace(record1, record2), is(false)); - assertThat("Higher limit record with later reset should replace lower", GitHub.shouldReplace(record3, record2), + assertThat("Higher limit record with later reset should replace lower", + GitHub.shouldReplace(record3, record2), is(true)); - assertThat("Lower limit record with later reset should replace higher", GitHub.shouldReplace(record4, record1), + assertThat("Lower limit record with later reset should replace higher", + GitHub.shouldReplace(record4, record1), is(true)); assertThat("Lower limit record with earlier reset should not replace higher", - GitHub.shouldReplace(record2, record4), is(false)); + GitHub.shouldReplace(record2, record4), + is(false)); } diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 81cfeba27b..f89d1faa5c 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -56,8 +56,12 @@ public void testListAllRepositories() throws Exception { @Test public void searchContent() throws Exception { - PagedSearchIterable r = gitHub.searchContent().q("addClass").in("file").language("js") - .repo("jquery/jquery").list(); + PagedSearchIterable r = gitHub.searchContent() + .q("addClass") + .in("file") + .language("js") + .repo("jquery/jquery") + .list(); GHContent c = r.iterator().next(); // System.out.println(c.getName()); assertNotNull(c.getDownloadUrl()); @@ -87,13 +91,13 @@ public void getMeta() throws IOException { assertEquals(19, meta.getWeb().size()); // Also test examples here - Class[] examples = new Class[] { ReadOnlyObjects.GHMetaPublic.class, ReadOnlyObjects.GHMetaPackage.class, + Class[] examples = new Class[]{ ReadOnlyObjects.GHMetaPublic.class, ReadOnlyObjects.GHMetaPackage.class, ReadOnlyObjects.GHMetaGettersUnmodifiable.class, ReadOnlyObjects.GHMetaGettersFinal.class, ReadOnlyObjects.GHMetaGettersFinalCreator.class, }; for (Class metaClass : examples) { - ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve().to("/meta", - (Class) metaClass); + ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve() + .to("/meta", (Class) metaClass); assertTrue(metaExample.isVerifiablePasswordAuthentication()); assertEquals(19, metaExample.getApi().size()); assertEquals(19, metaExample.getGit().size()); diff --git a/src/test/java/org/kohsuke/github/Github2faTest.java b/src/test/java/org/kohsuke/github/Github2faTest.java index fe20355b19..7681a50680 100644 --- a/src/test/java/org/kohsuke/github/Github2faTest.java +++ b/src/test/java/org/kohsuke/github/Github2faTest.java @@ -15,13 +15,13 @@ public class Github2faTest extends AbstractGitHubWireMockTest { public void test2faToken() throws IOException { assertFalse("Test only valid when not proxying", mockGitHub.isUseProxy()); - List asList = Arrays.asList("repo", "gist", "write:packages", "read:packages", "delete:packages", - "user", "delete_repo"); + List asList = Arrays + .asList("repo", "gist", "write:packages", "read:packages", "delete:packages", "user", "delete_repo"); String nameOfToken = "Test2faTokenCreate";// +timestamp;// use time stamp to ensure the token creations do not // collide with older tokens - GHAuthorization token = gitHub.createToken(asList, nameOfToken, "this is a test token created by a unit test", - () -> { + GHAuthorization token = gitHub + .createToken(asList, nameOfToken, "this is a test token created by a unit test", () -> { String data = "111878"; // TO UPDATE run this in debugger mode, put a breakpoint here, and enter the OTP you get into the // value of Data diff --git a/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java b/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java index d0eac990d0..c9bdda95ec 100644 --- a/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java +++ b/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java @@ -104,7 +104,8 @@ public void OkHttpConnector_NoCache() throws Exception { OkHttpClient client = createClient(false); OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client)); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -129,7 +130,8 @@ public void OkHttpConnector_Cache_MaxAgeNone() throws Exception { OkHttpClient client = createClient(true); OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client), -1); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -159,7 +161,8 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception { OkHttpClient client = createClient(true); OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client), 3); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -184,7 +187,8 @@ public void OkHttpConnector_Cache_MaxAgeDefault_Zero() throws Exception { OkHttpClient client = createClient(true); OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client)); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -204,7 +208,8 @@ private void checkRequestAndLimit(int networkRequestCount, int rateLimitUsed) th assertThat("Request Count", mockGitHub.getRequestCount(), is(networkRequestCount + userRequestCount)); // Rate limit must be under this value, but if it wiggles we don't care - assertThat("Rate Limit Change", rateLimitBefore.remaining - rateLimitAfter.remaining, + assertThat("Rate Limit Change", + rateLimitBefore.remaining - rateLimitAfter.remaining, is(lessThanOrEqualTo(rateLimitUsed + userRequestCount))); }