diff --git a/src/main/java/org/kohsuke/github/AbstractBuilder.java b/src/main/java/org/kohsuke/github/AbstractBuilder.java index 8a581270e6..29b26da5bf 100644 --- a/src/main/java/org/kohsuke/github/AbstractBuilder.java +++ b/src/main/java/org/kohsuke/github/AbstractBuilder.java @@ -100,7 +100,7 @@ protected AbstractBuilder(@Nonnull Class finalReturnType, @Override @Nonnull @BetaApi - public R done() throws IOException { + public R done() { R result; if (updateInPlace && baseInstance != null) { result = requester.fetchInto(baseInstance); @@ -129,7 +129,7 @@ public R done() throws IOException { */ @Nonnull @BetaApi - protected S with(@Nonnull String name, Object value) throws IOException { + protected S with(@Nonnull String name, Object value) { requester.with(name, value); return continueOrDone(); } @@ -149,7 +149,7 @@ protected S with(@Nonnull String name, Object value) throws IOException { */ @Nonnull @BetaApi - protected S continueOrDone() throws IOException { + protected S continueOrDone() { // This little bit of roughness in this base class means all inheriting builders get to create Updater and // Setter classes from almost identical code. Creator can often be implemented with significant code reuse as // well. diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index fd1db5c609..789fe49368 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -162,7 +162,7 @@ public PagedIterable listInstallations(final Date since) { * on error * @see Get an installation */ - public GHAppInstallation getInstallationById(long id) throws IOException { + public GHAppInstallation getInstallationById(long id) { return root().createRequest() .withUrlPath(String.format("/app/installations/%d", id)) .fetch(GHAppInstallation.class); @@ -181,7 +181,7 @@ public GHAppInstallation getInstallationById(long id) throws IOException { * @see Get an organization * installation */ - public GHAppInstallation getInstallationByOrganization(String name) throws IOException { + public GHAppInstallation getInstallationByOrganization(String name) { return root().createRequest() .withUrlPath(String.format("/orgs/%s/installation", name)) .fetch(GHAppInstallation.class); @@ -202,7 +202,7 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc * @see Get a repository * installation */ - public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { + public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) { return root().createRequest() .withUrlPath(String.format("/repos/%s/%s/installation", ownerName, repositoryName)) .fetch(GHAppInstallation.class); @@ -220,7 +220,7 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re * on error * @see Get a user installation */ - public GHAppInstallation getInstallationByUser(String name) throws IOException { + public GHAppInstallation getInstallationByUser(String name) { return root().createRequest() .withUrlPath(String.format("/users/%s/installation", name)) .fetch(GHAppInstallation.class); diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index edab276e90..166b59ef84 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -89,7 +89,7 @@ public GHAppCreateTokenBuilder permissions(Map permiss * @throws IOException * on error */ - public GHAppInstallationToken create() throws IOException { + public GHAppInstallationToken create() { return builder.method("POST").withUrlPath(apiUrlTail).fetch(GHAppInstallationToken.class); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index c2611e468c..9bf11aa871 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -212,7 +212,7 @@ public GHUser getSuspendedBy() { * on error * @see Delete an installation */ - public void deleteInstallation() throws IOException { + public void deleteInstallation() { root().createRequest().method("DELETE").withUrlPath(String.format("/app/installations/%d", getId())).send(); } @@ -263,7 +263,7 @@ public GHAppCreateTokenBuilder createToken() { * "https://docs.github.com/en/rest/apps/marketplace?apiVersion=2022-11-28#get-a-subscription-plan-for-an-account">Get * a subscription plan for an account */ - public GHMarketplaceAccountPlan getMarketplaceAccount() throws IOException { + public GHMarketplaceAccountPlan getMarketplaceAccount() { return new GHMarketplacePlanForAccountBuilder(root(), account.getId()).createRequest(); } } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java index f69144bbd4..e734772e0e 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -69,7 +69,7 @@ public GHRepositorySelection getRepositorySelection() { * @throws IOException * on error */ - public Date getExpiresAt() throws IOException { + public Date getExpiresAt() { return GitHubClient.parseDate(expires_at); } } diff --git a/src/main/java/org/kohsuke/github/GHArtifact.java b/src/main/java/org/kohsuke/github/GHArtifact.java index cc37a5bf4d..cf12c31db5 100644 --- a/src/main/java/org/kohsuke/github/GHArtifact.java +++ b/src/main/java/org/kohsuke/github/GHArtifact.java @@ -97,7 +97,7 @@ public GHRepository getRepository() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -112,7 +112,7 @@ public void delete() throws IOException { * @throws IOException * The IO exception. */ - public T download(InputStreamFunction streamFunction) throws IOException { + public T download(InputStreamFunction streamFunction) { requireNonNull(streamFunction, "Stream function must not be null"); return root().createRequest().method("GET").withUrlPath(getApiRoute(), "zip").fetchStream(streamFunction); diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 3f9c8f420c..e3ad2259d2 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -45,7 +45,7 @@ public String getContentType() { * @throws IOException * the io exception */ - public void setContentType(String contentType) throws IOException { + public void setContentType(String contentType) { edit("content_type", contentType); this.content_type = contentType; } @@ -76,7 +76,7 @@ public String getLabel() { * @throws IOException * the io exception */ - public void setLabel(String label) throws IOException { + public void setLabel(String label) { edit("label", label); this.label = label; } @@ -127,7 +127,7 @@ public String getBrowserDownloadUrl() { return browser_download_url; } - private void edit(String key, Object value) throws IOException { + private void edit(String key, Object value) { root().createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } @@ -137,7 +137,7 @@ private void edit(String key, Object value) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index 187867689b..b1394e3fcc 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -60,7 +60,7 @@ private String getApiTail() { * @throws IOException * if the blob cannot be created. */ - public GHBlob create() throws IOException { + public GHBlob create() { return req.method("POST").withUrlPath(getApiTail()).fetch(GHBlob.class); } } diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index f803c67e70..89b8aa5f7c 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -38,7 +38,7 @@ public class GHBranch extends GitHubInteractiveObject { * the exception */ @JsonCreator - GHBranch(@JsonProperty(value = "name", required = true) String name) throws Exception { + GHBranch(@JsonProperty(value = "name", required = true) String name) { Objects.requireNonNull(name); this.name = name; } @@ -106,7 +106,7 @@ public URL getProtectionUrl() { * @throws IOException * the io exception */ - public GHBranchProtection getProtection() throws IOException { + public GHBranchProtection getProtection() { return root().createRequest().setRawUrlPath(protection_url).fetch(GHBranchProtection.class); } @@ -125,7 +125,7 @@ public String getSHA1() { * @throws IOException * if disabling protection fails */ - public void disableProtection() throws IOException { + public void disableProtection() { root().createRequest().method("DELETE").setRawUrlPath(protection_url).send(); } @@ -155,7 +155,7 @@ public GHBranchProtectionBuilder enableProtection() { * if merging fails */ @CheckForNull - public GHCommit merge(GHBranch headBranch, String commitMessage) throws IOException { + public GHCommit merge(GHBranch headBranch, String commitMessage) { return merge(headBranch.getName(), commitMessage); } @@ -176,7 +176,7 @@ public GHCommit merge(GHBranch headBranch, String commitMessage) throws IOExcept * if merging fails */ @CheckForNull - public GHCommit merge(String head, String commitMessage) throws IOException { + public GHCommit merge(String head, String commitMessage) { GHCommit result = root().createRequest() .withUrlPath(owner.getApiTailUrl("merges")) .method("POST") diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 8fbdc0d232..8b96629de3 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -70,7 +70,7 @@ public GHBranchProtection() { * @throws IOException * the io exception */ - public void enabledSignedCommits() throws IOException { + public void enabledSignedCommits() { requester().method("POST").withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class); } @@ -80,7 +80,7 @@ public void enabledSignedCommits() throws IOException { * @throws IOException * the io exception */ - public void disableSignedCommits() throws IOException { + public void disableSignedCommits() { requester().method("DELETE").withUrlPath(url + REQUIRE_SIGNATURES_URI).send(); } @@ -172,7 +172,7 @@ public RequiredReviews getRequiredReviews() { * @throws IOException * the io exception */ - public boolean getRequiredSignatures() throws IOException { + public boolean getRequiredSignatures() { return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class).enabled; } diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index c56e7f2197..a336a40bb4 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -182,7 +182,7 @@ public GHBranchProtectionBuilder dismissStaleReviews(boolean v) { * @throws IOException * the io exception */ - public GHBranchProtection enable() throws IOException { + public GHBranchProtection enable() { return requester().method("PUT") .with(fields) .withNullable("required_status_checks", statusChecks) diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index cb12173ae4..1a3a52dcea 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -218,10 +218,10 @@ public String getHeadSha() { * @throws IOException * the io exception */ - public List getPullRequests() throws IOException { + public List getPullRequests() { for (GHPullRequest singlePull : pullRequests) { // Only refresh if we haven't do so before - singlePull.refresh(singlePull.getTitle()); + singlePull.refreshWithUnchecked(singlePull.getTitle()); } return Collections.unmodifiableList(Arrays.asList(pullRequests)); } diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index eefe6d0235..3b9a138bc3 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -231,7 +231,7 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { * @throws IOException * for the usual reasons */ - public @NonNull GHCheckRun create() throws IOException { + public @NonNull GHCheckRun create() { List extraAnnotations; if (output != null && output.annotations != null && output.annotations.size() > MAX_ANNOTATIONS) { extraAnnotations = output.annotations.subList(MAX_ANNOTATIONS, output.annotations.size()); diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index 8c9dea61f7..ae2d6e4bea 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -196,11 +196,11 @@ public GHApp getApp() { * @throws IOException * the io exception */ - public List getPullRequests() throws IOException { + public List getPullRequests() { if (pullRequests != null && pullRequests.length != 0) { for (GHPullRequest singlePull : pullRequests) { // Only refresh if we haven't do so before - singlePull.refresh(singlePull.getTitle()); + singlePull.refreshWithUnchecked(singlePull.getTitle()); } return Collections.unmodifiableList(Arrays.asList(pullRequests)); } diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index c1d987483a..5fbb83422a 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -43,7 +43,7 @@ public static class ShortInfo extends GitCommit { * @throws GHException * the GH exception */ - public int getCommentCount() throws GHException { + public int getCommentCount() { if (comment_count < 0) { throw new GHException("Not available on this endpoint."); } @@ -308,7 +308,7 @@ public GHCommit() { * @throws IOException * the io exception */ - public ShortInfo getCommitShortInfo() throws IOException { + public ShortInfo getCommitShortInfo() { if (commit == null) populate(); return commit; @@ -331,7 +331,7 @@ public GHRepository getOwner() { * @throws IOException * if the field was not populated and refresh fails */ - public int getLinesChanged() throws IOException { + public int getLinesChanged() { populate(); return stats.total; } @@ -343,7 +343,7 @@ public int getLinesChanged() throws IOException { * @throws IOException * if the field was not populated and refresh fails */ - public int getLinesAdded() throws IOException { + public int getLinesAdded() { populate(); return stats.additions; } @@ -355,7 +355,7 @@ public int getLinesAdded() throws IOException { * @throws IOException * if the field was not populated and refresh fails */ - public int getLinesDeleted() throws IOException { + public int getLinesDeleted() { populate(); return stats.deletions; } @@ -367,7 +367,7 @@ public int getLinesDeleted() throws IOException { * @throws IOException * on error */ - public GHTree getTree() throws IOException { + public GHTree getTree() { return owner.getTree(getCommitShortInfo().getTreeSHA1()); } @@ -409,7 +409,7 @@ public URL getUrl() { * @throws IOException * on error */ - public PagedIterable listFiles() throws IOException { + public PagedIterable listFiles() { populate(); @@ -444,7 +444,7 @@ public int size() { * @throws IOException * on error */ - public List getParents() throws IOException { + public List getParents() { populate(); List r = new ArrayList(); for (String sha1 : getParentSHA1s()) @@ -459,7 +459,7 @@ public List getParents() throws IOException { * @throws IOException * the io exception */ - public GHUser getAuthor() throws IOException { + public GHUser getAuthor() { populate(); return resolveUser(author); } @@ -471,7 +471,7 @@ public GHUser getAuthor() throws IOException { * @throws IOException * if the information was not already fetched and an attempt at fetching the information failed. */ - public Date getAuthoredDate() throws IOException { + public Date getAuthoredDate() { return getCommitShortInfo().getAuthoredDate(); } @@ -482,7 +482,7 @@ public Date getAuthoredDate() throws IOException { * @throws IOException * the io exception */ - public GHUser getCommitter() throws IOException { + public GHUser getCommitter() { populate(); return resolveUser(committer); } @@ -494,11 +494,11 @@ public GHUser getCommitter() throws IOException { * @throws IOException * if the information was not already fetched and an attempt at fetching the information failed. */ - public Date getCommitDate() throws IOException { + public Date getCommitDate() { return getCommitShortInfo().getCommitDate(); } - private GHUser resolveUser(User author) throws IOException { + private GHUser resolveUser(User author) { if (author == null || author.login == null) return null; return owner.root().getUser(author.login); @@ -523,7 +523,7 @@ public PagedIterable listPullRequests() { * @throws IOException * the io exception */ - public PagedIterable listBranchesWhereHead() throws IOException { + public PagedIterable listBranchesWhereHead() { return owner.root() .createRequest() .withUrlPath(String.format("/repos/%s/%s/commits/%s/branches-where-head", @@ -559,7 +559,7 @@ public PagedIterable listComments() { * @throws IOException * if comment is not created */ - public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException { + public GHCommitComment createComment(String body, String path, Integer line, Integer position) { GHCommitComment r = owner.root() .createRequest() .method("POST") @@ -582,7 +582,7 @@ public GHCommitComment createComment(String body, String path, Integer line, Int * @throws IOException * the io exception */ - public GHCommitComment createComment(String body) throws IOException { + public GHCommitComment createComment(String body) { return createComment(body, null, null, null); } @@ -593,7 +593,7 @@ public GHCommitComment createComment(String body) throws IOException { * @throws IOException * if statuses cannot be read */ - public PagedIterable listStatuses() throws IOException { + public PagedIterable listStatuses() { return owner.listCommitStatuses(sha); } @@ -604,7 +604,7 @@ public PagedIterable listStatuses() throws IOException { * @throws IOException * on error */ - public GHCommitStatus getLastStatus() throws IOException { + public GHCommitStatus getLastStatus() { return owner.getLastCommitStatus(sha); } @@ -615,7 +615,7 @@ public GHCommitStatus getLastStatus() throws IOException { * @throws IOException * on error */ - public PagedIterable getCheckRuns() throws IOException { + public PagedIterable getCheckRuns() { return owner.getCheckRuns(sha); } @@ -625,7 +625,7 @@ public PagedIterable getCheckRuns() throws IOException { * @throws IOException * on error */ - void populate() throws IOException { + void populate() { if (files == null && stats == null) owner.root().createRequest().withUrlPath(owner.getApiTailUrl("commits/" + sha)).fetchInto(this); } diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 11c382312b..f49609c0e9 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -136,7 +136,7 @@ private String getApiTail() { * @throws IOException * the io exception */ - public GHCommit create() throws IOException { + public GHCommit create() { req.with("parents", parents); return req.method("POST").withUrlPath(getApiTail()).fetch(GHCommit.class).wrapUp(repo); } diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index 40427b41ea..ba9a1b06ba 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -105,7 +105,7 @@ public int getLine() { * @throws IOException * the io exception */ - public GHUser getUser() throws IOException { + public GHUser getUser() { return owner == null || owner.isOffline() ? user : owner.root().getUser(user.login); } @@ -116,7 +116,7 @@ public GHUser getUser() throws IOException { * @throws IOException * the io exception */ - public GHCommit getCommit() throws IOException { + public GHCommit getCommit() { return getOwner().getCommit(getSHA1()); } @@ -128,7 +128,7 @@ public GHCommit getCommit() throws IOException { * @throws IOException * the io exception */ - public void update(String body) throws IOException { + public void update(String body) { owner.root() .createRequest() .method("PATCH") @@ -147,7 +147,7 @@ public void update(String body) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHReaction createReaction(ReactionContent content) throws IOException { + public GHReaction createReaction(ReactionContent content) { return owner.root() .createRequest() .method("POST") @@ -164,7 +164,7 @@ public GHReaction createReaction(ReactionContent content) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public void deleteReaction(GHReaction reaction) throws IOException { + public void deleteReaction(GHReaction reaction) { owner.root() .createRequest() .method("DELETE") @@ -190,7 +190,7 @@ public PagedIterable listReactions() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { owner.root().createRequest().method("DELETE").withUrlPath(getApiTail()).send(); } diff --git a/src/main/java/org/kohsuke/github/GHCommitPointer.java b/src/main/java/org/kohsuke/github/GHCommitPointer.java index f56c214a50..86ec900e0a 100644 --- a/src/main/java/org/kohsuke/github/GHCommitPointer.java +++ b/src/main/java/org/kohsuke/github/GHCommitPointer.java @@ -53,7 +53,7 @@ public GHCommitPointer() { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHUser getUser() throws IOException { + public GHUser getUser() { if (user != null) return user.root().intern(user); return user; @@ -103,7 +103,7 @@ public String getLabel() { * @throws IOException * the io exception */ - public GHCommit getCommit() throws IOException { + public GHCommit getCommit() { return getRepository().getCommit(getSha()); } diff --git a/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java b/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java index 28e34d66b8..8f5f84c977 100644 --- a/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java @@ -3,8 +3,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; -import java.io.IOException; - // TODO: Auto-generated Javadoc /** * Search commits. @@ -260,7 +258,7 @@ GHCommit[] getItems(GitHub root) { try { GHRepository repo = root.getRepository(repoName); commit.wrapUp(repo); - } catch (IOException ioe) { + } catch (Exception ioe) { } } return items; diff --git a/src/main/java/org/kohsuke/github/GHCommitStatus.java b/src/main/java/org/kohsuke/github/GHCommitStatus.java index 524c4d119a..efca172fbc 100644 --- a/src/main/java/org/kohsuke/github/GHCommitStatus.java +++ b/src/main/java/org/kohsuke/github/GHCommitStatus.java @@ -72,7 +72,7 @@ public String getDescription() { * @throws IOException * the io exception */ - public GHUser getCreator() throws IOException { + public GHUser getCreator() { return root().intern(creator); } diff --git a/src/main/java/org/kohsuke/github/GHCompare.java b/src/main/java/org/kohsuke/github/GHCompare.java index cba09389a1..e7150ff2ad 100644 --- a/src/main/java/org/kohsuke/github/GHCompare.java +++ b/src/main/java/org/kohsuke/github/GHCompare.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JacksonInject; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; import java.util.Collections; import java.util.Iterator; @@ -154,8 +154,8 @@ public Commit getMergeBaseCommit() { public Commit[] getCommits() { try { return listCommits().withPageSize(100).toArray(); - } catch (IOException e) { - throw new GHException(e.getMessage(), e); + } catch (UncheckedIOException e) { + throw new GHException(e.getMessage(), e.getCause()); } } diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 2bfc2a1bcc..ab7dc0e5ef 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -130,7 +130,7 @@ public String getTarget() { */ @Deprecated @SuppressFBWarnings("DM_DEFAULT_ENCODING") - public String getContent() throws IOException { + public String getContent() { return new String(readDecodedContent()); } @@ -147,8 +147,8 @@ public String getContent() throws IOException { * @deprecated Use {@link #read()} */ @Deprecated - public String getEncodedContent() throws IOException { - refresh(content); + public String getEncodedContent() { + refreshWithUnchecked(content); return content; } @@ -186,7 +186,7 @@ public String getHtmlUrl() { * @throws IOException * the io exception */ - public InputStream read() throws IOException { + public InputStream read() { return new ByteArrayInputStream(readDecodedContent()); } @@ -197,7 +197,7 @@ public InputStream read() throws IOException { * @throws IOException * the io exception */ - private byte[] readDecodedContent() throws IOException { + private byte[] readDecodedContent() { String encodedContent = getEncodedContent(); if (encoding.equals("base64")) { try { @@ -218,8 +218,8 @@ private byte[] readDecodedContent() throws IOException { * @throws IOException * the io exception */ - public String getDownloadUrl() throws IOException { - refresh(download_url); + public String getDownloadUrl() { + refreshWithUnchecked(download_url); return download_url; } @@ -249,7 +249,7 @@ public boolean isDirectory() { * @throws IOException * the io exception */ - protected synchronized void populate() throws IOException { + protected synchronized void populate() { root().createRequest().withUrlPath(url).fetchInto(this); } @@ -260,7 +260,7 @@ protected synchronized void populate() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listDirectoryContent() throws IOException { + public PagedIterable listDirectoryContent() { if (!isDirectory()) throw new IllegalStateException(path + " is not a directory"); @@ -279,7 +279,7 @@ public PagedIterable listDirectoryContent() throws IOException { * the io exception */ @SuppressFBWarnings("DM_DEFAULT_ENCODING") - public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException { + public GHContentUpdateResponse update(String newContent, String commitMessage) { return update(newContent.getBytes(), commitMessage, null); } @@ -297,7 +297,7 @@ public GHContentUpdateResponse update(String newContent, String commitMessage) t * the io exception */ @SuppressFBWarnings("DM_DEFAULT_ENCODING") - public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException { + public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) { return update(newContent.getBytes(), commitMessage, branch); } @@ -312,7 +312,7 @@ public GHContentUpdateResponse update(String newContent, String commitMessage, S * @throws IOException * the io exception */ - public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) throws IOException { + public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) { return update(newContentBytes, commitMessage, null); } @@ -329,8 +329,7 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa * @throws IOException * the io exception */ - public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage, String branch) - throws IOException { + public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage, String branch) { String encodedContent = Base64.getEncoder().encodeToString(newContentBytes); Requester requester = root().createRequest() @@ -363,7 +362,7 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa * @throws IOException * the io exception */ - public GHContentUpdateResponse delete(String message) throws IOException { + public GHContentUpdateResponse delete(String message) { return delete(message, null); } @@ -378,7 +377,7 @@ public GHContentUpdateResponse delete(String message) throws IOException { * @throws IOException * the io exception */ - public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException { + public GHContentUpdateResponse delete(String commitMessage, String branch) { Requester requester = root().createRequest() .method("DELETE") .with("path", path) @@ -430,7 +429,7 @@ GHContent wrap(GHRepository owner) { * Signals that an I/O exception has occurred. */ @Override - public synchronized void refresh() throws IOException { + public synchronized void refresh() { root().createRequest().setRawUrlPath(url).fetchInto(this); } } diff --git a/src/main/java/org/kohsuke/github/GHContentBuilder.java b/src/main/java/org/kohsuke/github/GHContentBuilder.java index 9b24af92b0..455b4818ff 100644 --- a/src/main/java/org/kohsuke/github/GHContentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHContentBuilder.java @@ -109,7 +109,7 @@ public GHContentBuilder message(String commitMessage) { * @throws IOException * the io exception */ - public GHContentUpdateResponse commit() throws IOException { + public GHContentUpdateResponse commit() { GHContentUpdateResponse response = req.withUrlPath(GHContent.getApiRoute(repo, path)) .fetch(GHContentUpdateResponse.class); diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 15bceb2ebd..1a976ee81a 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -27,7 +27,7 @@ public GHCreateRepositoryBuilder(String name, GitHub root, String apiTail) { try { name(name); - } catch (IOException e) { + } catch (Exception e) { // not going to happen here } } @@ -41,7 +41,7 @@ public GHCreateRepositoryBuilder(String name, GitHub root, String apiTail) { * @throws IOException * In case of any networking error or error from the server. */ - public GHCreateRepositoryBuilder gitignoreTemplate(String language) throws IOException { + public GHCreateRepositoryBuilder gitignoreTemplate(String language) { return with("gitignore_template", language); } @@ -54,7 +54,7 @@ public GHCreateRepositoryBuilder gitignoreTemplate(String language) throws IOExc * @throws IOException * In case of any networking error or error from the server. */ - public GHCreateRepositoryBuilder licenseTemplate(String license) throws IOException { + public GHCreateRepositoryBuilder licenseTemplate(String license) { return with("license_template", license); } @@ -67,7 +67,7 @@ public GHCreateRepositoryBuilder licenseTemplate(String license) throws IOExcept * @throws IOException * In case of any networking error or error from the server. */ - public GHCreateRepositoryBuilder autoInit(boolean enabled) throws IOException { + public GHCreateRepositoryBuilder autoInit(boolean enabled) { return with("auto_init", enabled); } @@ -80,7 +80,7 @@ public GHCreateRepositoryBuilder autoInit(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public GHCreateRepositoryBuilder team(GHTeam team) throws IOException { + public GHCreateRepositoryBuilder team(GHTeam team) { if (team != null) return with("team_id", team.getId()); return this; @@ -95,7 +95,7 @@ public GHCreateRepositoryBuilder team(GHTeam team) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public GHCreateRepositoryBuilder owner(String owner) throws IOException { + public GHCreateRepositoryBuilder owner(String owner) { return with("owner", owner); } @@ -135,7 +135,7 @@ public GHCreateRepositoryBuilder fromTemplateRepository(GHRepository templateRep * @throws IOException * if repository cannot be created */ - public GHRepository create() throws IOException { + public GHRepository create() { return done(); } } diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index 50a7743688..463e90fad5 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -154,7 +154,7 @@ public String toString() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { owner.root() .createRequest() .method("DELETE") diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index ae18580667..8ba9ced79f 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -172,7 +172,7 @@ public boolean isProductionEnvironment() { * @throws IOException * the io exception */ - public GHUser getCreator() throws IOException { + public GHUser getCreator() { return root().intern(creator); } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java index 0463b425bc..1dbbc2a41a 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java @@ -163,7 +163,7 @@ public GHDeploymentBuilder description(String description) { * @throws IOException * the io exception */ - public GHDeployment create() throws IOException { + public GHDeployment create() { return builder.withUrlPath(repo.getApiTailUrl("deployments")).fetch(GHDeployment.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java index e003758fb8..e8bd1d8f89 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java @@ -101,7 +101,7 @@ public GHDeploymentStatusBuilder logUrl(String logUrl) { * @throws IOException * the io exception */ - public GHDeploymentStatus create() throws IOException { + public GHDeploymentStatus create() { return builder.withUrlPath(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses")) .fetch(GHDeploymentStatus.class) .lateBind(repo); diff --git a/src/main/java/org/kohsuke/github/GHDiscussion.java b/src/main/java/org/kohsuke/github/GHDiscussion.java index 94edaacbc8..07bcd97ebc 100644 --- a/src/main/java/org/kohsuke/github/GHDiscussion.java +++ b/src/main/java/org/kohsuke/github/GHDiscussion.java @@ -39,7 +39,7 @@ public GHDiscussion() { * @throws IOException * Signals that an I/O exception has occurred. */ - public URL getHtmlUrl() throws IOException { + public URL getHtmlUrl() { return GitHubClient.parseURL(htmlUrl); } @@ -125,7 +125,7 @@ public boolean isPrivate() { * @throws IOException * the io exception */ - static GHDiscussion.Creator create(GHTeam team) throws IOException { + static GHDiscussion.Creator create(GHTeam team) { return new GHDiscussion.Creator(team); } @@ -140,7 +140,7 @@ static GHDiscussion.Creator create(GHTeam team) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException { + static GHDiscussion read(GHTeam team, long discussionNumber) { return team.root() .createRequest() .setRawUrlPath(getRawUrlPath(team, discussionNumber)) @@ -157,7 +157,7 @@ static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException * @throws IOException * Signals that an I/O exception has occurred. */ - static PagedIterable readAll(GHTeam team) throws IOException { + static PagedIterable readAll(GHTeam team) { return team.root() .createRequest() .setRawUrlPath(getRawUrlPath(team, null)) @@ -190,7 +190,7 @@ public GHDiscussion.Setter set() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { team.root().createRequest().method("DELETE").setRawUrlPath(getRawUrlPath(team, number)).send(); } @@ -244,7 +244,7 @@ private Creator(@Nonnull GHTeam team) { * if there is an I/O Exception */ @Nonnull - public Creator private_(boolean value) throws IOException { + public Creator private_(boolean value) { return with("private", value); } } diff --git a/src/main/java/org/kohsuke/github/GHDiscussionBuilder.java b/src/main/java/org/kohsuke/github/GHDiscussionBuilder.java index 19097c09fc..b4b54fab22 100644 --- a/src/main/java/org/kohsuke/github/GHDiscussionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDiscussionBuilder.java @@ -53,7 +53,7 @@ protected GHDiscussionBuilder(@Nonnull Class intermediateReturnType, * if there is an I/O Exception */ @Nonnull - public S title(String value) throws IOException { + public S title(String value) { return with("title", value); } @@ -67,7 +67,7 @@ public S title(String value) throws IOException { * if there is an I/O Exception */ @Nonnull - public S body(String value) throws IOException { + public S body(String value) { return with("body", value); } @@ -76,7 +76,7 @@ public S body(String value) throws IOException { */ @Nonnull @Override - public GHDiscussion done() throws IOException { + public GHDiscussion done() { return super.done().wrapUp(team); } } diff --git a/src/main/java/org/kohsuke/github/GHEventInfo.java b/src/main/java/org/kohsuke/github/GHEventInfo.java index 551b6cb2ed..bdaabf160a 100644 --- a/src/main/java/org/kohsuke/github/GHEventInfo.java +++ b/src/main/java/org/kohsuke/github/GHEventInfo.java @@ -4,6 +4,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.*; // TODO: Auto-generated Javadoc @@ -141,7 +142,7 @@ public Date getCreatedAt() { */ @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "The field comes from JSON deserialization") - public GHRepository getRepository() throws IOException { + public GHRepository getRepository() { return root().getRepository(repo.name); } @@ -154,7 +155,7 @@ public GHRepository getRepository() throws IOException { */ @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "The field comes from JSON deserialization") - public GHUser getActor() throws IOException { + public GHUser getActor() { return root().getUser(actor.getLogin()); } @@ -165,7 +166,7 @@ public GHUser getActor() throws IOException { * @throws IOException * on error */ - public String getActorLogin() throws IOException { + public String getActorLogin() { return actor.getLogin(); } @@ -178,7 +179,7 @@ public String getActorLogin() throws IOException { */ @SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "The field comes from JSON deserialization") - public GHOrganization getOrganization() throws IOException { + public GHOrganization getOrganization() { return (org == null || org.getLogin() == null) ? null : root().getOrganization(org.getLogin()); } @@ -194,9 +195,13 @@ public GHOrganization getOrganization() throws IOException { * @throws IOException * if payload cannot be parsed */ - public T getPayload(Class type) throws IOException { - T v = GitHubClient.getMappingObjectReader(root()).readValue(payload.traverse(), type); - v.lateBind(); - return v; + public T getPayload(Class type) { + try { + T v = GitHubClient.getMappingObjectReader(root()).readValue(payload.traverse(), type); + v.lateBind(); + return v; + } catch (IOException e) { + throw new UncheckedIOException(e); + } } } diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 845b95bcaa..ddb66503de 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonSetter; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.Collections; @@ -251,7 +250,7 @@ public List getRepositories() { // as to be unusable without populating, so we do it eagerly ghRepositories.add(this.root().getRepositoryById(singleRepo.getId())); } - } catch (IOException e) { + } catch (Exception e) { throw new GHException("Failed to refresh repositories", e); } } @@ -416,7 +415,7 @@ void lateBind() { for (GHRepository singleRepo : repositories) { // warp each of the repository singleRepo.populate(); } - } catch (IOException e) { + } catch (Exception e) { throw new GHException("Failed to refresh repositories", e); } } diff --git a/src/main/java/org/kohsuke/github/GHExternalGroup.java b/src/main/java/org/kohsuke/github/GHExternalGroup.java index 01d997b628..663c872aff 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroup.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroup.java @@ -198,7 +198,7 @@ void wrapUp(final GitHub root) { // auto-wrapUp when organization is known from * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHOrganization getOrganization() throws IOException { + public GHOrganization getOrganization() { return organization; } @@ -254,7 +254,7 @@ public List getMembers() { * Signals that an I/O exception has occurred. */ @Override - public void refresh() throws IOException { + public void refresh() { root().createRequest().withUrlPath(api("")).fetchInto(this).wrapUp(root()); } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index d035ee6ef6..78f94c0793 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -80,7 +80,7 @@ public String getGistId() { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHUser getOwner() throws IOException { + public GHUser getOwner() { return owner; } @@ -206,7 +206,7 @@ String getApiTailUrl(String tail) { * @throws IOException * the io exception */ - public void star() throws IOException { + public void star() { root().createRequest().method("PUT").withUrlPath(getApiTailUrl("star")).send(); } @@ -216,7 +216,7 @@ public void star() throws IOException { * @throws IOException * the io exception */ - public void unstar() throws IOException { + public void unstar() { root().createRequest().method("DELETE").withUrlPath(getApiTailUrl("star")).send(); } @@ -227,7 +227,7 @@ public void unstar() throws IOException { * @throws IOException * the io exception */ - public boolean isStarred() throws IOException { + public boolean isStarred() { return root().createRequest().withUrlPath(getApiTailUrl("star")).fetchHttpStatusCode() / 100 == 2; } @@ -238,7 +238,7 @@ public boolean isStarred() throws IOException { * @throws IOException * the io exception */ - public GHGist fork() throws IOException { + public GHGist fork() { return root().createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).fetch(GHGist.class); } @@ -257,7 +257,7 @@ public PagedIterable listForks() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath("/gists/" + id).send(); } @@ -268,7 +268,7 @@ public void delete() throws IOException { * @throws IOException * the io exception */ - public GHGistUpdater update() throws IOException { + public GHGistUpdater update() { return new GHGistUpdater(this); } diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index c2797b628c..7c64893c24 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(@Nonnull String fileName, @Nonnull String content) { * @throws IOException * if Gist cannot be created. */ - public GHGist create() throws IOException { + public GHGist create() { req.with("files", files); return req.withUrlPath("/gists").fetch(GHGist.class); } diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index 5faaccde4d..c43382db2b 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -44,7 +44,7 @@ public class GHGistUpdater { * @throws IOException * the io exception */ - public GHGistUpdater addFile(@Nonnull String fileName, @Nonnull String content) throws IOException { + public GHGistUpdater addFile(@Nonnull String fileName, @Nonnull String content) { updateFile(fileName, content); return this; } @@ -58,7 +58,7 @@ public GHGistUpdater addFile(@Nonnull String fileName, @Nonnull String content) * @throws IOException * Signals that an I/O exception has occurred. */ - public GHGistUpdater deleteFile(@Nonnull String fileName) throws IOException { + public GHGistUpdater deleteFile(@Nonnull String fileName) { files.put(fileName, null); return this; } @@ -74,7 +74,7 @@ public GHGistUpdater deleteFile(@Nonnull String fileName) throws IOException { * @throws IOException * the io exception */ - public GHGistUpdater renameFile(@Nonnull String fileName, @Nonnull String newFileName) throws IOException { + public GHGistUpdater renameFile(@Nonnull String fileName, @Nonnull String newFileName) { Map file = files.computeIfAbsent(fileName, d -> new HashMap<>()); file.put("filename", newFileName); return this; @@ -91,7 +91,7 @@ public GHGistUpdater renameFile(@Nonnull String fileName, @Nonnull String newFil * @throws IOException * the io exception */ - public GHGistUpdater updateFile(@Nonnull String fileName, @Nonnull String content) throws IOException { + public GHGistUpdater updateFile(@Nonnull String fileName, @Nonnull String content) { Map file = files.computeIfAbsent(fileName, d -> new HashMap<>()); file.put("content", content); return this; @@ -110,8 +110,7 @@ public GHGistUpdater updateFile(@Nonnull String fileName, @Nonnull String conten * @throws IOException * the io exception */ - public GHGistUpdater updateFile(@Nonnull String fileName, @Nonnull String newFileName, @Nonnull String content) - throws IOException { + public GHGistUpdater updateFile(@Nonnull String fileName, @Nonnull String newFileName, @Nonnull String content) { Map file = files.computeIfAbsent(fileName, d -> new HashMap<>()); file.put("content", content); file.put("filename", newFileName); @@ -138,7 +137,7 @@ public GHGistUpdater description(String desc) { * @throws IOException * the io exception */ - public GHGist update() throws IOException { + public GHGist update() { builder.with("files", files); return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).fetch(GHGist.class); } diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index d9e1fc3bd4..c0aa240df2 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -84,7 +84,7 @@ public Map getConfig() { * the io exception * @see Ping hook */ - public void ping() throws IOException { + public void ping() { root().createRequest().method("POST").withUrlPath(getApiRoute() + "/pings").send(); } @@ -94,7 +94,7 @@ public void ping() throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index addcad3179..dfb61b0bbb 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -30,7 +30,7 @@ private Context(GitHub root) { * @throws IOException * the io exception */ - public List getHooks() throws IOException { + public List getHooks() { // jdk/eclipse bug GHHook[] hookArray = root().createRequest().withUrlPath(collection()).fetch(collectionClass()); @@ -51,7 +51,7 @@ public List getHooks() throws IOException { * @throws IOException * the io exception */ - public GHHook getHook(int id) throws IOException { + public GHHook getHook(int id) { GHHook hook = root().createRequest().withUrlPath(collection() + "/" + id).fetch(clazz()); return wrap(hook); } @@ -71,8 +71,7 @@ public GHHook getHook(int id) throws IOException { * @throws IOException * the io exception */ - public GHHook createHook(String name, Map config, Collection events, boolean active) - throws IOException { + public GHHook createHook(String name, Map config, Collection events, boolean active) { List ea = null; if (events != null) { ea = new ArrayList(); @@ -100,7 +99,7 @@ public GHHook createHook(String name, Map config, Collection map) throws IOException { + private void edit(Map map) { root().createRequest().with(map).method("PATCH").withUrlPath(getApiRoute()).send(); } /** * Identical to edit(), but allows null for the value. */ - private void editNullable(String key, Object value) throws IOException { + private void editNullable(String key, Object value) { root().createRequest().withNullable(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } - private void editIssue(String key, Object value) throws IOException { + private void editIssue(String key, Object value) { root().createRequest().withNullable(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).send(); } @@ -301,7 +302,7 @@ private void editIssue(String key, Object value) throws IOException { * @throws IOException * the io exception */ - public void close() throws IOException { + public void close() { edit("state", "closed"); } @@ -313,7 +314,7 @@ public void close() throws IOException { * @throws IOException * the io exception */ - public void close(GHIssueStateReason reason) throws IOException { + public void close(GHIssueStateReason reason) { Map map = new HashMap<>(); map.put("state", "closed"); map.put("state_reason", reason.name().toLowerCase(Locale.ENGLISH)); @@ -326,7 +327,7 @@ public void close(GHIssueStateReason reason) throws IOException { * @throws IOException * the io exception */ - public void reopen() throws IOException { + public void reopen() { edit("state", "open"); } @@ -338,7 +339,7 @@ public void reopen() throws IOException { * @throws IOException * the io exception */ - public void setTitle(String title) throws IOException { + public void setTitle(String title) { edit("title", title); } @@ -350,7 +351,7 @@ public void setTitle(String title) throws IOException { * @throws IOException * the io exception */ - public void setBody(String body) throws IOException { + public void setBody(String body) { edit("body", body); } @@ -362,7 +363,7 @@ public void setBody(String body) throws IOException { * @throws IOException * The io exception */ - public void setMilestone(GHMilestone milestone) throws IOException { + public void setMilestone(GHMilestone milestone) { if (milestone == null) { editIssue("milestone", null); } else { @@ -378,7 +379,7 @@ public void setMilestone(GHMilestone milestone) throws IOException { * @throws IOException * the io exception */ - public void assignTo(GHUser user) throws IOException { + public void assignTo(GHUser user) { setAssignees(user); } @@ -390,7 +391,7 @@ public void assignTo(GHUser user) throws IOException { * @throws IOException * the io exception */ - public void setLabels(String... labels) throws IOException { + public void setLabels(String... labels) { editIssue("labels", labels); } @@ -405,7 +406,7 @@ public void setLabels(String... labels) throws IOException { * @throws IOException * the io exception */ - public List addLabels(String... names) throws IOException { + public List addLabels(String... names) { return _addLabels(Arrays.asList(names)); } @@ -420,7 +421,7 @@ public List addLabels(String... names) throws IOException { * @throws IOException * the io exception */ - public List addLabels(GHLabel... labels) throws IOException { + public List addLabels(GHLabel... labels) { return addLabels(Arrays.asList(labels)); } @@ -435,11 +436,11 @@ public List addLabels(GHLabel... labels) throws IOException { * @throws IOException * the io exception */ - public List addLabels(Collection labels) throws IOException { + public List addLabels(Collection labels) { return _addLabels(GHLabel.toNames(labels)); } - private List _addLabels(Collection names) throws IOException { + private List _addLabels(Collection names) { return Arrays.asList(root().createRequest() .with("labels", names) .method("POST") @@ -458,7 +459,7 @@ private List _addLabels(Collection names) throws IOException { * @throws IOException * the io exception, throws {@link GHFileNotFoundException} if label was not present. */ - public List removeLabel(String name) throws IOException { + public List removeLabel(String name) { return Arrays.asList(root().createRequest() .method("DELETE") .withUrlPath(getIssuesApiRoute() + "/labels", name) @@ -476,7 +477,7 @@ public List removeLabel(String name) throws IOException { * @throws IOException * the io exception */ - public List removeLabels(String... names) throws IOException { + public List removeLabels(String... names) { return _removeLabels(Arrays.asList(names)); } @@ -492,7 +493,7 @@ public List removeLabels(String... names) throws IOException { * the io exception * @see #removeLabels(String...) #removeLabels(String...) */ - public List removeLabels(GHLabel... labels) throws IOException { + public List removeLabels(GHLabel... labels) { return removeLabels(Arrays.asList(labels)); } @@ -507,17 +508,19 @@ public List removeLabels(GHLabel... labels) throws IOException { * @throws IOException * the io exception */ - public List removeLabels(Collection labels) throws IOException { + public List removeLabels(Collection labels) { return _removeLabels(GHLabel.toNames(labels)); } - private List _removeLabels(Collection names) throws IOException { + private List _removeLabels(Collection names) { List remainingLabels = Collections.emptyList(); for (String name : names) { try { remainingLabels = removeLabel(name); - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { // when trying to remove multiple labels, we ignore already removed + if (GHFileNotFoundException.class.isInstance(e)) { + } } } return remainingLabels; @@ -531,7 +534,7 @@ private List _removeLabels(Collection names) throws IOException * the io exception * @see #listComments() #listComments() */ - public List getComments() throws IOException { + public List getComments() { return listComments().toList(); } @@ -544,7 +547,7 @@ public List getComments() throws IOException { * @see List issue comments * @see #queryComments() queryComments to apply filters. */ - public PagedIterable listComments() throws IOException { + public PagedIterable listComments() { return root().createRequest() .withUrlPath(getIssuesApiRoute() + "/comments") .toIterable(GHIssueComment[].class, item -> item.wrapUp(this)); @@ -569,7 +572,7 @@ public GHIssueCommentQueryBuilder queryComments() { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHReaction createReaction(ReactionContent content) throws IOException { + public GHReaction createReaction(ReactionContent content) { return root().createRequest() .method("POST") .with("content", content.getContent()) @@ -585,7 +588,7 @@ public GHReaction createReaction(ReactionContent content) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public void deleteReaction(GHReaction reaction) throws IOException { + public void deleteReaction(GHReaction reaction) { owner.root() .createRequest() .method("DELETE") @@ -612,7 +615,7 @@ public PagedIterable listReactions() { * @throws IOException * the io exception */ - public void addAssignees(GHUser... assignees) throws IOException { + public void addAssignees(GHUser... assignees) { addAssignees(Arrays.asList(assignees)); } @@ -624,7 +627,7 @@ public void addAssignees(GHUser... assignees) throws IOException { * @throws IOException * the io exception */ - public void addAssignees(Collection assignees) throws IOException { + public void addAssignees(Collection assignees) { root().createRequest() .method("POST") .with(ASSIGNEES, getLogins(assignees)) @@ -640,7 +643,7 @@ public void addAssignees(Collection assignees) throws IOException { * @throws IOException * the io exception */ - public void setAssignees(GHUser... assignees) throws IOException { + public void setAssignees(GHUser... assignees) { setAssignees(Arrays.asList(assignees)); } @@ -652,7 +655,7 @@ public void setAssignees(GHUser... assignees) throws IOException { * @throws IOException * the io exception */ - public void setAssignees(Collection assignees) throws IOException { + public void setAssignees(Collection assignees) { root().createRequest() .method("PATCH") .with(ASSIGNEES, getLogins(assignees)) @@ -668,7 +671,7 @@ public void setAssignees(Collection assignees) throws IOException { * @throws IOException * the io exception */ - public void removeAssignees(GHUser... assignees) throws IOException { + public void removeAssignees(GHUser... assignees) { removeAssignees(Arrays.asList(assignees)); } @@ -680,7 +683,7 @@ public void removeAssignees(GHUser... assignees) throws IOException { * @throws IOException * the io exception */ - public void removeAssignees(Collection assignees) throws IOException { + public void removeAssignees(Collection assignees) { root().createRequest() .method("DELETE") .with(ASSIGNEES, getLogins(assignees)) @@ -720,7 +723,7 @@ protected String getIssuesApiRoute() { * @throws IOException * the io exception */ - public GHUser getAssignee() throws IOException { + public GHUser getAssignee() { return root().intern(assignee); } @@ -740,7 +743,7 @@ public List getAssignees() { * @throws IOException * the io exception */ - public GHUser getUser() throws IOException { + public GHUser getUser() { return root().intern(user); } @@ -755,7 +758,7 @@ public GHUser getUser() throws IOException { * @throws IOException * the io exception */ - public GHUser getClosedBy() throws IOException { + public GHUser getClosedBy() { if (!"closed".equals(state)) return null; @@ -867,7 +870,7 @@ protected static List getLogins(Collection users) { * @throws IOException * the io exception */ - public PagedIterable listEvents() throws IOException { + public PagedIterable listEvents() { return root().createRequest() .withUrlPath(getRepository().getApiTailUrl(String.format("/issues/%s/events", number))) .toIterable(GHIssueEvent[].class, item -> item.wrapUp(this)); diff --git a/src/main/java/org/kohsuke/github/GHIssueBuilder.java b/src/main/java/org/kohsuke/github/GHIssueBuilder.java index 0d904c4fb2..557686515f 100644 --- a/src/main/java/org/kohsuke/github/GHIssueBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueBuilder.java @@ -101,7 +101,7 @@ public GHIssueBuilder label(String label) { * @throws IOException * the io exception */ - public GHIssue create() throws IOException { + public GHIssue create() { return builder.with("labels", labels) .with("assignees", assignees) .withUrlPath(repo.getApiTailUrl("issues")) diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 2c6d8f9561..9320cf76f6 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -88,7 +88,7 @@ public String getBody() { * @throws IOException * the io exception */ - public GHUser getUser() throws IOException { + public GHUser getUser() { return owner == null || owner.isOffline() ? user : owner.root().getUser(user.getLogin()); } @@ -118,7 +118,7 @@ public GHCommentAuthorAssociation getAuthorAssociation() { * @throws IOException * the io exception */ - public void update(String body) throws IOException { + public void update(String body) { owner.root() .createRequest() .method("PATCH") @@ -134,7 +134,7 @@ public void update(String body) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { owner.root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -147,7 +147,7 @@ public void delete() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHReaction createReaction(ReactionContent content) throws IOException { + public GHReaction createReaction(ReactionContent content) { return owner.root() .createRequest() .method("POST") @@ -164,7 +164,7 @@ public GHReaction createReaction(ReactionContent content) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public void deleteReaction(GHReaction reaction) throws IOException { + public void deleteReaction(GHReaction reaction) { owner.root() .createRequest() .method("DELETE") diff --git a/src/main/java/org/kohsuke/github/GHKey.java b/src/main/java/org/kohsuke/github/GHKey.java index d0e90a2032..615f62fbc7 100644 --- a/src/main/java/org/kohsuke/github/GHKey.java +++ b/src/main/java/org/kohsuke/github/GHKey.java @@ -89,7 +89,7 @@ public String toString() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(String.format("/user/keys/%d", id)).send(); } } diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 6b77b8bfa4..8c3e863703 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -147,7 +147,7 @@ static Collection toNames(Collection labels) { * the io exception */ @BetaApi - static Creator create(GHRepository repository) throws IOException { + static Creator create(GHRepository repository) { return new Creator(repository); } @@ -162,7 +162,7 @@ static Creator create(GHRepository repository) throws IOException { * @throws IOException * the io exception */ - static GHLabel read(@Nonnull GHRepository repository, @Nonnull String name) throws IOException { + static GHLabel read(@Nonnull GHRepository repository, @Nonnull String name) { return repository.root() .createRequest() .withUrlPath(repository.getApiTailUrl("labels"), name) @@ -179,7 +179,7 @@ static GHLabel read(@Nonnull GHRepository repository, @Nonnull String name) thro * @throws IOException * the io exception */ - static PagedIterable readAll(@Nonnull final GHRepository repository) throws IOException { + static PagedIterable readAll(@Nonnull final GHRepository repository) { return repository.root() .createRequest() .withUrlPath(repository.getApiTailUrl("labels")) @@ -215,7 +215,7 @@ public Setter set() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").setRawUrlPath(getUrl()).send(); } diff --git a/src/main/java/org/kohsuke/github/GHLabelBuilder.java b/src/main/java/org/kohsuke/github/GHLabelBuilder.java index 3803a7de8e..b237077d5b 100644 --- a/src/main/java/org/kohsuke/github/GHLabelBuilder.java +++ b/src/main/java/org/kohsuke/github/GHLabelBuilder.java @@ -51,7 +51,7 @@ protected GHLabelBuilder(@Nonnull Class intermediateReturnType, */ @Nonnull @BetaApi - public S name(String value) throws IOException { + public S name(String value) { return with("name", value); } @@ -66,7 +66,7 @@ public S name(String value) throws IOException { */ @Nonnull @BetaApi - public S color(String value) throws IOException { + public S color(String value) { return with("color", value); } @@ -81,7 +81,7 @@ public S color(String value) throws IOException { */ @Nonnull @BetaApi - public S description(String value) throws IOException { + public S description(String value) { return with("description", value); } } diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java index 9a66ad3a98..b9ee5ae11d 100644 --- a/src/main/java/org/kohsuke/github/GHLicense.java +++ b/src/main/java/org/kohsuke/github/GHLicense.java @@ -107,7 +107,7 @@ public String getSpdxId() { * @throws IOException * the io exception */ - public Boolean isFeatured() throws IOException { + public Boolean isFeatured() { populate(); return featured; } @@ -119,7 +119,7 @@ public Boolean isFeatured() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public URL getHtmlUrl() throws IOException { + public URL getHtmlUrl() { populate(); return GitHubClient.parseURL(html_url); } @@ -131,7 +131,7 @@ public URL getHtmlUrl() throws IOException { * @throws IOException * the io exception */ - public String getDescription() throws IOException { + public String getDescription() { populate(); return description; } @@ -143,7 +143,7 @@ public String getDescription() throws IOException { * @throws IOException * the io exception */ - public String getCategory() throws IOException { + public String getCategory() { populate(); return category; } @@ -155,7 +155,7 @@ public String getCategory() throws IOException { * @throws IOException * the io exception */ - public String getImplementation() throws IOException { + public String getImplementation() { populate(); return implementation; } @@ -167,7 +167,7 @@ public String getImplementation() throws IOException { * @throws IOException * the io exception */ - public List getRequired() throws IOException { + public List getRequired() { populate(); return Collections.unmodifiableList(required); } @@ -179,7 +179,7 @@ public List getRequired() throws IOException { * @throws IOException * the io exception */ - public List getPermitted() throws IOException { + public List getPermitted() { populate(); return Collections.unmodifiableList(permitted); } @@ -191,7 +191,7 @@ public List getPermitted() throws IOException { * @throws IOException * the io exception */ - public List getForbidden() throws IOException { + public List getForbidden() { populate(); return Collections.unmodifiableList(forbidden); } @@ -203,7 +203,7 @@ public List getForbidden() throws IOException { * @throws IOException * the io exception */ - public String getBody() throws IOException { + public String getBody() { populate(); return body; } @@ -216,7 +216,7 @@ public String getBody() throws IOException { * @throws IOException * the io exception */ - protected synchronized void populate() throws IOException { + protected synchronized void populate() { if (description != null) return; // already populated diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java b/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java index df0261e880..76893cfae5 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java @@ -97,7 +97,7 @@ public GHMarketplaceAccountType getType() { * "https://docs.github.com/en/rest/apps/marketplace?apiVersion=2022-11-28#get-a-subscription-plan-for-an-account">Get * a subscription plan for an account */ - public GHMarketplaceAccountPlan getPlan() throws IOException { + public GHMarketplaceAccountPlan getPlan() { return new GHMarketplacePlanForAccountBuilder(root(), this.id).createRequest(); } diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java b/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java index 1e061a36c3..93e04c3629 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java @@ -75,7 +75,7 @@ public enum Sort { * @throws IOException * on error */ - public PagedIterable createRequest() throws IOException { + public PagedIterable createRequest() { return builder.withUrlPath(String.format("/marketplace_listing/plans/%d/accounts", this.planId)) .toIterable(GHMarketplaceAccountPlan[].class, null); } diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePlanForAccountBuilder.java b/src/main/java/org/kohsuke/github/GHMarketplacePlanForAccountBuilder.java index e5167f31ac..e5c3144d27 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePlanForAccountBuilder.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePlanForAccountBuilder.java @@ -37,7 +37,7 @@ public class GHMarketplacePlanForAccountBuilder extends GitHubInteractiveObject * @throws IOException * on error */ - public GHMarketplaceAccountPlan createRequest() throws IOException { + public GHMarketplaceAccountPlan createRequest() { return builder.withUrlPath(String.format("/marketplace_listing/accounts/%d", this.accountId)) .fetch(GHMarketplaceAccountPlan.class); } diff --git a/src/main/java/org/kohsuke/github/GHMembership.java b/src/main/java/org/kohsuke/github/GHMembership.java index e6b7e2e09c..153427c3d0 100644 --- a/src/main/java/org/kohsuke/github/GHMembership.java +++ b/src/main/java/org/kohsuke/github/GHMembership.java @@ -92,7 +92,7 @@ public GHOrganization getOrganization() { * the io exception * @see GHMyself#getMembership(GHOrganization) GHMyself#getMembership(GHOrganization) */ - public void activate() throws IOException { + public void activate() { root().createRequest().method("PATCH").with("state", State.ACTIVE).withUrlPath(url).fetchInto(this); } diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index eeefaf5a9b..dbb6df56cc 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -49,7 +49,7 @@ public GHRepository getOwner() { * @throws IOException * the io exception */ - public GHUser getCreator() throws IOException { + public GHUser getCreator() { return root().intern(creator); } @@ -71,7 +71,7 @@ public Date getDueOn() { * @throws IOException * the io exception */ - public Date getClosedAt() throws IOException { + public Date getClosedAt() { return GitHubClient.parseDate(closed_at); } @@ -144,7 +144,7 @@ public GHMilestoneState getState() { * @throws IOException * the io exception */ - public void close() throws IOException { + public void close() { edit("state", "closed"); } @@ -154,7 +154,7 @@ public void close() throws IOException { * @throws IOException * the io exception */ - public void reopen() throws IOException { + public void reopen() { edit("state", "open"); } @@ -164,11 +164,11 @@ public void reopen() throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } - private void edit(String key, Object value) throws IOException { + private void edit(String key, Object value) { root().createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } @@ -180,7 +180,7 @@ private void edit(String key, Object value) throws IOException { * @throws IOException * the io exception */ - public void setTitle(String title) throws IOException { + public void setTitle(String title) { edit("title", title); } @@ -192,7 +192,7 @@ public void setTitle(String title) throws IOException { * @throws IOException * the io exception */ - public void setDescription(String description) throws IOException { + public void setDescription(String description) { edit("description", description); } @@ -204,7 +204,7 @@ public void setDescription(String description) throws IOException { * @throws IOException * the io exception */ - public void setDueOn(Date dueOn) throws IOException { + public void setDueOn(Date dueOn) { edit("due_on", GitHubClient.printDate(dueOn)); } diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 784f120b15..6ba24fa350 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -53,7 +53,7 @@ public enum RepositoryListFilter { * @deprecated Use {@link #listEmails()} */ @Deprecated - public List getEmails() throws IOException { + public List getEmails() { return getEmails2().stream().map(email -> email.getEmail()).collect(Collectors.toList()); } @@ -69,7 +69,7 @@ public List getEmails() throws IOException { * @deprecated Use {@link #listEmails()} */ @Deprecated - public List getEmails2() throws IOException { + public List getEmails2() { return listEmails().toList(); } @@ -95,7 +95,7 @@ public PagedIterable listEmails() { * @throws IOException * the io exception */ - public List getPublicKeys() throws IOException { + public List getPublicKeys() { return root().createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toList(); } @@ -112,7 +112,7 @@ public List getPublicKeys() throws IOException { * @throws IOException * the io exception */ - public GHKey addPublicKey(String title, String key) throws IOException { + public GHKey addPublicKey(String title, String key) { return root().createRequest() .withUrlPath("/user/keys") .method("POST") @@ -131,7 +131,7 @@ public GHKey addPublicKey(String title, String key) throws IOException { * @throws IOException * the io exception */ - public List getPublicVerifiedKeys() throws IOException { + public List getPublicVerifiedKeys() { return root().createRequest() .withUrlPath("/users/" + getLogin() + "/keys") .toIterable(GHVerifiedKey[].class, null) @@ -145,7 +145,7 @@ public List getPublicVerifiedKeys() throws IOException { * @throws IOException * the io exception */ - public GHPersonSet getAllOrganizations() throws IOException { + public GHPersonSet getAllOrganizations() { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); for (GHOrganization o : root().createRequest() @@ -165,7 +165,7 @@ public GHPersonSet getAllOrganizations() throws IOException { * @throws IOException * the io exception */ - public synchronized Map getAllRepositories() throws IOException { + public synchronized Map getAllRepositories() { Map repositories = new TreeMap(); for (GHRepository r : listRepositories()) { repositories.put(r.getName(), r); @@ -254,14 +254,14 @@ public PagedIterable listOrgMemberships(final GHMembership.State s * @throws IOException * the io exception */ - public GHMembership getMembership(GHOrganization o) throws IOException { + public GHMembership getMembership(GHOrganization o) { return root().createRequest() .withUrlPath("/user/memberships/orgs/" + o.getLogin()) .fetch(GHMembership.class) .wrap(root()); } - // public void addEmails(Collection emails) throws IOException { + // public void addEmails(Collection emails) { //// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails"); // root.retrieveWithAuth3() // } diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 7e62d7b6c6..41fa5e2884 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -226,7 +226,7 @@ private long calcNextCheckTime(GitHubResponse response) { * @throws IOException * the io exception */ - public void markAsRead() throws IOException { + public void markAsRead() { markAsRead(-1); } @@ -238,7 +238,7 @@ public void markAsRead() throws IOException { * @throws IOException * the io exception */ - public void markAsRead(long timestamp) throws IOException { + public void markAsRead(long timestamp) { final Requester req = root().createRequest(); if (timestamp >= 0) req.with("last_read_at", GitHubClient.printDate(new Date(timestamp))); diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 9d9b2f4fe0..516858ac88 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -78,7 +78,7 @@ public Map> getResponseHeaderFields() { * @throws IOException * on error */ - public Date getCreatedAt() throws IOException { + public Date getCreatedAt() { return GitHubClient.parseDate(createdAt); } @@ -98,7 +98,7 @@ public URL getUrl() { * @throws IOException * on error */ - public Date getUpdatedAt() throws IOException { + public Date getUpdatedAt() { return GitHubClient.parseDate(updatedAt); } diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 6d0e299330..df57b0e0be 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -47,7 +48,7 @@ public GHCreateRepositoryBuilder createRepository(String name) { * @throws IOException * the io exception */ - public Map getTeams() throws IOException { + public Map getTeams() { Map r = new TreeMap(); for (GHTeam t : listTeams()) { r.put(t.getName(), t); @@ -62,7 +63,7 @@ public Map getTeams() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listTeams() throws IOException { + public PagedIterable listTeams() { return root().createRequest() .withUrlPath(String.format("/orgs/%s/teams", login)) .toIterable(GHTeam[].class, item -> item.wrapUp(this)); @@ -78,7 +79,7 @@ public PagedIterable listTeams() throws IOException { * the io exception * @see documentation */ - public GHTeam getTeam(long teamId) throws IOException { + public GHTeam getTeam(long teamId) { return root().createRequest() .withUrlPath(String.format("/organizations/%d/team/%d", getId(), teamId)) .fetch(GHTeam.class) @@ -94,7 +95,7 @@ public GHTeam getTeam(long teamId) throws IOException { * @throws IOException * the io exception */ - public GHTeam getTeamByName(String name) throws IOException { + public GHTeam getTeamByName(String name) { for (GHTeam t : listTeams()) { if (t.getName().equals(name)) return t; @@ -112,7 +113,7 @@ public GHTeam getTeamByName(String name) throws IOException { * the io exception * @see documentation */ - public GHTeam getTeamBySlug(String slug) throws IOException { + public GHTeam getTeamBySlug(String slug) { return root().createRequest() .withUrlPath(String.format("/orgs/%s/teams/%s", login, slug)) .fetch(GHTeam.class) @@ -128,7 +129,7 @@ public GHTeam getTeamBySlug(String slug) throws IOException { * @see documentation */ - public PagedIterable listExternalGroups() throws IOException { + public PagedIterable listExternalGroups() { return listExternalGroups(null); } @@ -143,7 +144,7 @@ public PagedIterable listExternalGroups() throws IOException { * @see documentation */ - public PagedIterable listExternalGroups(final String displayName) throws IOException { + public PagedIterable listExternalGroups(final String displayName) { final Requester requester = root().createRequest() .withUrlPath(String.format("/orgs/%s/external-groups", login)); if (displayName != null) { @@ -163,16 +164,21 @@ public PagedIterable listExternalGroups(final String displayNam * @see documentation */ - public GHExternalGroup getExternalGroup(final long groupId) throws IOException { + public GHExternalGroup getExternalGroup(final long groupId) { try { return root().createRequest() .withUrlPath(String.format("/orgs/%s/external-group/%d", login, groupId)) .fetch(GHExternalGroup.class) .wrapUp(this); - } catch (final HttpException e) { - throw EnterpriseManagedSupport.forOrganization(this) - .filterException(e, "Could not retrieve organization external group") - .orElse(e); + } catch (final UncheckedIOException ue) { + if (HttpException.class.isInstance(ue.getCause())) { + HttpException e = (HttpException) ue.getCause(); + throw new UncheckedIOException(EnterpriseManagedSupport.forOrganization(this) + .filterException(e, "Could not retrieve organization external group") + .orElse(e)); + } else { + throw ue; + } } } @@ -199,7 +205,7 @@ public enum Role { * @see documentation */ - public void add(GHUser user, Role role) throws IOException { + public void add(GHUser user, Role role) { root().createRequest() .method("PUT") .with("role", role.name().toLowerCase()) @@ -218,7 +224,7 @@ public boolean hasMember(GHUser user) { try { root().createRequest().withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send(); return true; - } catch (IOException ignore) { + } catch (Exception ignore) { return false; } } @@ -237,7 +243,7 @@ public boolean hasMember(GHUser user) { * @see documentation */ - public GHMembership getMembership(String username) throws IOException { + public GHMembership getMembership(String username) { return root().createRequest() .withUrlPath("/orgs/" + login + "/memberships/" + username) .fetch(GHMembership.class); @@ -252,7 +258,7 @@ public GHMembership getMembership(String username) throws IOException { * @throws IOException * the io exception */ - public void remove(GHUser user) throws IOException { + public void remove(GHUser user) { root().createRequest().method("DELETE").withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send(); } @@ -267,7 +273,7 @@ public boolean hasPublicMember(GHUser user) { try { root().createRequest().withUrlPath("/orgs/" + login + "/public_members/" + user.getLogin()).send(); return true; - } catch (IOException ignore) { + } catch (Exception ignore) { return false; } } @@ -280,7 +286,7 @@ public boolean hasPublicMember(GHUser user) { * @throws IOException * the io exception */ - public void publicize(GHUser u) throws IOException { + public void publicize(GHUser u) { root().createRequest().method("PUT").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).send(); } @@ -291,7 +297,7 @@ public void publicize(GHUser u) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listMembers() throws IOException { + public PagedIterable listMembers() { return listMembers("members"); } @@ -302,7 +308,7 @@ public PagedIterable listMembers() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listPublicMembers() throws IOException { + public PagedIterable listPublicMembers() { return listMembers("public_members"); } @@ -313,11 +319,11 @@ public PagedIterable listPublicMembers() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listOutsideCollaborators() throws IOException { + public PagedIterable listOutsideCollaborators() { return listMembers("outside_collaborators"); } - private PagedIterable listMembers(String suffix) throws IOException { + private PagedIterable listMembers(String suffix) { return listMembers(suffix, null, null); } @@ -330,7 +336,7 @@ private PagedIterable listMembers(String suffix) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listMembersWithFilter(String filter) throws IOException { + public PagedIterable listMembersWithFilter(String filter) { return listMembers("members", filter, null); } @@ -343,7 +349,7 @@ public PagedIterable listMembersWithFilter(String filter) throws IOExcep * @throws IOException * the io exception */ - public PagedIterable listOutsideCollaboratorsWithFilter(String filter) throws IOException { + public PagedIterable listOutsideCollaboratorsWithFilter(String filter) { return listMembers("outside_collaborators", filter, null); } @@ -356,12 +362,11 @@ public PagedIterable listOutsideCollaboratorsWithFilter(String filter) t * @throws IOException * the io exception */ - public PagedIterable listMembersWithRole(String role) throws IOException { + public PagedIterable listMembersWithRole(String role) { return listMembers("members", null, role); } - private PagedIterable listMembers(final String suffix, final String filter, String role) - throws IOException { + private PagedIterable listMembers(final String suffix, final String filter, String role) { return root().createRequest() .withUrlPath(String.format("/orgs/%s/%s", login, suffix)) .with("filter", filter) @@ -376,7 +381,7 @@ private PagedIterable listMembers(final String suffix, final String filt * @throws IOException * the io exception */ - public PagedIterable listSecurityManagers() throws IOException { + public PagedIterable listSecurityManagers() { return root().createRequest() .withUrlPath(String.format("/orgs/%s/security-managers", login)) .toIterable(GHTeam[].class, item -> item.wrapUp(this)); @@ -390,7 +395,7 @@ public PagedIterable listSecurityManagers() throws IOException { * @throws IOException * the io exception */ - public void conceal(GHUser u) throws IOException { + public void conceal(GHUser u) { root().createRequest() .method("DELETE") .withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()) @@ -414,11 +419,11 @@ public boolean areOrganizationProjectsEnabled() { * @throws IOException * the io exception */ - public void enableOrganizationProjects(boolean newStatus) throws IOException { + public void enableOrganizationProjects(boolean newStatus) { edit("has_organization_projects", newStatus); } - private void edit(String key, Object value) throws IOException { + private void edit(String key, Object value) { root().createRequest() .withUrlPath(String.format("/orgs/%s", login)) .method("PATCH") @@ -435,7 +440,7 @@ private void edit(String key, Object value) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { + public PagedIterable listProjects(final GHProject.ProjectStateFilter status) { return root().createRequest() .with("state", status) .withUrlPath(String.format("/orgs/%s/projects", login)) @@ -449,7 +454,7 @@ public PagedIterable listProjects(final GHProject.ProjectStateFilter * @throws IOException * the io exception */ - public PagedIterable listProjects() throws IOException { + public PagedIterable listProjects() { return listProjects(GHProject.ProjectStateFilter.OPEN); } @@ -464,7 +469,7 @@ public PagedIterable listProjects() throws IOException { * @throws IOException * the io exception */ - public GHProject createProject(String name, String body) throws IOException { + public GHProject createProject(String name, String body) { return root().createRequest() .method("POST") .with("name", name) @@ -561,7 +566,7 @@ public GHTeamBuilder createTeam(String name) { * @throws IOException * the io exception */ - public List getRepositoriesWithOpenPullRequests() throws IOException { + public List getRepositoriesWithOpenPullRequests() { List r = new ArrayList(); for (GHRepository repository : listRepositories().withPageSize(100)) { List pullRequests = repository.queryPullRequests().state(GHIssueState.OPEN).list().toList(); @@ -579,7 +584,7 @@ public List getRepositoriesWithOpenPullRequests() throws IOExcepti * @throws IOException * the io exception */ - public List getPullRequests() throws IOException { + public List getPullRequests() { List all = new ArrayList(); for (GHRepository r : getRepositoriesWithOpenPullRequests()) { all.addAll(r.queryPullRequests().state(GHIssueState.OPEN).list().toList()); @@ -594,7 +599,7 @@ public List getPullRequests() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public PagedIterable listEvents() throws IOException { + public PagedIterable listEvents() { return root().createRequest() .withUrlPath(String.format("/orgs/%s/events", login)) .toIterable(GHEventInfo[].class, null); @@ -620,7 +625,7 @@ public PagedIterable listRepositories() { * @throws IOException * the io exception */ - public List getHooks() throws IOException { + public List getHooks() { return GHHooks.orgContext(this).getHooks(); } @@ -633,7 +638,7 @@ public List getHooks() throws IOException { * @throws IOException * the io exception */ - public GHHook getHook(int id) throws IOException { + public GHHook getHook(int id) { return GHHooks.orgContext(this).getHook(id); } @@ -645,7 +650,7 @@ public GHHook getHook(int id) throws IOException { * @throws IOException * the io exception */ - public void deleteHook(int id) throws IOException { + public void deleteHook(int id) { GHHooks.orgContext(this).deleteHook(id); } @@ -665,8 +670,7 @@ public void deleteHook(int id) throws IOException { * @throws IOException * the io exception */ - public GHHook createHook(String name, Map config, Collection events, boolean active) - throws IOException { + public GHHook createHook(String name, Map config, Collection events, boolean active) { return GHHooks.orgContext(this).createHook(name, config, events, active); } @@ -681,7 +685,7 @@ public GHHook createHook(String name, Map config, Collection events) throws IOException { + public GHHook createWebHook(URL url, Collection events) { return createHook("web", Collections.singletonMap("url", url.toExternalForm()), events, true); } @@ -694,7 +698,7 @@ public GHHook createWebHook(URL url, Collection events) throws IOExcept * @throws IOException * the io exception */ - public GHHook createWebHook(URL url) throws IOException { + public GHHook createWebHook(URL url) { return createWebHook(url, null); } } diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 175883b3b3..29f481a42b 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -2,6 +2,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; import java.util.Collections; import java.util.Date; @@ -52,7 +53,7 @@ public GHPerson() { * @throws IOException * the io exception */ - protected synchronized void populate() throws IOException { + protected synchronized void populate() { if (super.getCreatedAt() != null) { return; // already populated } @@ -75,7 +76,7 @@ protected synchronized void populate() throws IOException { * @throws IOException * the io exception */ - public synchronized Map getRepositories() throws IOException { + public synchronized Map getRepositories() { Map repositories = new TreeMap(); for (GHRepository r : listRepositories().withPageSize(100)) { repositories.put(r.getName(), r); @@ -120,11 +121,14 @@ public PagedIterable listRepositories(final int pageSize) { * @throws IOException * the io exception */ - public GHRepository getRepository(String name) throws IOException { + public GHRepository getRepository(String name) { try { return GHRepository.read(root(), login, name); - } catch (FileNotFoundException e) { - return null; + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -162,7 +166,7 @@ public String getLogin() { * @throws IOException * the io exception */ - public String getName() throws IOException { + public String getName() { populate(); return name; } @@ -174,7 +178,7 @@ public String getName() throws IOException { * @throws IOException * the io exception */ - public String getCompany() throws IOException { + public String getCompany() { populate(); return company; } @@ -186,7 +190,7 @@ public String getCompany() throws IOException { * @throws IOException * the io exception */ - public String getLocation() throws IOException { + public String getLocation() { populate(); return location; } @@ -198,7 +202,7 @@ public String getLocation() throws IOException { * @throws IOException * the io exception */ - public String getTwitterUsername() throws IOException { + public String getTwitterUsername() { populate(); return twitter_username; } @@ -210,7 +214,7 @@ public String getTwitterUsername() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public Date getCreatedAt() throws IOException { + public Date getCreatedAt() { populate(); return super.getCreatedAt(); } @@ -222,7 +226,7 @@ public Date getCreatedAt() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public Date getUpdatedAt() throws IOException { + public Date getUpdatedAt() { populate(); return super.getUpdatedAt(); } @@ -234,7 +238,7 @@ public Date getUpdatedAt() throws IOException { * @throws IOException * the io exception */ - public String getBlog() throws IOException { + public String getBlog() { populate(); return blog; } @@ -255,7 +259,7 @@ public URL getHtmlUrl() { * @throws IOException * the io exception */ - public String getEmail() throws IOException { + public String getEmail() { populate(); return email; } @@ -267,7 +271,7 @@ public String getEmail() throws IOException { * @throws IOException * the io exception */ - public int getPublicGistCount() throws IOException { + public int getPublicGistCount() { populate(); return public_gists; } @@ -279,7 +283,7 @@ public int getPublicGistCount() throws IOException { * @throws IOException * the io exception */ - public int getPublicRepoCount() throws IOException { + public int getPublicRepoCount() { populate(); return public_repos; } @@ -291,7 +295,7 @@ public int getPublicRepoCount() throws IOException { * @throws IOException * the io exception */ - public int getFollowingCount() throws IOException { + public int getFollowingCount() { populate(); return following; } @@ -303,7 +307,7 @@ public int getFollowingCount() throws IOException { * @throws IOException * the io exception */ - public int getFollowersCount() throws IOException { + public int getFollowersCount() { populate(); return followers; } @@ -315,7 +319,7 @@ public int getFollowersCount() throws IOException { * @throws IOException * the io exception */ - public String getType() throws IOException { + public String getType() { populate(); return type; } @@ -327,7 +331,7 @@ public String getType() throws IOException { * @throws IOException * the io exception */ - public boolean isSiteAdmin() throws IOException { + public boolean isSiteAdmin() { populate(); return site_admin; } @@ -339,7 +343,7 @@ public boolean isSiteAdmin() throws IOException { * @throws IOException * the io exception */ - public Optional getTotalPrivateRepoCount() throws IOException { + public Optional getTotalPrivateRepoCount() { populate(); return Optional.ofNullable(total_private_repos); } diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index 3d0ebdd489..b01d0af342 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -27,6 +27,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; import java.util.Locale; @@ -63,7 +64,7 @@ public GHProject() { * @throws IOException * Signals that an I/O exception has occurred. */ - public URL getHtmlUrl() throws IOException { + public URL getHtmlUrl() { return GitHubClient.parseURL(html_url); } @@ -75,7 +76,7 @@ public URL getHtmlUrl() throws IOException { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHObject getOwner() throws IOException { + public GHObject getOwner() { if (owner == null) { try { if (owner_url.contains("/orgs/")) { @@ -86,8 +87,11 @@ public GHObject getOwner() throws IOException { String[] pathElements = getOwnerUrl().getPath().split("/"); owner = GHRepository.read(root(), pathElements[1], pathElements[2]); } - } catch (FileNotFoundException e) { - return null; + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } return owner; @@ -160,7 +164,7 @@ GHProject lateBind(GHRepository repo) { return this; } - private void edit(String key, Object value) throws IOException { + private void edit(String key, Object value) { root().createRequest().method("PATCH").with(key, value).withUrlPath(getApiRoute()).send(); } @@ -181,7 +185,7 @@ protected String getApiRoute() { * @throws IOException * the io exception */ - public void setName(String name) throws IOException { + public void setName(String name) { edit("name", name); } @@ -193,7 +197,7 @@ public void setName(String name) throws IOException { * @throws IOException * the io exception */ - public void setBody(String body) throws IOException { + public void setBody(String body) { edit("body", body); } @@ -216,7 +220,7 @@ public enum ProjectState { * @throws IOException * the io exception */ - public void setState(ProjectState state) throws IOException { + public void setState(ProjectState state) { edit("state", state.toString().toLowerCase()); } @@ -242,7 +246,7 @@ public static enum ProjectStateFilter { * @throws IOException * the io exception */ - public void setOrganizationPermission(GHPermissionType permission) throws IOException { + public void setOrganizationPermission(GHPermissionType permission) { edit("organization_permission", permission.toString().toLowerCase()); } @@ -254,7 +258,7 @@ public void setOrganizationPermission(GHPermissionType permission) throws IOExce * @throws IOException * the io exception */ - public void setPublic(boolean isPublic) throws IOException { + public void setPublic(boolean isPublic) { edit("public", isPublic); } @@ -264,7 +268,7 @@ public void setPublic(boolean isPublic) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -275,7 +279,7 @@ public void delete() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listColumns() throws IOException { + public PagedIterable listColumns() { final GHProject project = this; return root().createRequest() .withUrlPath(String.format("/projects/%d/columns", getId())) @@ -291,7 +295,7 @@ public PagedIterable listColumns() throws IOException { * @throws IOException * the io exception */ - public GHProjectColumn createColumn(String name) throws IOException { + public GHProjectColumn createColumn(String name) { return root().createRequest() .method("POST") .with("name", name) diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index ddfba5c152..3b5a46740e 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; // TODO: Auto-generated Javadoc @@ -36,7 +37,7 @@ public GHProjectCard() { * @throws IOException * Signals that an I/O exception has occurred. */ - public URL getHtmlUrl() throws IOException { + public URL getHtmlUrl() { return null; } @@ -72,11 +73,15 @@ GHProjectCard lateBind(GHProjectColumn column) { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHProject getProject() throws IOException { + public GHProject getProject() { if (project == null) { try { project = root().createRequest().withUrlPath(getProjectUrl().getPath()).fetch(GHProject.class); - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + // no-op + } + throw e; } } return project; @@ -90,15 +95,20 @@ public GHProject getProject() throws IOException { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHProjectColumn getColumn() throws IOException { + public GHProjectColumn getColumn() { if (column == null) { try { column = root().createRequest() .withUrlPath(getColumnUrl().getPath()) .fetch(GHProjectColumn.class) .lateBind(root()); - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + // no-op + } + throw e; } + } return column; } @@ -110,7 +120,7 @@ public GHProjectColumn getColumn() throws IOException { * @throws IOException * the io exception */ - public GHIssue getContent() throws IOException { + public GHIssue getContent() { if (StringUtils.isEmpty(content_url)) return null; try { @@ -119,8 +129,11 @@ public GHIssue getContent() throws IOException { } else { return root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class); } - } catch (FileNotFoundException e) { - return null; + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -187,7 +200,7 @@ public boolean isArchived() { * @throws IOException * the io exception */ - public void setNote(String note) throws IOException { + public void setNote(String note) { edit("note", note); } @@ -199,11 +212,11 @@ public void setNote(String note) throws IOException { * @throws IOException * the io exception */ - public void setArchived(boolean archived) throws IOException { + public void setArchived(boolean archived) { edit("archived", archived); } - private void edit(String key, Object value) throws IOException { + private void edit(String key, Object value) { root().createRequest().method("PATCH").with(key, value).withUrlPath(getApiRoute()).send(); } @@ -222,7 +235,7 @@ protected String getApiRoute() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index 5af7afec7a..d621a54b21 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -4,6 +4,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; // TODO: Auto-generated Javadoc @@ -57,11 +58,14 @@ GHProjectColumn lateBind(GHProject project) { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHProject getProject() throws IOException { + public GHProject getProject() { if (project == null) { try { project = root().createRequest().withUrlPath(getProjectUrl().getPath()).fetch(GHProject.class); - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + } + throw e; } } return project; @@ -93,11 +97,11 @@ public URL getProjectUrl() { * @throws IOException * the io exception */ - public void setName(String name) throws IOException { + public void setName(String name) { edit("name", name); } - private void edit(String key, Object value) throws IOException { + private void edit(String key, Object value) { root().createRequest().method("PATCH").with(key, value).withUrlPath(getApiRoute()).send(); } @@ -116,7 +120,7 @@ protected String getApiRoute() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -127,7 +131,7 @@ public void delete() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listCards() throws IOException { + public PagedIterable listCards() { final GHProjectColumn column = this; return root().createRequest() .withUrlPath(String.format("/projects/columns/%d/cards", getId())) @@ -143,7 +147,7 @@ public PagedIterable listCards() throws IOException { * @throws IOException * the io exception */ - public GHProjectCard createCard(String note) throws IOException { + public GHProjectCard createCard(String note) { return root().createRequest() .method("POST") .with("note", note) @@ -161,7 +165,7 @@ public GHProjectCard createCard(String note) throws IOException { * @throws IOException * the io exception */ - public GHProjectCard createCard(GHIssue issue) throws IOException { + public GHProjectCard createCard(GHIssue issue) { String contentType = issue instanceof GHPullRequest ? "PullRequest" : "Issue"; return root().createRequest() .method("POST") diff --git a/src/main/java/org/kohsuke/github/GHProjectsV2Item.java b/src/main/java/org/kohsuke/github/GHProjectsV2Item.java index 43d0224489..0efc12ebe5 100644 --- a/src/main/java/org/kohsuke/github/GHProjectsV2Item.java +++ b/src/main/java/org/kohsuke/github/GHProjectsV2Item.java @@ -70,7 +70,7 @@ public ContentType getContentType() { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHUser getCreator() throws IOException { + public GHUser getCreator() { return root().intern(creator); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index a355b07a12..ffb6abef6a 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -206,7 +206,7 @@ public PullRequest getPullRequest() { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHUser getMergedBy() throws IOException { + public GHUser getMergedBy() { populate(); return merged_by; } @@ -218,7 +218,7 @@ public GHUser getMergedBy() throws IOException { * @throws IOException * the io exception */ - public int getReviewComments() throws IOException { + public int getReviewComments() { populate(); return review_comments; } @@ -230,7 +230,7 @@ public int getReviewComments() throws IOException { * @throws IOException * the io exception */ - public int getAdditions() throws IOException { + public int getAdditions() { populate(); return additions; } @@ -242,7 +242,7 @@ public int getAdditions() throws IOException { * @throws IOException * the io exception */ - public int getCommits() throws IOException { + public int getCommits() { populate(); return commits; } @@ -254,7 +254,7 @@ public int getCommits() throws IOException { * @throws IOException * the io exception */ - public boolean isMerged() throws IOException { + public boolean isMerged() { populate(); return merged; } @@ -266,7 +266,7 @@ public boolean isMerged() throws IOException { * @throws IOException * the io exception */ - public boolean canMaintainerModify() throws IOException { + public boolean canMaintainerModify() { populate(); return maintainer_can_modify; } @@ -278,7 +278,7 @@ public boolean canMaintainerModify() throws IOException { * @throws IOException * the io exception */ - public boolean isDraft() throws IOException { + public boolean isDraft() { populate(); return draft; } @@ -292,8 +292,8 @@ public boolean isDraft() throws IOException { * @throws IOException * the io exception */ - public Boolean getMergeable() throws IOException { - refresh(mergeable); + public Boolean getMergeable() { + refreshWithUnchecked(mergeable); return mergeable; } @@ -313,7 +313,7 @@ Boolean getMergeableNoRefresh() { * @throws IOException * the io exception */ - public int getDeletions() throws IOException { + public int getDeletions() { populate(); return deletions; } @@ -325,7 +325,7 @@ public int getDeletions() throws IOException { * @throws IOException * the io exception */ - public String getMergeableState() throws IOException { + public String getMergeableState() { populate(); return mergeable_state; } @@ -337,7 +337,7 @@ public String getMergeableState() throws IOException { * @throws IOException * the io exception */ - public int getChangedFiles() throws IOException { + public int getChangedFiles() { populate(); return changed_files; } @@ -349,7 +349,7 @@ public int getChangedFiles() throws IOException { * @throws IOException * the io exception */ - public String getMergeCommitSha() throws IOException { + public String getMergeCommitSha() { populate(); return merge_commit_sha; } @@ -361,8 +361,8 @@ public String getMergeCommitSha() throws IOException { * @throws IOException * the io exception */ - public List getRequestedReviewers() throws IOException { - refresh(requested_reviewers); + public List getRequestedReviewers() { + refreshWithUnchecked(requested_reviewers); return Collections.unmodifiableList(Arrays.asList(requested_reviewers)); } @@ -373,8 +373,8 @@ public List getRequestedReviewers() throws IOException { * @throws IOException * the io exception */ - public List getRequestedTeams() throws IOException { - refresh(requested_teams); + public List getRequestedTeams() { + refreshWithUnchecked(requested_teams); return Collections.unmodifiableList(Arrays.asList(requested_teams)); } @@ -384,10 +384,8 @@ public List getRequestedTeams() throws IOException { *

* Depending on the original API call where this object is created, it may not contain everything. */ - private void populate() throws IOException { - if (mergeable_state != null) - return; // already populated - refresh(); + private void populate() { + refreshWithUnchecked(mergeable_state); } /** @@ -396,7 +394,7 @@ private void populate() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public void refresh() throws IOException { + public void refresh() { if (isOffline()) { return; // cannot populate, will have to live with what we have } @@ -439,7 +437,7 @@ public PagedIterable listReviews() { * @throws IOException * the io exception */ - public PagedIterable listReviewComments() throws IOException { + public PagedIterable listReviewComments() { return root().createRequest() .withUrlPath(getApiRoute() + COMMENTS_ACTION) .toIterable(GHPullRequestReviewComment[].class, item -> item.wrapUp(this)); @@ -491,8 +489,7 @@ public GHPullRequestReviewCommentBuilder createReviewComment() { * @deprecated use {@link #createReviewComment()} */ @Deprecated - public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) - throws IOException { + public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) { return createReviewComment().body(body).commitId(sha).path(path).position(position).create(); } @@ -504,7 +501,7 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S * @throws IOException * the io exception */ - public void requestReviewers(List reviewers) throws IOException { + public void requestReviewers(List reviewers) { root().createRequest() .method("POST") .with("reviewers", getLogins(reviewers)) @@ -520,7 +517,7 @@ public void requestReviewers(List reviewers) throws IOException { * @throws IOException * the io exception */ - public void requestTeamReviewers(List teams) throws IOException { + public void requestTeamReviewers(List teams) { List teamReviewers = new ArrayList(teams.size()); for (GHTeam team : teams) { teamReviewers.add(team.getSlug()); @@ -541,7 +538,7 @@ public void requestTeamReviewers(List teams) throws IOException { * @throws IOException * the io exception */ - public GHPullRequest setBaseBranch(String newBaseBranch) throws IOException { + public GHPullRequest setBaseBranch(String newBaseBranch) { return root().createRequest() .method("PATCH") .with("base", newBaseBranch) @@ -555,7 +552,7 @@ public GHPullRequest setBaseBranch(String newBaseBranch) throws IOException { * @throws IOException * the io exception */ - public void updateBranch() throws IOException { + public void updateBranch() { root().createRequest() .method("PUT") .with("expected_head_sha", head.getSha()) @@ -574,7 +571,7 @@ public void updateBranch() throws IOException { * @throws IOException * the io exception */ - public void merge(String msg) throws IOException { + public void merge(String msg) { merge(msg, null); } @@ -591,7 +588,7 @@ public void merge(String msg) throws IOException { * @throws IOException * the io exception */ - public void merge(String msg, String sha) throws IOException { + public void merge(String msg, String sha) { merge(msg, sha, null); } @@ -610,7 +607,7 @@ public void merge(String msg, String sha) throws IOException { * @throws IOException * the io exception */ - public void merge(String msg, String sha, MergeMethod method) throws IOException { + public void merge(String msg, String sha, MergeMethod method) { root().createRequest() .method("PUT") .with("commit_message", msg) diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index be5bbdc062..c05204ff60 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -95,7 +95,7 @@ public String getBody() { * @throws IOException * the io exception */ - public GHUser getUser() throws IOException { + public GHUser getUser() { if (user != null) { return owner.root().getUser(user.getLogin()); } @@ -146,7 +146,7 @@ protected String getApiRoute() { * @throws IOException * the io exception */ - public Date getSubmittedAt() throws IOException { + public Date getSubmittedAt() { return GitHubClient.parseDate(submitted_at); } @@ -158,7 +158,7 @@ public Date getSubmittedAt() throws IOException { * Signals that an I/O exception has occurred. */ @Override - public Date getCreatedAt() throws IOException { + public Date getCreatedAt() { return getSubmittedAt(); } @@ -172,7 +172,7 @@ public Date getCreatedAt() throws IOException { * @throws IOException * the io exception */ - public void submit(String body, GHPullRequestReviewEvent event) throws IOException { + public void submit(String body, GHPullRequestReviewEvent event) { owner.root() .createRequest() .method("POST") @@ -190,7 +190,7 @@ public void submit(String body, GHPullRequestReviewEvent event) throws IOExcepti * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { owner.root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -202,7 +202,7 @@ public void delete() throws IOException { * @throws IOException * the io exception */ - public void dismiss(String message) throws IOException { + public void dismiss(String message) { owner.root() .createRequest() .method("PUT") @@ -219,7 +219,7 @@ public void dismiss(String message) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listReviewComments() throws IOException { + public PagedIterable listReviewComments() { return owner.root() .createRequest() .withUrlPath(getApiRoute() + "/comments") diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index c536dbfdc3..aa36014277 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -129,7 +129,7 @@ public GHPullRequestReviewBuilder singleLineComment(String body, String path, in * @throws IOException * the io exception */ - public GHPullRequestReview create() throws IOException { + public GHPullRequestReview create() { return builder.method("POST") .with("comments", comments) .withUrlPath(pr.getApiRoute() + "/reviews") diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 6c5e1a6808..4b732ebc1c 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -112,7 +112,7 @@ public String getBody() { * @throws IOException * the io exception */ - public GHUser getUser() throws IOException { + public GHUser getUser() { return owner.root().getUser(user.getLogin()); } @@ -353,7 +353,7 @@ public static Side from(String value) { * @throws IOException * the io exception */ - public void update(String body) throws IOException { + public void update(String body) { owner.root().createRequest().method("PATCH").with("body", body).withUrlPath(getApiRoute()).fetchInto(this); this.body = body; } @@ -364,7 +364,7 @@ public void update(String body) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { owner.root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -377,7 +377,7 @@ public void delete() throws IOException { * @throws IOException * the io exception */ - public GHPullRequestReviewComment reply(String body) throws IOException { + public GHPullRequestReviewComment reply(String body) { return owner.root() .createRequest() .method("POST") @@ -396,7 +396,7 @@ public GHPullRequestReviewComment reply(String body) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHReaction createReaction(ReactionContent content) throws IOException { + public GHReaction createReaction(ReactionContent content) { return owner.root() .createRequest() .method("POST") @@ -413,7 +413,7 @@ public GHReaction createReaction(ReactionContent content) throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public void deleteReaction(GHReaction reaction) throws IOException { + public void deleteReaction(GHReaction reaction) { owner.root() .createRequest() .method("DELETE") diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java index a3b267c9f9..4a9194423f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java @@ -117,7 +117,7 @@ public GHPullRequestReviewCommentBuilder lines(int startLine, int endLine) { * @throws IOException * the io exception */ - public GHPullRequestReviewComment create() throws IOException { + public GHPullRequestReviewComment create() { return builder.method("POST") .withUrlPath(pr.getApiRoute() + "/comments") .fetch(GHPullRequestReviewComment.class) diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 4db5e1c67b..0cf2a15170 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -4,6 +4,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; // TODO: Auto-generated Javadoc @@ -58,7 +59,7 @@ public GHObject getObject() { * @throws IOException * the io exception */ - public void updateTo(String sha) throws IOException { + public void updateTo(String sha) { updateTo(sha, false); } @@ -72,7 +73,7 @@ public void updateTo(String sha) throws IOException { * @throws IOException * the io exception */ - public void updateTo(String sha, Boolean force) throws IOException { + public void updateTo(String sha, Boolean force) { root().createRequest() .method("PATCH") .with("sha", sha) @@ -87,7 +88,7 @@ public void updateTo(String sha, Boolean force) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(url).send(); } @@ -102,7 +103,7 @@ public void delete() throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ - static GHRef read(GHRepository repository, String refName) throws IOException { + static GHRef read(GHRepository repository, String refName) { // Also accept e.g. "refs/heads/branch" for consistency with createRef(). if (refName.startsWith("refs/")) { refName = refName.replaceFirst("refs/", ""); @@ -116,11 +117,11 @@ static GHRef read(GHRepository repository, String refName) throws IOException { .createRequest() .withUrlPath(repository.getApiTailUrl(String.format("git/refs/%s", refName))) .fetch(GHRef.class); - } catch (IOException e) { + } catch (UncheckedIOException e) { // If the parse exception is due to the above returning an array instead of a single ref // that means the individual ref did not exist. Handled by result check below. // Otherwise, rethrow. - if (!(e.getCause() instanceof JsonMappingException)) { + if (!(e.getCause().getCause() instanceof JsonMappingException)) { throw e; } } @@ -131,8 +132,8 @@ static GHRef read(GHRepository repository, String refName) throws IOException { // the same for this scenario - the server refs matching is prefix-based, so // a ref that ends with the correct string will always be the correct one. if (result == null || !result.getRef().endsWith(refName)) { - throw new GHFileNotFoundException(String.format("git/refs/%s", refName) - + " {\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/git/refs/#get-a-reference\"}"); + throw new UncheckedIOException(new GHFileNotFoundException(String.format("git/refs/%s", refName) + + " {\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/git/refs/#get-a-reference\"}")); } return result; } @@ -148,7 +149,7 @@ static GHRef read(GHRepository repository, String refName) throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ - static PagedIterable readMatching(GHRepository repository, String refType) throws IOException { + static PagedIterable readMatching(GHRepository repository, String refType) { if (refType.startsWith("refs/")) { refType = refType.replaceFirst("refs/", ""); } diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 1c6c82851d..d91b286a55 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -6,6 +6,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.net.URL; import java.net.URLEncoder; import java.util.Collections; @@ -226,12 +227,16 @@ static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) { * @throws IOException * the io exception */ - public GHAsset uploadAsset(File file, String contentType) throws IOException { - FileInputStream s = new FileInputStream(file); + public GHAsset uploadAsset(File file, String contentType) { try { - return uploadAsset(file.getName(), s, contentType); - } finally { - s.close(); + FileInputStream s = new FileInputStream(file); + try { + return uploadAsset(file.getName(), s, contentType); + } finally { + s.close(); + } + } catch (IOException e) { + throw new UncheckedIOException(e); } } @@ -248,16 +253,20 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { * @throws IOException * the io exception */ - public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { - Requester builder = owner.root().createRequest().method("POST"); - String url = getUploadUrl(); - // strip the helpful garbage from the url - int endIndex = url.indexOf('{'); - if (endIndex != -1) { - url = url.substring(0, endIndex); + public GHAsset uploadAsset(String filename, InputStream stream, String contentType) { + try { + Requester builder = owner.root().createRequest().method("POST"); + String url = getUploadUrl(); + // strip the helpful garbage from the url + int endIndex = url.indexOf('{'); + if (endIndex != -1) { + url = url.substring(0, endIndex); + } + url += "?name=" + URLEncoder.encode(filename, "UTF-8"); + return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this); + } catch (IOException e) { + throw new UncheckedIOException(e); } - url += "?name=" + URLEncoder.encode(filename, "UTF-8"); - return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this); } /** @@ -285,7 +294,7 @@ public PagedIterable listAssets() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(owner.getApiTailUrl("releases/" + getId())).send(); } diff --git a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java index 9b2b4a4f0b..87bd017c99 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java +++ b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java @@ -159,7 +159,7 @@ public GHReleaseBuilder makeLatest(MakeLatest latest) { * @throws IOException * the io exception */ - public GHRelease create() throws IOException { + public GHRelease create() { return builder.withUrlPath(repo.getApiTailUrl("releases")).fetch(GHRelease.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index 83113412d8..5b5e604473 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -129,7 +129,7 @@ public GHReleaseUpdater makeLatest(GHReleaseBuilder.MakeLatest latest) { * @throws IOException * the io exception */ - public GHRelease update() throws IOException { + public GHRelease update() { return builder.method("PATCH") .withUrlPath(base.owner.getApiTailUrl("releases/" + base.getId())) .fetch(GHRelease.class) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 305dadcf7a..425ee5eda9 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -37,6 +37,7 @@ import java.io.InputStreamReader; import java.io.InterruptedIOException; import java.io.Reader; +import java.io.UncheckedIOException; import java.net.URL; import java.util.Arrays; import java.util.Collection; @@ -140,7 +141,7 @@ public GHRepository() { * @throws IOException * Signals that an I/O exception has occurred. */ - static GHRepository read(GitHub root, String owner, String name) throws IOException { + static GHRepository read(GitHub root, String owner, String name) { return root.createRequest().withUrlPath("/repos/" + owner + '/' + name).fetch(GHRepository.class); } @@ -187,7 +188,7 @@ public PagedIterable listDeployments(String sha, String ref, Strin * @throws IOException * the io exception */ - public GHDeployment getDeployment(long id) throws IOException { + public GHDeployment getDeployment(long id) { return root().createRequest() .withUrlPath(getApiTailUrl("deployments/" + id)) .fetch(GHDeployment.class) @@ -343,7 +344,7 @@ public String getLanguage() { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHUser getOwner() throws IOException { + public GHUser getOwner() { return isOffline() ? owner : root().getUser(getOwnerName()); // because 'owner' isn't fully populated } @@ -356,7 +357,7 @@ public GHUser getOwner() throws IOException { * @throws IOException * the io exception */ - public GHIssue getIssue(int id) throws IOException { + public GHIssue getIssue(int id) { return root().createRequest().withUrlPath(getApiTailUrl("issues/" + id)).fetch(GHIssue.class).wrap(this); } @@ -380,7 +381,7 @@ public GHIssueBuilder createIssue(String title) { * @throws IOException * the io exception */ - public List getIssues(GHIssueState state) throws IOException { + public List getIssues(GHIssueState state) { return queryIssues().state(state).list().toList(); } @@ -395,7 +396,7 @@ public List getIssues(GHIssueState state) throws IOException { * @throws IOException * the io exception */ - public List getIssues(GHIssueState state, GHMilestone milestone) throws IOException { + public List getIssues(GHIssueState state, GHMilestone milestone) { return queryIssues().milestone(milestone == null ? "none" : "" + milestone.getNumber()) .state(state) .list() @@ -434,7 +435,7 @@ public GHReleaseBuilder createRelease(String tag) { * @throws IOException * the io exception */ - public GHRef createRef(String name, String sha) throws IOException { + public GHRef createRef(String name, String sha) { return root().createRequest() .method("POST") .with("ref", name) @@ -452,14 +453,17 @@ public GHRef createRef(String name, String sha) throws IOException { * @throws IOException * the io exception */ - public GHRelease getRelease(long id) throws IOException { + public GHRelease getRelease(long id) { try { return root().createRequest() .withUrlPath(getApiTailUrl("releases/" + id)) .fetch(GHRelease.class) .wrap(this); - } catch (FileNotFoundException e) { - return null; // no release for this id + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -472,14 +476,17 @@ public GHRelease getRelease(long id) throws IOException { * @throws IOException * the io exception */ - public GHRelease getReleaseByTagName(String tag) throws IOException { + public GHRelease getReleaseByTagName(String tag) { try { return root().createRequest() .withUrlPath(getApiTailUrl("releases/tags/" + tag)) .fetch(GHRelease.class) .wrap(this); - } catch (FileNotFoundException e) { - return null; // no release for this tag + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -490,14 +497,17 @@ public GHRelease getReleaseByTagName(String tag) throws IOException { * @throws IOException * the io exception */ - public GHRelease getLatestRelease() throws IOException { + public GHRelease getLatestRelease() { try { return root().createRequest() .withUrlPath(getApiTailUrl("releases/latest")) .fetch(GHRelease.class) .wrap(this); - } catch (FileNotFoundException e) { - return null; // no latest release + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -508,7 +518,7 @@ public GHRelease getLatestRelease() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listReleases() throws IOException { + public PagedIterable listReleases() { return root().createRequest() .withUrlPath(getApiTailUrl("releases")) .toIterable(GHRelease[].class, item -> item.wrap(this)); @@ -521,7 +531,7 @@ public PagedIterable listReleases() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listTags() throws IOException { + public PagedIterable listTags() { return root().createRequest() .withUrlPath(getApiTailUrl("tags")) .toIterable(GHTag[].class, item -> item.wrap(this)); @@ -535,7 +545,7 @@ public PagedIterable listTags() throws IOException { * @throws IOException * the io exception */ - public Map listLanguages() throws IOException { + public Map listLanguages() { HashMap result = new HashMap<>(); root().createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class).forEach((key, value) -> { Long addValue = -1L; @@ -743,9 +753,9 @@ public Visibility getVisibility() { if (visibility == null) { try { populate(); - } catch (final IOException e) { + } catch (final UncheckedIOException e) { // Convert this to a runtime exception to avoid messy method signature - throw new GHException("Could not populate the visibility of the repository", e); + throw new GHException("Could not populate the visibility of the repository", e.getCause()); } } return Visibility.from(visibility); @@ -760,9 +770,9 @@ public boolean isTemplate() { if (isTemplate == null) { try { populate(); - } catch (IOException e) { + } catch (UncheckedIOException e) { // Convert this to a runtime exception to avoid messy method signature - throw new GHException("Could not populate the template setting of the repository", e); + throw new GHException("Could not populate the template setting of the repository", e.getCause()); } // if this somehow is not populated, set it to false; isTemplate = Boolean.TRUE.equals(isTemplate); @@ -872,7 +882,7 @@ public enum CollaboratorAffiliation { * @throws IOException * the io exception */ - public GHPersonSet getCollaborators() throws IOException { + public GHPersonSet getCollaborators() { return new GHPersonSet(listCollaborators().toList()); } @@ -883,7 +893,7 @@ public GHPersonSet getCollaborators() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listCollaborators() throws IOException { + public PagedIterable listCollaborators() { return listUsers("collaborators"); } @@ -896,7 +906,7 @@ public PagedIterable listCollaborators() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listCollaborators(CollaboratorAffiliation affiliation) throws IOException { + public PagedIterable listCollaborators(CollaboratorAffiliation affiliation) { return listUsers(root().createRequest().with("affiliation", affiliation), "collaborators"); } @@ -909,7 +919,7 @@ public PagedIterable listCollaborators(CollaboratorAffiliation affiliati * @throws IOException * the io exception */ - public PagedIterable listAssignees() throws IOException { + public PagedIterable listAssignees() { return listUsers("assignees"); } @@ -922,7 +932,7 @@ public PagedIterable listAssignees() throws IOException { * @throws IOException * the io exception */ - public boolean hasAssignee(GHUser u) throws IOException { + public boolean hasAssignee(GHUser u) { return root().createRequest().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).fetchHttpStatusCode() / 100 == 2; } @@ -935,7 +945,7 @@ public boolean hasAssignee(GHUser u) throws IOException { * @throws IOException * the io exception */ - public Set getCollaboratorNames() throws IOException { + public Set getCollaboratorNames() { Set r = new HashSet<>(); // no initializer - we just want to the logins PagedIterable users = root().createRequest() @@ -957,7 +967,7 @@ public Set getCollaboratorNames() throws IOException { * @throws IOException * the io exception */ - public Set getCollaboratorNames(CollaboratorAffiliation affiliation) throws IOException { + public Set getCollaboratorNames(CollaboratorAffiliation affiliation) { Set r = new HashSet<>(); // no initializer - we just want to the logins PagedIterable users = root().createRequest() @@ -979,7 +989,7 @@ public Set getCollaboratorNames(CollaboratorAffiliation affiliation) thr * @throws IOException * the io exception */ - public boolean isCollaborator(GHUser user) throws IOException { + public boolean isCollaborator(GHUser user) { return root().createRequest() .withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())) .fetchHttpStatusCode() == 204; @@ -994,7 +1004,7 @@ public boolean isCollaborator(GHUser user) throws IOException { * @throws IOException * the io exception */ - public GHPermissionType getPermission(String user) throws IOException { + public GHPermissionType getPermission(String user) { GHPermission perm = root().createRequest() .withUrlPath(getApiTailUrl("collaborators/" + user + "/permission")) .fetch(GHPermission.class); @@ -1010,7 +1020,7 @@ public GHPermissionType getPermission(String user) throws IOException { * @throws IOException * the io exception */ - public GHPermissionType getPermission(GHUser u) throws IOException { + public GHPermissionType getPermission(GHUser u) { return getPermission(u.getLogin()); } @@ -1025,7 +1035,7 @@ public GHPermissionType getPermission(GHUser u) throws IOException { * @throws IOException * the io exception */ - public boolean hasPermission(String user, GHPermissionType permission) throws IOException { + public boolean hasPermission(String user, GHPermissionType permission) { return getPermission(user).implies(permission); } @@ -1040,7 +1050,7 @@ public boolean hasPermission(String user, GHPermissionType permission) throws IO * @throws IOException * the io exception */ - public boolean hasPermission(GHUser user, GHPermissionType permission) throws IOException { + public boolean hasPermission(GHUser user, GHPermissionType permission) { return hasPermission(user.getLogin(), permission); } @@ -1051,7 +1061,7 @@ public boolean hasPermission(GHUser user, GHPermissionType permission) throws IO * @throws IOException * the io exception */ - public Set getTeams() throws IOException { + public Set getTeams() { GHOrganization org = root().getOrganization(getOwnerName()); return root().createRequest() .withUrlPath(getApiTailUrl("teams")) @@ -1070,7 +1080,7 @@ public Set getTeams() throws IOException { * @throws IOException * the io exception */ - public void addCollaborators(GHOrganization.RepositoryRole permission, GHUser... users) throws IOException { + public void addCollaborators(GHOrganization.RepositoryRole permission, GHUser... users) { addCollaborators(asList(users), permission); } @@ -1082,7 +1092,7 @@ public void addCollaborators(GHOrganization.RepositoryRole permission, GHUser... * @throws IOException * the io exception */ - public void addCollaborators(GHUser... users) throws IOException { + public void addCollaborators(GHUser... users) { addCollaborators(asList(users)); } @@ -1094,7 +1104,7 @@ public void addCollaborators(GHUser... users) throws IOException { * @throws IOException * the io exception */ - public void addCollaborators(Collection users) throws IOException { + public void addCollaborators(Collection users) { modifyCollaborators(users, "PUT", null); } @@ -1108,8 +1118,7 @@ public void addCollaborators(Collection users) throws IOException { * @throws IOException * the io exception */ - public void addCollaborators(Collection users, GHOrganization.RepositoryRole permission) - throws IOException { + public void addCollaborators(Collection users, GHOrganization.RepositoryRole permission) { modifyCollaborators(users, "PUT", permission); } @@ -1121,7 +1130,7 @@ public void addCollaborators(Collection users, GHOrganization.Repository * @throws IOException * the io exception */ - public void removeCollaborators(GHUser... users) throws IOException { + public void removeCollaborators(GHUser... users) { removeCollaborators(asList(users)); } @@ -1133,13 +1142,13 @@ public void removeCollaborators(GHUser... users) throws IOException { * @throws IOException * the io exception */ - public void removeCollaborators(Collection users) throws IOException { + public void removeCollaborators(Collection users) { modifyCollaborators(users, "DELETE", null); } private void modifyCollaborators(@NonNull Collection users, @NonNull String method, - @CheckForNull GHOrganization.RepositoryRole permission) throws IOException { + @CheckForNull GHOrganization.RepositoryRole permission) { Requester requester = root().createRequest().method(method); if (permission != null) { requester = requester.with("permission", permission.toString()).inBody(); @@ -1159,7 +1168,7 @@ private void modifyCollaborators(@NonNull Collection users, * @throws IOException * the io exception */ - public void setEmailServiceHook(String address) throws IOException { + public void setEmailServiceHook(String address) { Map config = new HashMap<>(); config.put("address", address); root().createRequest() @@ -1179,7 +1188,7 @@ public void setEmailServiceHook(String address) throws IOException { * @throws IOException * the io exception */ - public void enableIssueTracker(boolean v) throws IOException { + public void enableIssueTracker(boolean v) { set().issues(v); } @@ -1191,7 +1200,7 @@ public void enableIssueTracker(boolean v) throws IOException { * @throws IOException * the io exception */ - public void enableProjects(boolean v) throws IOException { + public void enableProjects(boolean v) { set().projects(v); } @@ -1203,7 +1212,7 @@ public void enableProjects(boolean v) throws IOException { * @throws IOException * the io exception */ - public void enableWiki(boolean v) throws IOException { + public void enableWiki(boolean v) { set().wiki(v); } @@ -1215,7 +1224,7 @@ public void enableWiki(boolean v) throws IOException { * @throws IOException * the io exception */ - public void enableDownloads(boolean v) throws IOException { + public void enableDownloads(boolean v) { set().downloads(v); } @@ -1227,7 +1236,7 @@ public void enableDownloads(boolean v) throws IOException { * @throws IOException * the io exception */ - public void renameTo(String name) throws IOException { + public void renameTo(String name) { set().name(name); } @@ -1239,7 +1248,7 @@ public void renameTo(String name) throws IOException { * @throws IOException * the io exception */ - public void setDescription(String value) throws IOException { + public void setDescription(String value) { set().description(value); } @@ -1251,7 +1260,7 @@ public void setDescription(String value) throws IOException { * @throws IOException * the io exception */ - public void setHomepage(String value) throws IOException { + public void setHomepage(String value) { set().homepage(value); } @@ -1263,7 +1272,7 @@ public void setHomepage(String value) throws IOException { * @throws IOException * the io exception */ - public void setDefaultBranch(String value) throws IOException { + public void setDefaultBranch(String value) { set().defaultBranch(value); } @@ -1275,7 +1284,7 @@ public void setDefaultBranch(String value) throws IOException { * @throws IOException * the io exception */ - public void setPrivate(boolean value) throws IOException { + public void setPrivate(boolean value) { set().private_(value); } @@ -1287,7 +1296,7 @@ public void setPrivate(boolean value) throws IOException { * @throws IOException * the io exception */ - public void setVisibility(final Visibility value) throws IOException { + public void setVisibility(final Visibility value) { root().createRequest() .method("PATCH") .with("name", name) @@ -1304,7 +1313,7 @@ public void setVisibility(final Visibility value) throws IOException { * @throws IOException * the io exception */ - public void allowSquashMerge(boolean value) throws IOException { + public void allowSquashMerge(boolean value) { set().allowSquashMerge(value); } @@ -1316,7 +1325,7 @@ public void allowSquashMerge(boolean value) throws IOException { * @throws IOException * the io exception */ - public void allowMergeCommit(boolean value) throws IOException { + public void allowMergeCommit(boolean value) { set().allowMergeCommit(value); } @@ -1328,7 +1337,7 @@ public void allowMergeCommit(boolean value) throws IOException { * @throws IOException * the io exception */ - public void allowRebaseMerge(boolean value) throws IOException { + public void allowRebaseMerge(boolean value) { set().allowRebaseMerge(value); } @@ -1340,7 +1349,7 @@ public void allowRebaseMerge(boolean value) throws IOException { * @throws IOException * the io exception */ - public void allowForking(boolean value) throws IOException { + public void allowForking(boolean value) { set().allowForking(value); } @@ -1352,7 +1361,7 @@ public void allowForking(boolean value) throws IOException { * @throws IOException * the io exception */ - public void deleteBranchOnMerge(boolean value) throws IOException { + public void deleteBranchOnMerge(boolean value) { set().deleteBranchOnMerge(value); } @@ -1362,13 +1371,16 @@ public void deleteBranchOnMerge(boolean value) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { try { root().createRequest().method("DELETE").withUrlPath(getApiTailUrl("")).send(); - } catch (FileNotFoundException x) { - throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name - + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916") - .initCause(x); + } catch (UncheckedIOException x) { + if (FileNotFoundException.class.isInstance(x)) { + throw new UncheckedIOException("Failed to delete " + getOwnerName() + "/" + name + + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916", + x.getCause()); + } + throw x; } } @@ -1389,7 +1401,7 @@ public void delete() throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public void archive() throws IOException { + public void archive() { set().archive(); // Generally would not update this record, // but doing so here since this will result in any other update actions failing @@ -1459,7 +1471,7 @@ public PagedIterable listForks(final ForkSort sort) { * @throws IOException * the io exception */ - public GHRepository fork() throws IOException { + public GHRepository fork() { root().createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).send(); // this API is asynchronous. we need to wait for a bit @@ -1471,10 +1483,10 @@ public GHRepository fork() throws IOException { try { Thread.sleep(3000); } catch (InterruptedException e) { - throw (IOException) new InterruptedIOException().initCause(e); + throw new UncheckedIOException((IOException) new InterruptedIOException().initCause(e)); } } - throw new IOException(this + " was forked but can't find the new repository"); + throw new GHException(this + " was forked but can't find the new repository"); } /** @@ -1486,7 +1498,7 @@ public GHRepository fork() throws IOException { * @throws IOException * the io exception */ - public GHBranchSync sync(String branch) throws IOException { + public GHBranchSync sync(String branch) { return root().createRequest() .method("POST") .with("branch", branch) @@ -1504,7 +1516,7 @@ public GHBranchSync sync(String branch) throws IOException { * @throws IOException * the io exception */ - public GHRepository forkTo(GHOrganization org) throws IOException { + public GHRepository forkTo(GHOrganization org) { root().createRequest() .method("POST") .with("organization", org.getLogin()) @@ -1520,10 +1532,10 @@ public GHRepository forkTo(GHOrganization org) throws IOException { try { Thread.sleep(3000); } catch (InterruptedException e) { - throw (IOException) new InterruptedIOException().initCause(e); + throw new UncheckedIOException((IOException) new InterruptedIOException().initCause(e)); } } - throw new IOException(this + " was forked into " + org.getLogin() + " but can't find the new repository"); + throw new GHException(this + " was forked into " + org.getLogin() + " but can't find the new repository"); } /** @@ -1535,7 +1547,7 @@ public GHRepository forkTo(GHOrganization org) throws IOException { * @throws IOException * the io exception */ - public GHPullRequest getPullRequest(int i) throws IOException { + public GHPullRequest getPullRequest(int i) { return root().createRequest().withUrlPath(getApiTailUrl("pulls/" + i)).fetch(GHPullRequest.class).wrapUp(this); } @@ -1574,7 +1586,7 @@ public GHPullRequestSearchBuilder searchPullRequests() { * @throws IOException * the io exception */ - public GHPullRequest createPullRequest(String title, String head, String base, String body) throws IOException { + public GHPullRequest createPullRequest(String title, String head, String base, String body) { return createPullRequest(title, head, base, body, true); } @@ -1601,7 +1613,7 @@ public GHPullRequest createPullRequest(String title, String head, String base, String body, - boolean maintainerCanModify) throws IOException { + boolean maintainerCanModify) { return createPullRequest(title, head, base, body, maintainerCanModify, false); } @@ -1631,7 +1643,7 @@ public GHPullRequest createPullRequest(String title, String base, String body, boolean maintainerCanModify, - boolean draft) throws IOException { + boolean draft) { return root().createRequest() .method("POST") .with("title", title) @@ -1652,7 +1664,7 @@ public GHPullRequest createPullRequest(String title, * @throws IOException * the io exception */ - public List getHooks() throws IOException { + public List getHooks() { return GHHooks.repoContext(this, owner).getHooks(); } @@ -1665,7 +1677,7 @@ public List getHooks() throws IOException { * @throws IOException * the io exception */ - public GHHook getHook(int id) throws IOException { + public GHHook getHook(int id) { return GHHooks.repoContext(this, owner).getHook(id); } @@ -1677,7 +1689,7 @@ public GHHook getHook(int id) throws IOException { * @throws IOException * the io exception */ - public void deleteHook(int id) throws IOException { + public void deleteHook(int id) { GHHooks.repoContext(this, owner).deleteHook(id); } @@ -1709,7 +1721,7 @@ public void setCompareUsePaginatedCommits(boolean value) { * @throws IOException * on failure communicating with GitHub */ - public GHCompare getCompare(String id1, String id2) throws IOException { + public GHCompare getCompare(String id1, String id2) { final Requester requester = root().createRequest() .withUrlPath(getApiTailUrl(String.format("compare/%s...%s", id1, id2))); @@ -1732,7 +1744,7 @@ public GHCompare getCompare(String id1, String id2) throws IOException { * @throws IOException * the io exception */ - public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException { + public GHCompare getCompare(GHCommit id1, GHCommit id2) { return getCompare(id1.getSHA1(), id2.getSHA1()); } @@ -1747,7 +1759,7 @@ public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException { * @throws IOException * the io exception */ - public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { + public GHCompare getCompare(GHBranch id1, GHBranch id2) { GHRepository owner1 = id1.getOwner(); GHRepository owner2 = id2.getOwner(); @@ -1773,7 +1785,7 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { * @throws IOException * on failure communicating with GitHub */ - public GHRef[] getRefs() throws IOException { + public GHRef[] getRefs() { return listRefs().toArray(); } @@ -1784,7 +1796,7 @@ public GHRef[] getRefs() throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ - public PagedIterable listRefs() throws IOException { + public PagedIterable listRefs() { return listRefs(""); } @@ -1797,7 +1809,7 @@ public PagedIterable listRefs() throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ - public GHRef[] getRefs(String refType) throws IOException { + public GHRef[] getRefs(String refType) { return listRefs(refType).toArray(); } @@ -1810,7 +1822,7 @@ public GHRef[] getRefs(String refType) throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ - public PagedIterable listRefs(String refType) throws IOException { + public PagedIterable listRefs(String refType) { return GHRef.readMatching(this, refType); } @@ -1823,7 +1835,7 @@ public PagedIterable listRefs(String refType) throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ - public GHRef getRef(String refName) throws IOException { + public GHRef getRef(String refName) { return GHRef.read(this, refName); } @@ -1837,7 +1849,7 @@ public GHRef getRef(String refName) throws IOException { * @throws IOException * the io exception */ - public GHTagObject getTagObject(String sha) throws IOException { + public GHTagObject getTagObject(String sha) { return root().createRequest().withUrlPath(getApiTailUrl("git/tags/" + sha)).fetch(GHTagObject.class).wrap(this); } @@ -1850,7 +1862,7 @@ public GHTagObject getTagObject(String sha) throws IOException { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid tree type being requested */ - public GHTree getTree(String sha) throws IOException { + public GHTree getTree(String sha) { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); return root().createRequest().withUrlPath(url).fetch(GHTree.class).wrap(this); } @@ -1876,7 +1888,7 @@ public GHTreeBuilder createTree() { * @throws IOException * on failure communicating with GitHub, potentially due to an invalid tree type being requested */ - public GHTree getTreeRecursive(String sha, int recursive) throws IOException { + public GHTree getTreeRecursive(String sha, int recursive) { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); return root().createRequest().with("recursive", recursive).withUrlPath(url).fetch(GHTree.class).wrap(this); } @@ -1895,7 +1907,7 @@ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { * @see Get a blob * @see #readBlob(String) #readBlob(String) */ - public GHBlob getBlob(String blobSha) throws IOException { + public GHBlob getBlob(String blobSha) { String target = getApiTailUrl("git/blobs/" + blobSha); return root().createRequest().withUrlPath(target).fetch(GHBlob.class); } @@ -1920,7 +1932,7 @@ public GHBlobBuilder createBlob() { * @see Get a blob * @see #getBlob(String) #getBlob(String) */ - public InputStream readBlob(String blobSha) throws IOException { + public InputStream readBlob(String blobSha) { String target = getApiTailUrl("git/blobs/" + blobSha); // https://developer.github.com/v3/media/ describes this media type @@ -1939,7 +1951,7 @@ public InputStream readBlob(String blobSha) throws IOException { * @throws IOException * the io exception */ - public GHCommit getCommit(String sha1) throws IOException { + public GHCommit getCommit(String sha1) { GHCommit c = commits.get(sha1); if (c == null) { c = root().createRequest() @@ -2012,7 +2024,7 @@ public PagedIterable listCommitComments(String commitSha) { * @throws IOException * as usual but also if you don't use the preview connector */ - public GHLicense getLicense() throws IOException { + public GHLicense getLicense() { GHContentWithLicense lic = getLicenseContent_(); return lic != null ? lic.license : null; } @@ -2024,18 +2036,21 @@ public GHLicense getLicense() throws IOException { * @throws IOException * as usual but also if you don't use the preview connector */ - public GHContent getLicenseContent() throws IOException { + public GHContent getLicenseContent() { return getLicenseContent_(); } - private GHContentWithLicense getLicenseContent_() throws IOException { + private GHContentWithLicense getLicenseContent_() { try { return root().createRequest() .withUrlPath(getApiTailUrl("license")) .fetch(GHContentWithLicense.class) .wrap(this); - } catch (FileNotFoundException e) { - return null; + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -2048,7 +2063,7 @@ private GHContentWithLicense getLicenseContent_() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listCommitStatuses(final String sha1) throws IOException { + public PagedIterable listCommitStatuses(final String sha1) { return root().createRequest() .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1)) .toIterable(GHCommitStatus[].class, null); @@ -2063,7 +2078,7 @@ public PagedIterable listCommitStatuses(final String sha1) throw * @throws IOException * the io exception */ - public GHCommitStatus getLastCommitStatus(String sha1) throws IOException { + public GHCommitStatus getLastCommitStatus(String sha1) { List v = listCommitStatuses(sha1).toList(); return v.isEmpty() ? null : v.get(0); } @@ -2079,7 +2094,7 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException { * @see List check runs * for a specific ref */ - public PagedIterable getCheckRuns(String ref) throws IOException { + public PagedIterable getCheckRuns(String ref) { GitHubRequest request = root().createRequest() .withUrlPath(String.format("/repos/%s/%s/commits/%s/check-runs", getOwnerName(), name, ref)) .build(); @@ -2099,7 +2114,7 @@ public PagedIterable getCheckRuns(String ref) throws IOException { * @see List check runs * for a specific ref */ - public PagedIterable getCheckRuns(String ref, Map params) throws IOException { + public PagedIterable getCheckRuns(String ref, Map params) { GitHubRequest request = root().createRequest() .withUrlPath(String.format("/repos/%s/%s/commits/%s/check-runs", getOwnerName(), name, ref)) .with(params) @@ -2128,7 +2143,7 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, - String context) throws IOException { + String context) { return root().createRequest() .method("POST") .with("state", state) @@ -2156,8 +2171,7 @@ public GHCommitStatus createCommitStatus(String sha1, * @see #createCommitStatus(String, GHCommitState, String, String, String) #createCommitStatus(String, * GHCommitState,String,String,String) */ - public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) - throws IOException { + public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) { return createCommitStatus(sha1, state, targetUrl, description, null); } @@ -2192,7 +2206,7 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin * @throws IOException * the io exception */ - public PagedIterable listEvents() throws IOException { + public PagedIterable listEvents() { return root().createRequest() .withUrlPath(String.format("/repos/%s/%s/events", getOwnerName(), name)) .toIterable(GHEventInfo[].class, null); @@ -2207,7 +2221,7 @@ public PagedIterable listEvents() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listLabels() throws IOException { + public PagedIterable listLabels() { return GHLabel.readAll(this); } @@ -2220,7 +2234,7 @@ public PagedIterable listLabels() throws IOException { * @throws IOException * the io exception */ - public GHLabel getLabel(String name) throws IOException { + public GHLabel getLabel(String name) { return GHLabel.read(this, name); } @@ -2235,7 +2249,7 @@ public GHLabel getLabel(String name) throws IOException { * @throws IOException * the io exception */ - public GHLabel createLabel(String name, String color) throws IOException { + public GHLabel createLabel(String name, String color) { return GHLabel.create(this).name(name).color(color).description("").done(); } @@ -2252,7 +2266,7 @@ public GHLabel createLabel(String name, String color) throws IOException { * @throws IOException * the io exception */ - public GHLabel createLabel(String name, String color, String description) throws IOException { + public GHLabel createLabel(String name, String color, String description) { return GHLabel.create(this).name(name).color(color).description(description).done(); } @@ -2327,8 +2341,7 @@ private PagedIterable listUsers(Requester requester, final String suffix * @throws IOException * the io exception */ - public GHHook createHook(String name, Map config, Collection events, boolean active) - throws IOException { + public GHHook createHook(String name, Map config, Collection events, boolean active) { return GHHooks.repoContext(this, owner).createHook(name, config, events, active); } @@ -2343,7 +2356,7 @@ public GHHook createHook(String name, Map config, Collection events) throws IOException { + public GHHook createWebHook(URL url, Collection events) { return createHook("web", Collections.singletonMap("url", url.toExternalForm()), events, true); } @@ -2356,7 +2369,7 @@ public GHHook createWebHook(URL url, Collection events) throws IOExcept * @throws IOException * the io exception */ - public GHHook createWebHook(URL url) throws IOException { + public GHHook createWebHook(URL url) { return createWebHook(url, null); } @@ -2367,7 +2380,7 @@ public GHHook createWebHook(URL url) throws IOException { * @throws IOException * the io exception */ - public Map getBranches() throws IOException { + public Map getBranches() { Map r = new TreeMap(); for (GHBranch p : root().createRequest() .withUrlPath(getApiTailUrl("branches")) @@ -2387,7 +2400,7 @@ public Map getBranches() throws IOException { * @throws IOException * the io exception */ - public GHBranch getBranch(String name) throws IOException { + public GHBranch getBranch(String name) { return root().createRequest().withUrlPath(getApiTailUrl("branches/" + name)).fetch(GHBranch.class).wrap(this); } @@ -2414,7 +2427,7 @@ public PagedIterable listMilestones(final GHIssueState state) { * @throws IOException * the io exception */ - public GHMilestone getMilestone(int number) throws IOException { + public GHMilestone getMilestone(int number) { GHMilestone m = milestones.get(number); if (m == null) { m = root().createRequest().withUrlPath(getApiTailUrl("milestones/" + number)).fetch(GHMilestone.class); @@ -2433,7 +2446,7 @@ public GHMilestone getMilestone(int number) throws IOException { * @throws IOException * the io exception */ - public GHContent getFileContent(String path) throws IOException { + public GHContent getFileContent(String path) { return getFileContent(path, null); } @@ -2448,7 +2461,7 @@ public GHContent getFileContent(String path) throws IOException { * @throws IOException * the io exception */ - public GHContent getFileContent(String path, String ref) throws IOException { + public GHContent getFileContent(String path, String ref) { Requester requester = root().createRequest(); String target = getApiTailUrl("contents/" + path); @@ -2464,7 +2477,7 @@ public GHContent getFileContent(String path, String ref) throws IOException { * @throws IOException * the io exception */ - public List getDirectoryContent(String path) throws IOException { + public List getDirectoryContent(String path) { return getDirectoryContent(path, null); } @@ -2479,7 +2492,7 @@ public List getDirectoryContent(String path) throws IOException { * @throws IOException * the io exception */ - public List getDirectoryContent(String path, String ref) throws IOException { + public List getDirectoryContent(String path, String ref) { Requester requester = root().createRequest(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); @@ -2499,7 +2512,7 @@ public List getDirectoryContent(String path, String ref) throws IOExc * @throws IOException * the io exception */ - public GHContent getReadme() throws IOException { + public GHContent getReadme() { Requester requester = root().createRequest(); return requester.withUrlPath(getApiTailUrl("readme")).fetch(GHContent.class).wrap(this); } @@ -2514,7 +2527,7 @@ public GHContent getReadme() throws IOException { * @throws IOException * the io exception */ - public void createVariable(String name, String value) throws IOException { + public void createVariable(String name, String value) { GHRepositoryVariable.create(this).name(name).value(value).done(); } @@ -2527,7 +2540,7 @@ public void createVariable(String name, String value) throws IOException { * @throws IOException * the io exception */ - public GHRepositoryVariable getVariable(String name) throws IOException { + public GHRepositoryVariable getVariable(String name) { return GHRepositoryVariable.read(this, name); } @@ -2551,7 +2564,7 @@ public GHContentBuilder createContent() { * @throws IOException * the io exception */ - public GHMilestone createMilestone(String title, String description) throws IOException { + public GHMilestone createMilestone(String title, String description) { return root().createRequest() .method("POST") .with("title", title) @@ -2572,7 +2585,7 @@ public GHMilestone createMilestone(String title, String description) throws IOEx * @throws IOException * the io exception */ - public GHDeployKey addDeployKey(String title, String key) throws IOException { + public GHDeployKey addDeployKey(String title, String key) { return addDeployKey(title, key, false); } @@ -2589,7 +2602,7 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { * @throws IOException * the io exception */ - public GHDeployKey addDeployKey(String title, String key, boolean readOnly) throws IOException { + public GHDeployKey addDeployKey(String title, String key, boolean readOnly) { return root().createRequest() .method("POST") .with("title", title) @@ -2607,7 +2620,7 @@ public GHDeployKey addDeployKey(String title, String key, boolean readOnly) thro * @throws IOException * the io exception */ - public List getDeployKeys() throws IOException { + public List getDeployKeys() { return root().createRequest() .withUrlPath(getApiTailUrl("keys")) .toIterable(GHDeployKey[].class, item -> item.lateBind(this)) @@ -2624,7 +2637,7 @@ public List getDeployKeys() throws IOException { * @see #getParent() #getParent() */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHRepository getSource() throws IOException { + public GHRepository getSource() { if (fork && source == null) { populate(); } @@ -2646,7 +2659,7 @@ public GHRepository getSource() throws IOException { * @see #getSource() #getSource() */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHRepository getParent() throws IOException { + public GHRepository getParent() { if (fork && parent == null) { populate(); } @@ -2668,7 +2681,7 @@ public GHRepository getParent() throws IOException { * @throws IOException * the io exception */ - public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { + public GHSubscription subscribe(boolean subscribed, boolean ignored) { return root().createRequest() .method("PUT") .with("subscribed", subscribed) @@ -2685,14 +2698,17 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx * @throws IOException * the io exception */ - public GHSubscription getSubscription() throws IOException { + public GHSubscription getSubscription() { try { return root().createRequest() .withUrlPath(getApiTailUrl("subscription")) .fetch(GHSubscription.class) .wrapUp(this); - } catch (FileNotFoundException e) { - return null; + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } @@ -2709,7 +2725,7 @@ private static class GHCodeownersErrors { * @throws IOException * the io exception */ - public List listCodeownersErrors() throws IOException { + public List listCodeownersErrors() { return root().createRequest() .withUrlPath(getApiTailUrl("codeowners/errors")) .fetch(GHCodeownersErrors.class).errors; @@ -2722,7 +2738,7 @@ public List listCodeownersErrors() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listContributors() throws IOException { + public PagedIterable listContributors() { return root().createRequest().withUrlPath(getApiTailUrl("contributors")).toIterable(Contributor[].class, null); } @@ -2795,7 +2811,7 @@ public GHRepositoryStatistics getStatistics() { * @throws IOException * the io exception */ - public GHProject createProject(String name, String body) throws IOException { + public GHProject createProject(String name, String body) { return root().createRequest() .method("POST") .with("name", name) @@ -2814,7 +2830,7 @@ public GHProject createProject(String name, String body) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { + public PagedIterable listProjects(final GHProject.ProjectStateFilter status) { return root().createRequest() .with("state", status) .withUrlPath(getApiTailUrl("projects")) @@ -2828,7 +2844,7 @@ public PagedIterable listProjects(final GHProject.ProjectStateFilter * @throws IOException * the io exception */ - public PagedIterable listProjects() throws IOException { + public PagedIterable listProjects() { return listProjects(GHProject.ProjectStateFilter.OPEN); } @@ -2846,16 +2862,20 @@ public PagedIterable listProjects() throws IOException { * the io exception * @see GitHub#renderMarkdown(String) GitHub#renderMarkdown(String) */ - public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException { - return new InputStreamReader( - root().createRequest() - .method("POST") - .with("text", text) - .with("mode", mode == null ? null : mode.toString()) - .with("context", getFullName()) - .withUrlPath("/markdown") - .fetchStream(Requester::copyInputStream), - "UTF-8"); + public Reader renderMarkdown(String text, MarkdownMode mode) { + try { + return new InputStreamReader( + root().createRequest() + .method("POST") + .with("text", text) + .with("mode", mode == null ? null : mode.toString()) + .with("context", getFullName()) + .withUrlPath("/markdown") + .fetchStream(Requester::copyInputStream), + "UTF-8"); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } /** @@ -2875,7 +2895,7 @@ public GHNotificationStream listNotifications() { * @throws IOException * the io exception */ - public GHRepositoryViewTraffic getViewTraffic() throws IOException { + public GHRepositoryViewTraffic getViewTraffic() { return root().createRequest().withUrlPath(getApiTailUrl("/traffic/views")).fetch(GHRepositoryViewTraffic.class); } @@ -2887,7 +2907,7 @@ public GHRepositoryViewTraffic getViewTraffic() throws IOException { * @throws IOException * the io exception */ - public GHRepositoryCloneTraffic getCloneTraffic() throws IOException { + public GHRepositoryCloneTraffic getCloneTraffic() { return root().createRequest() .withUrlPath(getApiTailUrl("/traffic/clones")) .fetch(GHRepositoryCloneTraffic.class); @@ -2941,7 +2961,7 @@ String getApiTailUrl(String tail) { * @throws IOException * the io exception */ - public PagedIterable listIssueEvents() throws IOException { + public PagedIterable listIssueEvents() { return root().createRequest() .withUrlPath(getApiTailUrl("issues/events")) .toIterable(GHIssueEvent[].class, null); @@ -2956,7 +2976,7 @@ public PagedIterable listIssueEvents() throws IOException { * @throws IOException * the io exception */ - public GHIssueEvent getIssueEvent(long id) throws IOException { + public GHIssueEvent getIssueEvent(long id) { return root().createRequest().withUrlPath(getApiTailUrl("issues/events/" + id)).fetch(GHIssueEvent.class); } @@ -2978,7 +2998,7 @@ public PagedIterable listWorkflows() { * @throws IOException * the io exception */ - public GHWorkflow getWorkflow(long id) throws IOException { + public GHWorkflow getWorkflow(long id) { return getWorkflow(String.valueOf(id)); } @@ -2991,7 +3011,7 @@ public GHWorkflow getWorkflow(long id) throws IOException { * @throws IOException * the io exception */ - public GHWorkflow getWorkflow(String nameOrId) throws IOException { + public GHWorkflow getWorkflow(String nameOrId) { return root().createRequest() .withUrlPath(getApiTailUrl("actions/workflows"), nameOrId) .fetch(GHWorkflow.class) @@ -3016,7 +3036,7 @@ public GHWorkflowRunQueryBuilder queryWorkflowRuns() { * @throws IOException * the io exception */ - public GHWorkflowRun getWorkflowRun(long id) throws IOException { + public GHWorkflowRun getWorkflowRun(long id) { return root().createRequest() .withUrlPath(getApiTailUrl("actions/runs"), String.valueOf(id)) .fetch(GHWorkflowRun.class) @@ -3041,7 +3061,7 @@ public PagedIterable listArtifacts() { * @throws IOException * the io exception */ - public GHArtifact getArtifact(long id) throws IOException { + public GHArtifact getArtifact(long id) { return root().createRequest() .withUrlPath(getApiTailUrl("actions/artifacts"), String.valueOf(id)) .fetch(GHArtifact.class) @@ -3057,7 +3077,7 @@ public GHArtifact getArtifact(long id) throws IOException { * @throws IOException * the io exception */ - public GHWorkflowJob getWorkflowJob(long id) throws IOException { + public GHWorkflowJob getWorkflowJob(long id) { return root().createRequest() .withUrlPath(getApiTailUrl("/actions/jobs"), String.valueOf(id)) .fetch(GHWorkflowJob.class) @@ -3071,7 +3091,7 @@ public GHWorkflowJob getWorkflowJob(long id) throws IOException { * @throws IOException * the io exception */ - public GHRepositoryPublicKey getPublicKey() throws IOException { + public GHRepositoryPublicKey getPublicKey() { return root().createRequest() .withUrlPath(getApiTailUrl("/actions/secrets/public-key")) .fetch(GHRepositoryPublicKey.class) @@ -3091,7 +3111,7 @@ private static class Topics { * @throws IOException * the io exception */ - public List listTopics() throws IOException { + public List listTopics() { Topics topics = root().createRequest().withUrlPath(getApiTailUrl("topics")).fetch(Topics.class); return topics.names; } @@ -3105,7 +3125,7 @@ public List listTopics() throws IOException { * @throws IOException * the io exception */ - public void setTopics(List topics) throws IOException { + public void setTopics(List topics) { root().createRequest().method("PUT").with("names", topics).withUrlPath(getApiTailUrl("topics")).send(); } @@ -3122,7 +3142,7 @@ public void setTopics(List topics) throws IOException { * @throws IOException * the io exception */ - public void createSecret(String secretName, String encryptedValue, String publicKeyId) throws IOException { + public void createSecret(String secretName, String encryptedValue, String publicKeyId) { root().createRequest() .method("PUT") .with("encrypted_value", encryptedValue) @@ -3146,7 +3166,7 @@ public void createSecret(String secretName, String encryptedValue, String public * @throws IOException * Signals that an I/O exception has occurred. */ - public GHTagObject createTag(String tag, String message, String object, String type) throws IOException { + public GHTagObject createTag(String tag, String message, String object, String type) { return root().createRequest() .method("POST") .with("tag", tag) @@ -3171,7 +3191,7 @@ public GHTagObject createTag(String tag, String message, String object, String t * @throws IOException * The IO exception. */ - public T readZip(InputStreamFunction streamFunction, String ref) throws IOException { + public T readZip(InputStreamFunction streamFunction, String ref) { return downloadArchive("zip", ref, streamFunction); } @@ -3188,7 +3208,7 @@ public T readZip(InputStreamFunction streamFunction, String ref) throws I * @throws IOException * The IO exception. */ - public T readTar(InputStreamFunction streamFunction, String ref) throws IOException { + public T readTar(InputStreamFunction streamFunction, String ref) { return downloadArchive("tar", ref, streamFunction); } @@ -3205,7 +3225,7 @@ public T readTar(InputStreamFunction streamFunction, String ref) throws I * @throws IOException * the io exception */ - public void dispatch(String eventType, @Nullable T clientPayload) throws IOException { + public void dispatch(String eventType, @Nullable T clientPayload) { root().createRequest() .method("POST") .withUrlPath(getApiTailUrl("dispatches")) @@ -3216,7 +3236,7 @@ public void dispatch(String eventType, @Nullable T clientPayload) throws IOE private T downloadArchive(@Nonnull String type, @CheckForNull String ref, - @Nonnull InputStreamFunction streamFunction) throws IOException { + @Nonnull InputStreamFunction streamFunction) { requireNonNull(streamFunction, "Sink must not be null"); String tailUrl = getApiTailUrl(type + "ball"); if (ref != null) { @@ -3232,7 +3252,7 @@ private T downloadArchive(@Nonnull String type, * @throws IOException * Signals that an I/O exception has occurred. */ - void populate() throws IOException { + void populate() { if (isOffline()) { return; // can't populate if the root is offline } @@ -3276,7 +3296,7 @@ protected Updater(@Nonnull GHRepository repository) { * @throws IOException * the io exception */ - public void star() throws IOException { + public void star() { root().createRequest().method("PUT").withUrlPath(String.format("/user/starred/%s", full_name)).send(); } @@ -3286,7 +3306,7 @@ public void star() throws IOException { * @throws IOException * the io exception */ - public void unstar() throws IOException { + public void unstar() { root().createRequest().method("DELETE").withUrlPath(String.format("/user/starred/%s", full_name)).send(); } @@ -3298,7 +3318,7 @@ public void unstar() throws IOException { * @throws IOException * the io exception */ - public List getTopReferralPaths() throws IOException { + public List getTopReferralPaths() { return Arrays.asList(root().createRequest() .method("GET") .withUrlPath(getApiTailUrl("/traffic/popular/paths")) @@ -3313,7 +3333,7 @@ public List getTopReferralPaths() throws IOE * @throws IOException * the io exception */ - public List getTopReferralSources() throws IOException { + public List getTopReferralSources() { return Arrays.asList(root().createRequest() .method("GET") .withUrlPath(getApiTailUrl("/traffic/popular/referrers")) @@ -3330,7 +3350,7 @@ public List getTopReferralSources() throw * @throws IOException * the io exception */ - public PagedIterable listRulesForBranch(String branch) throws IOException { + public PagedIterable listRulesForBranch(String branch) { return root().createRequest() .method("GET") .withUrlPath(getApiTailUrl("/rules/branches/" + branch)) @@ -3345,7 +3365,7 @@ public PagedIterable listRulesForBranch(String branch) throws * @throws IOException * the io exception */ - public boolean isVulnerabilityAlertsEnabled() throws IOException { + public boolean isVulnerabilityAlertsEnabled() { return root().createRequest() .method("GET") .withUrlPath(getApiTailUrl("/vulnerability-alerts")) diff --git a/src/main/java/org/kohsuke/github/GHRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHRepositoryBuilder.java index d32dbd2563..dcc2fbc90e 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryBuilder.java @@ -39,7 +39,7 @@ protected GHRepositoryBuilder(Class intermediateReturnType, GitHub root, GHRe * @throws IOException * In case of any networking error or error from the server. */ - public S allowSquashMerge(boolean enabled) throws IOException { + public S allowSquashMerge(boolean enabled) { return with("allow_squash_merge", enabled); } @@ -54,7 +54,7 @@ public S allowSquashMerge(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S allowMergeCommit(boolean enabled) throws IOException { + public S allowMergeCommit(boolean enabled) { return with("allow_merge_commit", enabled); } @@ -69,7 +69,7 @@ public S allowMergeCommit(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S allowRebaseMerge(boolean enabled) throws IOException { + public S allowRebaseMerge(boolean enabled) { return with("allow_rebase_merge", enabled); } @@ -82,7 +82,7 @@ public S allowRebaseMerge(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S allowForking(boolean enabled) throws IOException { + public S allowForking(boolean enabled) { return with("allow_forking", enabled); } @@ -97,7 +97,7 @@ public S allowForking(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S deleteBranchOnMerge(boolean enabled) throws IOException { + public S deleteBranchOnMerge(boolean enabled) { return with("delete_branch_on_merge", enabled); } @@ -110,7 +110,7 @@ public S deleteBranchOnMerge(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S defaultBranch(String branch) throws IOException { + public S defaultBranch(String branch) { return with("default_branch", branch); } @@ -123,7 +123,7 @@ public S defaultBranch(String branch) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S description(String description) throws IOException { + public S description(String description) { return with("description", description); } @@ -136,7 +136,7 @@ public S description(String description) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S homepage(URL homepage) throws IOException { + public S homepage(URL homepage) { return homepage(homepage.toExternalForm()); } @@ -149,7 +149,7 @@ public S homepage(URL homepage) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S homepage(String homepage) throws IOException { + public S homepage(String homepage) { return with("homepage", homepage); } @@ -162,7 +162,7 @@ public S homepage(String homepage) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S private_(boolean enabled) throws IOException { + public S private_(boolean enabled) { return with("private", enabled); } @@ -175,7 +175,7 @@ public S private_(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S visibility(final Visibility visibility) throws IOException { + public S visibility(final Visibility visibility) { return with("visibility", visibility.toString()); } @@ -188,7 +188,7 @@ public S visibility(final Visibility visibility) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S issues(boolean enabled) throws IOException { + public S issues(boolean enabled) { return with("has_issues", enabled); } @@ -201,7 +201,7 @@ public S issues(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S projects(boolean enabled) throws IOException { + public S projects(boolean enabled) { return with("has_projects", enabled); } @@ -214,7 +214,7 @@ public S projects(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S wiki(boolean enabled) throws IOException { + public S wiki(boolean enabled) { return with("has_wiki", enabled); } @@ -227,7 +227,7 @@ public S wiki(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S downloads(boolean enabled) throws IOException { + public S downloads(boolean enabled) { return with("has_downloads", enabled); } @@ -240,7 +240,7 @@ public S downloads(boolean enabled) throws IOException { * @throws IOException * In case of any networking error or error from the server. */ - public S isTemplate(boolean enabled) throws IOException { + public S isTemplate(boolean enabled) { return with("is_template", enabled); } @@ -252,7 +252,7 @@ public S isTemplate(boolean enabled) throws IOException { * Signals that an I/O exception has occurred. */ @Override - public GHRepository done() throws IOException { + public GHRepository done() { return super.done(); } @@ -263,7 +263,7 @@ public GHRepository done() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - S archive() throws IOException { + S archive() { return with("archived", true); } @@ -276,7 +276,7 @@ S archive() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - S name(String name) throws IOException { + S name(String name) { return with("name", name); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java b/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java index 2c1bc4b27a..773081f254 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java @@ -81,7 +81,7 @@ public Date getAnswerChosenAt() { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHUser getAnswerChosenBy() throws IOException { + public GHUser getAnswerChosenBy() { return root().intern(answerChosenBy); } @@ -119,7 +119,7 @@ public String getTitle() { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHUser getUser() throws IOException { + public GHUser getUser() { return root().intern(user); } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java b/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java index b16f61a98b..159c893b0d 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java @@ -67,7 +67,7 @@ public int getChildCommentCount() { * @throws IOException * Signals that an I/O exception has occurred. */ - public GHUser getUser() throws IOException { + public GHUser getUser() { return root().intern(user); } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryRule.java b/src/main/java/org/kohsuke/github/GHRepositoryRule.java index 2db05c7057..e94dba42c5 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryRule.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryRule.java @@ -6,6 +6,7 @@ import org.kohsuke.github.internal.EnumUtils; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.List; import java.util.Map; import java.util.Optional; @@ -76,7 +77,7 @@ public long getRulesetId() { * @throws IOException * if an I/O error occurs */ - public Optional getParameter(Parameter parameter) throws IOException { + public Optional getParameter(Parameter parameter) { if (this.parameters == null) { return Optional.empty(); } @@ -338,11 +339,15 @@ String getKey() { return this.key; } - T apply(JsonNode jsonNode, GitHub root) throws IOException { - if (jsonNode == null) { - return null; + T apply(JsonNode jsonNode, GitHub root) { + try { + if (jsonNode == null) { + return null; + } + return GitHubClient.getMappingObjectReader(root).forType(this.getType()).readValue(jsonNode); + } catch (IOException e) { + throw new UncheckedIOException(e); } - return GitHubClient.getMappingObjectReader(root).forType(this.getType()).readValue(jsonNode); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 4de7fbad5f..8959ae1017 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -5,6 +5,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -45,7 +46,7 @@ public GHRepositoryStatistics(GHRepository repo) { * @throws InterruptedException * the interrupted exception */ - public PagedIterable getContributorStats() throws IOException, InterruptedException { + public PagedIterable getContributorStats() { return getContributorStats(true); } @@ -63,19 +64,22 @@ public PagedIterable getContributorStats() throws IOException, @BetaApi @SuppressWarnings("SleepWhileInLoop") @SuppressFBWarnings(value = { "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" }, justification = "JSON API") - public PagedIterable getContributorStats(boolean waitTillReady) - throws IOException, InterruptedException { + public PagedIterable getContributorStats(boolean waitTillReady) { PagedIterable stats = getContributorStatsImpl(); - if (stats == null && waitTillReady) { - for (int i = 0; i < MAX_WAIT_ITERATIONS; i += 1) { - // Wait a few seconds and try again. - Thread.sleep(WAIT_SLEEP_INTERVAL); - stats = getContributorStatsImpl(); - if (stats != null) { - break; + try { + if (stats == null && waitTillReady) { + for (int i = 0; i < MAX_WAIT_ITERATIONS; i += 1) { + // Wait a few seconds and try again. + Thread.sleep(WAIT_SLEEP_INTERVAL); + stats = getContributorStatsImpl(); + if (stats != null) { + break; + } } } + } catch (InterruptedException e) { + throw new GHException("Interrupted", e); } return stats; @@ -84,7 +88,7 @@ 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 { + private PagedIterable getContributorStatsImpl() { return root().createRequest() .withUrlPath(getApiTailUrl("contributors")) .toIterable(ContributorStats[].class, null); @@ -137,7 +141,7 @@ public int getTotal() { * @throws NoSuchElementException * the no such element exception */ - public Week getWeek(long timestamp) throws NoSuchElementException { + public Week getWeek(long timestamp) { // maybe store the weeks in a map to make this more efficient? for (Week week : weeks) { if (week.getWeekTimestamp() == timestamp) { @@ -245,7 +249,7 @@ public String toString() { * @throws IOException * the io exception */ - public PagedIterable getCommitActivity() throws IOException { + public PagedIterable getCommitActivity() { return root().createRequest() .withUrlPath(getApiTailUrl("commit_activity")) .toIterable(CommitActivity[].class, null); @@ -305,19 +309,23 @@ public long getWeek() { * @throws IOException * the io exception */ - public List getCodeFrequency() throws IOException { + public List getCodeFrequency() { try { CodeFrequency[] list = root().createRequest() .withUrlPath(getApiTailUrl("code_frequency")) .fetch(CodeFrequency[].class); return Arrays.asList(list); - } catch (MismatchedInputException e) { - // This sometimes happens when retrieving code frequency statistics - // for a repository for the first time. It is probably still being - // generated, so return null. - return null; + } catch (UncheckedIOException e) { + if (e.getCause() instanceof MismatchedInputException) { + // This sometimes happens when retrieving code frequency statistics + // for a repository for the first time. It is probably still being + // generated, so return null. + return null; + } + throw e; } + } /** @@ -385,7 +393,7 @@ public String toString() { * @throws IOException * the io exception */ - public Participation getParticipation() throws IOException { + public Participation getParticipation() { return root().createRequest().withUrlPath(getApiTailUrl("participation")).fetch(Participation.class); } @@ -430,7 +438,7 @@ public List getOwnerCommits() { * @throws IOException * the io exception */ - public List getPunchCard() throws IOException { + public List getPunchCard() { PunchCardItem[] list = root().createRequest() .withUrlPath(getApiTailUrl("punch_card")) .fetch(PunchCardItem[].class); diff --git a/src/main/java/org/kohsuke/github/GHRepositoryVariable.java b/src/main/java/org/kohsuke/github/GHRepositoryVariable.java index 6a45c6cf98..7565d940ba 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryVariable.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryVariable.java @@ -98,7 +98,7 @@ GitHub getApiRoot() { * @throws IOException * the io exception */ - static GHRepositoryVariable read(@Nonnull GHRepository repository, @Nonnull String name) throws IOException { + static GHRepositoryVariable read(@Nonnull GHRepository repository, @Nonnull String name) { GHRepositoryVariable variable = repository.root() .createRequest() .withUrlPath(repository.getApiTailUrl(VARIABLE_NAMESPACE), name) @@ -119,7 +119,7 @@ static GHRepositoryVariable read(@Nonnull GHRepository repository, @Nonnull Stri * the io exception */ @BetaApi - static GHRepositoryVariable.Creator create(GHRepository repository) throws IOException { + static GHRepositoryVariable.Creator create(GHRepository repository) { return new GHRepositoryVariable.Creator(repository); } @@ -129,7 +129,7 @@ static GHRepositoryVariable.Creator create(GHRepository repository) throws IOExc * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getUrl().concat(SLASH).concat(name)).send(); } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryVariableBuilder.java b/src/main/java/org/kohsuke/github/GHRepositoryVariableBuilder.java index 62af8140d8..6640883565 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryVariableBuilder.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryVariableBuilder.java @@ -45,7 +45,7 @@ protected GHRepositoryVariableBuilder(@Nonnull Class intermediateReturnType, */ @Nonnull @BetaApi - public S name(String value) throws IOException { + public S name(String value) { return with("name", value); } @@ -60,7 +60,7 @@ public S name(String value) throws IOException { */ @Nonnull @BetaApi - public S value(String value) throws IOException { + public S value(String value) { return with("value", value); } } diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index 1066d51b7b..85839ee122 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -96,7 +96,7 @@ public GHRepository getRepository() { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(repo.getApiTailUrl("subscription")).send(); } diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index edba5e7b25..8a92fb2f3d 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -5,6 +5,7 @@ import org.kohsuke.github.internal.EnumUtils; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; import java.util.*; @@ -144,7 +145,7 @@ public Privacy getPrivacy() { * @throws IOException * the io exception */ - public void setDescription(String description) throws IOException { + public void setDescription(String description) { root().createRequest().method("PATCH").with("description", description).withUrlPath(api("")).send(); } @@ -156,7 +157,7 @@ public void setDescription(String description) throws IOException { * @throws IOException * the io exception */ - public void setPrivacy(Privacy privacy) throws IOException { + public void setPrivacy(Privacy privacy) { root().createRequest().method("PATCH").with("privacy", privacy).withUrlPath(api("")).send(); } @@ -168,7 +169,7 @@ public void setPrivacy(Privacy privacy) throws IOException { * the io exception */ @Nonnull - public PagedIterable listDiscussions() throws IOException { + public PagedIterable listDiscussions() { return GHDiscussion.readAll(this); } @@ -181,7 +182,7 @@ public PagedIterable listDiscussions() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listMembers(String role) throws IOException { + public PagedIterable listMembers(String role) { return root().createRequest().withUrlPath(api("/members")).with("role", role).toIterable(GHUser[].class, null); } @@ -194,7 +195,7 @@ public PagedIterable listMembers(String role) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listMembers(Role role) throws IOException { + public PagedIterable listMembers(Role role) { return listMembers(transformEnum(role)); } @@ -209,7 +210,7 @@ public PagedIterable listMembers(Role role) throws IOException { * @see documentation */ @Nonnull - public GHDiscussion getDiscussion(long discussionNumber) throws IOException { + public GHDiscussion getDiscussion(long discussionNumber) { return GHDiscussion.read(this, discussionNumber); } @@ -220,7 +221,7 @@ public GHDiscussion getDiscussion(long discussionNumber) throws IOException { * @throws IOException * the io exception */ - public PagedIterable listMembers() throws IOException { + public PagedIterable listMembers() { return listMembers("all"); } @@ -231,7 +232,7 @@ public PagedIterable listMembers() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listChildTeams() throws IOException { + public PagedIterable listChildTeams() { return root().createRequest() .withUrlPath(api("/teams")) .toIterable(GHTeam[].class, item -> item.wrapUp(this.organization)); @@ -244,7 +245,7 @@ public PagedIterable listChildTeams() throws IOException { * @throws IOException * the io exception */ - public Set getMembers() throws IOException { + public Set getMembers() { return listMembers().toSet(); } @@ -259,7 +260,7 @@ public boolean hasMember(GHUser user) { try { root().createRequest().withUrlPath(api("/memberships/" + user.getLogin())).send(); return true; - } catch (@SuppressWarnings("unused") IOException ignore) { + } catch (@SuppressWarnings("unused") UncheckedIOException ignore) { return false; } } @@ -271,7 +272,7 @@ public boolean hasMember(GHUser user) { * @throws IOException * the io exception */ - public Map getRepositories() throws IOException { + public Map getRepositories() { Map m = new TreeMap<>(); for (GHRepository r : listRepositories()) { m.put(r.getName(), r); @@ -299,7 +300,7 @@ public PagedIterable listRepositories() { * the io exception * @since 1.59 */ - public void add(GHUser u) throws IOException { + public void add(GHUser u) { root().createRequest().method("PUT").withUrlPath(api("/memberships/" + u.getLogin())).send(); } @@ -315,7 +316,7 @@ public void add(GHUser u) throws IOException { * @throws IOException * the io exception */ - public void add(GHUser user, Role role) throws IOException { + public void add(GHUser user, Role role) { root().createRequest() .method("PUT") .with("role", role) @@ -331,7 +332,7 @@ public void add(GHUser user, Role role) throws IOException { * @throws IOException * the io exception */ - public void remove(GHUser u) throws IOException { + public void remove(GHUser u) { root().createRequest().method("DELETE").withUrlPath(api("/memberships/" + u.getLogin())).send(); } @@ -343,7 +344,7 @@ public void remove(GHUser u) throws IOException { * @throws IOException * the io exception */ - public void add(GHRepository r) throws IOException { + public void add(GHRepository r) { add(r, (GHOrganization.RepositoryRole) null); } @@ -357,7 +358,7 @@ public void add(GHRepository r) throws IOException { * @throws IOException * the io exception */ - public void add(GHRepository r, GHOrganization.RepositoryRole permission) throws IOException { + public void add(GHRepository r, GHOrganization.RepositoryRole permission) { root().createRequest() .method("PUT") .with("permission", @@ -374,7 +375,7 @@ public void add(GHRepository r, GHOrganization.RepositoryRole permission) throws * @throws IOException * the io exception */ - public void remove(GHRepository r) throws IOException { + public void remove(GHRepository r) { root().createRequest() .method("DELETE") .withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())) @@ -387,7 +388,7 @@ public void remove(GHRepository r) throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(api("")).send(); } @@ -401,7 +402,7 @@ private String api(String tail) { return "/organizations/" + organization.getId() + "/team/" + getId() + tail; } - private String publicApi(String tail) throws IOException { + private String publicApi(String tail) { return "/orgs/" + getOrganization().login + "/teams/" + getSlug() + tail; } @@ -416,7 +417,7 @@ private String publicApi(String tail) throws IOException { * @throws IOException * the io exception */ - public GHDiscussion.Creator createDiscussion(String title) throws IOException { + public GHDiscussion.Creator createDiscussion(String title) { return GHDiscussion.create(this).title(title); } @@ -429,17 +430,22 @@ public GHDiscussion.Creator createDiscussion(String title) throws IOException { * @see documentation */ - public List getExternalGroups() throws IOException { + public List getExternalGroups() { try { return Collections.unmodifiableList(Arrays.asList(root().createRequest() .method("GET") .withUrlPath(publicApi(EXTERNAL_GROUPS)) .fetch(GHExternalGroupPage.class) .getGroups())); - } catch (final HttpException e) { - throw EnterpriseManagedSupport.forOrganization(getOrganization()) - .filterException(e, "Could not retrieve team external groups") - .orElse(e); + } catch (final UncheckedIOException ue) { + if (HttpException.class.isInstance(ue.getCause())) { + HttpException e = (HttpException) ue.getCause(); + throw new UncheckedIOException(EnterpriseManagedSupport.forOrganization(getOrganization()) + .filterException(e, "Could not retrieve team external group") + .orElse(e)); + } else { + throw ue; + } } } @@ -454,7 +460,7 @@ public List getExternalGroups() throws IOException { * @see documentation */ - public GHExternalGroup connectToExternalGroup(final GHExternalGroup group) throws IOException { + public GHExternalGroup connectToExternalGroup(final GHExternalGroup group) { return connectToExternalGroup(group.getId()); } @@ -469,7 +475,7 @@ public GHExternalGroup connectToExternalGroup(final GHExternalGroup group) throw * @see documentation */ - public GHExternalGroup connectToExternalGroup(final long group_id) throws IOException { + public GHExternalGroup connectToExternalGroup(final long group_id) { try { return root().createRequest() .method("PATCH") @@ -477,10 +483,15 @@ public GHExternalGroup connectToExternalGroup(final long group_id) throws IOExce .withUrlPath(publicApi(EXTERNAL_GROUPS)) .fetch(GHExternalGroup.class) .wrapUp(getOrganization()); - } catch (final HttpException e) { - throw EnterpriseManagedSupport.forOrganization(getOrganization()) - .filterException(e, "Could not connect team to external group") - .orElse(e); + } catch (final UncheckedIOException ue) { + if (HttpException.class.isInstance(ue.getCause())) { + HttpException e = (HttpException) ue.getCause(); + throw new UncheckedIOException(EnterpriseManagedSupport.forOrganization(getOrganization()) + .filterException(e, "Could not retrieve team external group") + .orElse(e)); + } else { + throw ue; + } } } @@ -492,7 +503,7 @@ public GHExternalGroup connectToExternalGroup(final long group_id) throws IOExce * @see documentation */ - public void deleteExternalGroupConnection() throws IOException { + public void deleteExternalGroupConnection() { root().createRequest().method("DELETE").withUrlPath(publicApi(EXTERNAL_GROUPS)).send(); } @@ -504,8 +515,8 @@ public void deleteExternalGroupConnection() throws IOException { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") - public GHOrganization getOrganization() throws IOException { - refresh(organization); + public GHOrganization getOrganization() { + refreshWithUnchecked(organization); return organization; } diff --git a/src/main/java/org/kohsuke/github/GHTeamBuilder.java b/src/main/java/org/kohsuke/github/GHTeamBuilder.java index 6db44008af..cb2b397601 100644 --- a/src/main/java/org/kohsuke/github/GHTeamBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTeamBuilder.java @@ -116,7 +116,7 @@ public GHTeamBuilder parentTeamId(long parentTeamId) { * @throws IOException * if team cannot be created */ - public GHTeam create() throws IOException { + public GHTeam create() { return builder.method("POST").withUrlPath("/orgs/" + orgName + "/teams").fetch(GHTeam.class).wrapUp(root()); } } diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 2bafc28307..db4d409735 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -4,6 +4,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Date; // TODO: Auto-generated Javadoc @@ -118,7 +119,7 @@ public String getLastCommentUrl() { * @throws IOException * the io exception */ - public GHIssue getBoundIssue() throws IOException { + public GHIssue getBoundIssue() { if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type)) return null; return repository.getIssue(Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1))); @@ -131,7 +132,7 @@ public GHIssue getBoundIssue() throws IOException { * @throws IOException * the io exception */ - public GHPullRequest getBoundPullRequest() throws IOException { + public GHPullRequest getBoundPullRequest() { if (!"PullRequest".equals(subject.type)) return null; return repository.getPullRequest(Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1))); @@ -144,7 +145,7 @@ public GHPullRequest getBoundPullRequest() throws IOException { * @throws IOException * the io exception */ - public GHCommit getBoundCommit() throws IOException { + public GHCommit getBoundCommit() { if (!"Commit".equals(subject.type)) return null; return repository.getCommit(subject.url.substring(subject.url.lastIndexOf('/') + 1)); @@ -156,7 +157,7 @@ public GHCommit getBoundCommit() throws IOException { * @throws IOException * the io exception */ - public void markAsRead() throws IOException { + public void markAsRead() { root().createRequest().method("PATCH").withUrlPath(url).send(); } @@ -171,7 +172,7 @@ public void markAsRead() throws IOException { * @throws IOException * the io exception */ - public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { + public GHSubscription subscribe(boolean subscribed, boolean ignored) { return root().createRequest() .method("PUT") .with("subscribed", subscribed) @@ -187,11 +188,14 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx * @throws IOException * the io exception */ - public GHSubscription getSubscription() throws IOException { + public GHSubscription getSubscription() { try { return root().createRequest().method("POST").withUrlPath(subscription_url).fetch(GHSubscription.class); - } catch (FileNotFoundException e) { - return null; + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + return null; + } + throw e; } } } diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index c7e1902124..70bc5d4b6f 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -131,7 +131,7 @@ public GHTreeBuilder add(String path, byte[] content, boolean executable) { try { String dataSha = repo.createBlob().binaryContent(content).create().getSha(); return shaEntry(path, dataSha, executable); - } catch (IOException e) { + } catch (Exception e) { throw new GHException("Cannot create binary content of '" + path + "'", e); } } @@ -175,7 +175,7 @@ private String getApiTail() { * @throws IOException * the io exception */ - public GHTree create() throws IOException { + public GHTree create() { req.with("tree", treeEntries); return req.method("POST").withUrlPath(getApiTail()).fetch(GHTree.class).wrap(repo); } diff --git a/src/main/java/org/kohsuke/github/GHTreeEntry.java b/src/main/java/org/kohsuke/github/GHTreeEntry.java index 6759378e1f..71e1ab5c2d 100644 --- a/src/main/java/org/kohsuke/github/GHTreeEntry.java +++ b/src/main/java/org/kohsuke/github/GHTreeEntry.java @@ -87,7 +87,7 @@ public URL getUrl() { * @throws IOException * the io exception */ - public GHBlob asBlob() throws IOException { + public GHBlob asBlob() { if (type.equals("blob")) return tree.repo.getBlob(sha); else @@ -101,7 +101,7 @@ public GHBlob asBlob() throws IOException { * @throws IOException * the io exception */ - public InputStream readAsBlob() throws IOException { + public InputStream readAsBlob() { if (type.equals("blob")) return tree.repo.readBlob(sha); else @@ -115,7 +115,7 @@ public InputStream readAsBlob() throws IOException { * @throws IOException * the io exception */ - public GHTree asTree() throws IOException { + public GHTree asTree() { if (type.equals("tree")) return tree.repo.getTree(sha); else diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index fd93a00937..3d0e615692 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -53,7 +53,7 @@ public GHUser() { * @throws IOException * the io exception */ - public List getKeys() throws IOException { + public List getKeys() { return root().createRequest().withUrlPath(getApiTailUrl("keys")).toIterable(GHKey[].class, null).toList(); } @@ -63,7 +63,7 @@ public List getKeys() throws IOException { * @throws IOException * the io exception */ - public void follow() throws IOException { + public void follow() { root().createRequest().method("PUT").withUrlPath("/user/following/" + login).send(); } @@ -73,7 +73,7 @@ public void follow() throws IOException { * @throws IOException * the io exception */ - public void unfollow() throws IOException { + public void unfollow() { root().createRequest().method("DELETE").withUrlPath("/user/following/" + login).send(); } @@ -84,7 +84,7 @@ public void unfollow() throws IOException { * @throws IOException * the io exception */ - public GHPersonSet getFollows() throws IOException { + public GHPersonSet getFollows() { return new GHPersonSet(listFollows().toList()); } @@ -104,7 +104,7 @@ public PagedIterable listFollows() { * @throws IOException * the io exception */ - public GHPersonSet getFollowers() throws IOException { + public GHPersonSet getFollowers() { return new GHPersonSet(listFollowers().toList()); } @@ -214,7 +214,7 @@ public String getBio() { * @throws IOException * the io exception */ - public GHPersonSet getOrganizations() throws IOException { + public GHPersonSet getOrganizations() { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); for (GHOrganization o : root().createRequest() @@ -234,7 +234,7 @@ public GHPersonSet getOrganizations() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public PagedIterable listEvents() throws IOException { + public PagedIterable listEvents() { return root().createRequest() .withUrlPath(String.format("/users/%s/events", login)) .toIterable(GHEventInfo[].class, null); @@ -247,7 +247,7 @@ public PagedIterable listEvents() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listGists() throws IOException { + public PagedIterable listGists() { return root().createRequest() .withUrlPath(String.format("/users/%s/gists", login)) .toIterable(GHGist[].class, null); @@ -263,7 +263,7 @@ public PagedIterable listGists() throws IOException { * href=https://docs.github.com/en/enterprise-server@3.3/admin/identity-and-access-management/authenticating-users-for-your-github-enterprise-server-instance/using-ldap>Github * LDAP */ - public Optional getLdapDn() throws IOException { + public Optional getLdapDn() { super.populate(); return Optional.ofNullable(ldap_dn); } @@ -275,7 +275,7 @@ public Optional getLdapDn() throws IOException { * @throws IOException * on error */ - public Date getSuspendedAt() throws IOException { + public Date getSuspendedAt() { super.populate(); return GitHubClient.parseDate(suspendedAt); } diff --git a/src/main/java/org/kohsuke/github/GHWorkflow.java b/src/main/java/org/kohsuke/github/GHWorkflow.java index 522870a9cf..e7e4f385c2 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflow.java +++ b/src/main/java/org/kohsuke/github/GHWorkflow.java @@ -70,7 +70,7 @@ public String getState() { * @throws IOException * Signals that an I/O exception has occurred. */ - public URL getHtmlUrl() throws IOException { + public URL getHtmlUrl() { return GitHubClient.parseURL(htmlUrl); } @@ -99,7 +99,7 @@ public URL getBadgeUrl() { * @throws IOException * the io exception */ - public void disable() throws IOException { + public void disable() { root().createRequest().method("PUT").withUrlPath(getApiRoute(), "disable").send(); } @@ -109,7 +109,7 @@ public void disable() throws IOException { * @throws IOException * the io exception */ - public void enable() throws IOException { + public void enable() { root().createRequest().method("PUT").withUrlPath(getApiRoute(), "enable").send(); } @@ -121,7 +121,7 @@ public void enable() throws IOException { * @throws IOException * the io exception */ - public void dispatch(String ref) throws IOException { + public void dispatch(String ref) { dispatch(ref, Collections.emptyMap()); } @@ -136,7 +136,7 @@ public void dispatch(String ref) throws IOException { * @throws IOException * the io exception */ - public void dispatch(String ref, Map inputs) throws IOException { + public void dispatch(String ref, Map inputs) { Requester requester = root().createRequest() .method("POST") .withUrlPath(getApiRoute(), "dispatches") diff --git a/src/main/java/org/kohsuke/github/GHWorkflowJob.java b/src/main/java/org/kohsuke/github/GHWorkflowJob.java index 76a2fddaef..454c1ce1cb 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowJob.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowJob.java @@ -231,7 +231,7 @@ public GHRepository getRepository() { * @throws IOException * The IO exception. */ - public T downloadLogs(InputStreamFunction streamFunction) throws IOException { + public T downloadLogs(InputStreamFunction streamFunction) { requireNonNull(streamFunction, "Stream function must not be null"); return root().createRequest().method("GET").withUrlPath(getApiRoute(), "logs").fetchStream(streamFunction); diff --git a/src/main/java/org/kohsuke/github/GHWorkflowRun.java b/src/main/java/org/kohsuke/github/GHWorkflowRun.java index 6077e4480c..319e620d70 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowRun.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowRun.java @@ -115,7 +115,7 @@ public long getRunAttempt() { * @throws IOException * on error */ - public Date getRunStartedAt() throws IOException { + public Date getRunStartedAt() { return GitHubClient.parseDate(runStartedAt); } @@ -126,7 +126,7 @@ public Date getRunStartedAt() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public URL getHtmlUrl() throws IOException { + public URL getHtmlUrl() { return GitHubClient.parseURL(htmlUrl); } @@ -281,11 +281,11 @@ public GHRepository getRepository() { * @throws IOException * the io exception */ - public List getPullRequests() throws IOException { + public List getPullRequests() { if (pullRequests != null && pullRequests.length != 0) { for (GHPullRequest pullRequest : pullRequests) { // Only refresh if we haven't do so before - pullRequest.refresh(pullRequest.getTitle()); + pullRequest.refreshWithUnchecked(pullRequest.getTitle()); } return Collections.unmodifiableList(Arrays.asList(pullRequests)); } @@ -298,7 +298,7 @@ public List getPullRequests() throws IOException { * @throws IOException * the io exception */ - public void cancel() throws IOException { + public void cancel() { root().createRequest().method("POST").withUrlPath(getApiRoute(), "cancel").send(); } @@ -308,7 +308,7 @@ public void cancel() throws IOException { * @throws IOException * the io exception */ - public void delete() throws IOException { + public void delete() { root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @@ -318,7 +318,7 @@ public void delete() throws IOException { * @throws IOException * the io exception */ - public void rerun() throws IOException { + public void rerun() { root().createRequest().method("POST").withUrlPath(getApiRoute(), "rerun").send(); } @@ -328,7 +328,7 @@ public void rerun() throws IOException { * @throws IOException * the io exception */ - public void approve() throws IOException { + public void approve() { root().createRequest().method("POST").withUrlPath(getApiRoute(), "approve").send(); } @@ -356,7 +356,7 @@ public PagedIterable listArtifacts() { * @throws IOException * The IO exception. */ - public T downloadLogs(InputStreamFunction streamFunction) throws IOException { + public T downloadLogs(InputStreamFunction streamFunction) { requireNonNull(streamFunction, "Stream function must not be null"); return root().createRequest().method("GET").withUrlPath(getApiRoute(), "logs").fetchStream(streamFunction); @@ -368,7 +368,7 @@ public T downloadLogs(InputStreamFunction streamFunction) throws IOExcept * @throws IOException * the io exception */ - public void deleteLogs() throws IOException { + public void deleteLogs() { root().createRequest().method("DELETE").withUrlPath(getApiRoute(), "logs").send(); } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index aa5b6239e3..f877aa76f5 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -178,7 +178,7 @@ public String getLogin() { if (u != null) { login = u.getLogin(); } - } catch (IOException e) { + } catch (Exception e) { } } return login; @@ -464,12 +464,12 @@ public GHRateLimit rateLimit() throws IOException { * the io exception */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected") - public GHMyself getMyself() throws IOException { + public GHMyself getMyself() { client.requireCredential(); return setMyself(); } - private GHMyself setMyself() throws IOException { + private GHMyself setMyself() { synchronized (this) { if (this.myself == null) { this.myself = createRequest().withUrlPath("/user").fetch(GHMyself.class); @@ -487,7 +487,7 @@ private GHMyself setMyself() throws IOException { * @throws IOException * the io exception */ - public GHUser getUser(String login) throws IOException { + public GHUser getUser(String login) { GHUser u = users.get(login); if (u == null) { u = createRequest().withUrlPath("/users/" + login).fetch(GHUser.class); @@ -529,7 +529,7 @@ protected GHUser getUser(GHUser orig) { * @throws IOException * the io exception */ - public GHOrganization getOrganization(String name) throws IOException { + public GHOrganization getOrganization(String name) { GHOrganization o = orgs.get(name); if (o == null) { o = createRequest().withUrlPath("/orgs/" + name).fetch(GHOrganization.class); @@ -571,7 +571,7 @@ public PagedIterable listOrganizations(final String since) { * the io exception * @see GHRepository#getName() GHRepository#getName() */ - public GHRepository getRepository(String name) throws IOException { + public GHRepository getRepository(String name) { String[] tokens = name.split("/"); if (tokens.length != 2) { throw new IllegalArgumentException("Repository name must be in format owner/repo"); @@ -588,7 +588,7 @@ public GHRepository getRepository(String name) throws IOException { * @throws IOException * the io exception */ - public GHRepository getRepositoryById(long id) throws IOException { + public GHRepository getRepositoryById(long id) { return createRequest().withUrlPath("/repositories/" + id).fetch(GHRepository.class); } @@ -600,7 +600,7 @@ public GHRepository getRepositoryById(long id) throws IOException { * the io exception * @see GitHub API - Licenses */ - public PagedIterable listLicenses() throws IOException { + public PagedIterable listLicenses() { return createRequest().withUrlPath("/licenses").toIterable(GHLicense[].class, null); } @@ -611,7 +611,7 @@ public PagedIterable listLicenses() throws IOException { * @throws IOException * the io exception */ - public PagedIterable listUsers() throws IOException { + public PagedIterable listUsers() { return createRequest().withUrlPath("/users").toIterable(GHUser[].class, null); } @@ -625,7 +625,7 @@ public PagedIterable listUsers() throws IOException { * the io exception * @see GHLicense#getKey() GHLicense#getKey() */ - public GHLicense getLicense(String key) throws IOException { + public GHLicense getLicense(String key) { return createRequest().withUrlPath("/licenses/" + key).fetch(GHLicense.class); } @@ -642,7 +642,7 @@ public GHLicense getLicense(String key) throws IOException { * @see List * Plans */ - public PagedIterable listMarketplacePlans() throws IOException { + public PagedIterable listMarketplacePlans() { return createRequest().withUrlPath("/marketplace_listing/plans").toIterable(GHMarketplacePlan[].class, null); } @@ -653,7 +653,7 @@ public PagedIterable listMarketplacePlans() throws IOExceptio * @throws IOException * the io exception */ - public List getMyInvitations() throws IOException { + public List getMyInvitations() { return createRequest().withUrlPath("/user/repository_invitations") .toIterable(GHInvitation[].class, null) .toList(); @@ -669,7 +669,7 @@ public List getMyInvitations() throws IOException { * @throws IOException * the io exception */ - public Map getMyOrganizations() throws IOException { + public Map getMyOrganizations() { GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs") .toIterable(GHOrganization[].class, null) .toArray(); @@ -695,7 +695,7 @@ public Map getMyOrganizations() throws IOException { * @see Get a user's * Marketplace purchases */ - public PagedIterable getMyMarketplacePurchases() throws IOException { + public PagedIterable getMyMarketplacePurchases() { return createRequest().withUrlPath("/user/marketplace_purchases") .toIterable(GHMarketplaceUserPurchase[].class, null); } @@ -709,7 +709,7 @@ public PagedIterable getMyMarketplacePurchases() thro * @throws IOException * the io exception */ - public Map getUserPublicOrganizations(GHUser user) throws IOException { + public Map getUserPublicOrganizations(GHUser user) { return getUserPublicOrganizations(user.getLogin()); } @@ -724,7 +724,7 @@ public Map getUserPublicOrganizations(GHUser user) throw * @throws IOException * the io exception */ - public Map getUserPublicOrganizations(String login) throws IOException { + public Map getUserPublicOrganizations(String login) { GHOrganization[] orgs = createRequest().withUrlPath("/users/" + login + "/orgs") .toIterable(GHOrganization[].class, null) .toArray(); @@ -746,7 +746,7 @@ public Map getUserPublicOrganizations(String login) thro * @throws IOException * the io exception */ - public Map> getMyTeams() throws IOException { + public Map> getMyTeams() { Map> allMyTeams = new HashMap<>(); for (GHTeam team : createRequest().withUrlPath("/user/teams") .toIterable(GHTeam[].class, item -> item.wrapUp(this)) @@ -769,7 +769,7 @@ public Map> getMyTeams() throws IOException { * @throws IOException * the io exception */ - public List getEvents() throws IOException { + public List getEvents() { return createRequest().withUrlPath("/events").toIterable(GHEventInfo[].class, null).toList(); } @@ -784,7 +784,7 @@ public List getEvents() throws IOException { * @throws IOException * the io exception */ - public List getUserPublicEvents(String login) throws IOException { + public List getUserPublicEvents(String login) { return createRequest().withUrlPath("/users/" + login + "/events/public") .toIterable(GHEventInfo[].class, null) .toList(); @@ -799,7 +799,7 @@ public List getUserPublicEvents(String login) throws IOException { * @throws IOException * the io exception */ - public GHGist getGist(String id) throws IOException { + public GHGist getGist(String id) { return createRequest().withUrlPath("/gists/" + id).fetch(GHGist.class); } @@ -929,7 +929,7 @@ public GHAuthorization createOrGetAuth(String clientId, String clientSecret, List scopes, String note, - String note_url) throws IOException { + String note_url) { Requester requester = createRequest().with("client_secret", clientSecret) .with("scopes", scopes) .with("note", note) @@ -948,7 +948,7 @@ public GHAuthorization createOrGetAuth(String clientId, * @see Delete an * authorization */ - public void deleteAuth(long id) throws IOException { + public void deleteAuth(long id) { createRequest().method("DELETE").withUrlPath("/authorizations/" + id).send(); } @@ -965,7 +965,7 @@ public void deleteAuth(long id) throws IOException { * @see Check an * authorization */ - public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { + public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) { return createRequest().withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) .fetch(GHAuthorization.class); } @@ -983,7 +983,7 @@ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String acces * @see Reset an * authorization */ - public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { + public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) { return createRequest().method("POST") .withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) .fetch(GHAuthorization.class); @@ -998,7 +998,7 @@ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String acces * @see List your * authorizations */ - public PagedIterable listMyAuthorizations() throws IOException { + public PagedIterable listMyAuthorizations() { return createRequest().withUrlPath("/authorizations").toIterable(GHAuthorization[].class, null); } @@ -1013,7 +1013,7 @@ public PagedIterable listMyAuthorizations() throws IOException * @see Get the authenticated * GitHub App */ - public GHApp getApp() throws IOException { + public GHApp getApp() { return createRequest().withUrlPath("/app").fetch(GHApp.class); } @@ -1027,7 +1027,7 @@ public GHApp getApp() throws IOException { * the IO exception * @see Get an app */ - public GHApp getApp(@Nonnull String slug) throws IOException { + public GHApp getApp(@Nonnull String slug) { return createRequest().withUrlPath("/apps/" + slug).fetch(GHApp.class); } @@ -1043,7 +1043,7 @@ public GHApp getApp(@Nonnull String slug) throws IOException { * "https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-a-github-app-from-a-manifest">Get an * app */ - public GHAppFromManifest createAppFromManifest(@Nonnull String code) throws IOException { + public GHAppFromManifest createAppFromManifest(@Nonnull String code) { return createRequest().method("POST") .withUrlPath("/app-manifests/" + code + "/conversions") .fetch(GHAppFromManifest.class); @@ -1060,7 +1060,7 @@ public GHAppFromManifest createAppFromManifest(@Nonnull String code) throws IOEx * the io exception * @see GitHub App installations */ - public GHAuthenticatedAppInstallation getInstallation() throws IOException { + public GHAuthenticatedAppInstallation getInstallation() { return new GHAuthenticatedAppInstallation(this); } @@ -1082,7 +1082,7 @@ public boolean isCredentialValid() { * authentication * @see Get Meta */ - public GHMeta getMeta() throws IOException { + public GHMeta getMeta() { return this.sanityCachedMeta.get(() -> createRequest().withUrlPath("/meta").fetch(GHMeta.class)); } @@ -1095,7 +1095,7 @@ public GHMeta getMeta() throws IOException { * @throws IOException * the io exception */ - public GHProject getProject(long id) throws IOException { + public GHProject getProject(long id) { return createRequest().withUrlPath("/projects/" + id).fetch(GHProject.class); } @@ -1108,7 +1108,7 @@ public GHProject getProject(long id) throws IOException { * @throws IOException * the io exception */ - public GHProjectColumn getProjectColumn(long id) throws IOException { + public GHProjectColumn getProjectColumn(long id) { return createRequest().withUrlPath("/projects/columns/" + id).fetch(GHProjectColumn.class).lateBind(this); } @@ -1121,7 +1121,7 @@ public GHProjectColumn getProjectColumn(long id) throws IOException { * @throws IOException * the io exception */ - public GHProjectCard getProjectCard(long id) throws IOException { + public GHProjectCard getProjectCard(long id) { return createRequest().withUrlPath("/projects/columns/cards/" + id).fetch(GHProjectCard.class).lateBind(this); } @@ -1320,7 +1320,7 @@ Requester createRequest() { * @throws IOException * Signals that an I/O exception has occurred. */ - GHUser intern(GHUser user) throws IOException { + GHUser intern(GHUser user) { if (user != null) { // if we already have this user in our map, get it // if not, remember this new user diff --git a/src/main/java/org/kohsuke/github/GitHubClient.java b/src/main/java/org/kohsuke/github/GitHubClient.java index 38552b573c..e77a2f3e71 100644 --- a/src/main/java/org/kohsuke/github/GitHubClient.java +++ b/src/main/java/org/kohsuke/github/GitHubClient.java @@ -270,14 +270,17 @@ GHRateLimit getRateLimit(@Nonnull RateLimitTarget rateLimitTarget) throws IOExce (connectorResponse) -> GitHubResponse.parseBody(connectorResponse, JsonRateLimit.class)) .body().resources; - } catch (FileNotFoundException e) { - // For some versions of GitHub Enterprise, the rate_limit endpoint returns a 404. - LOGGER.log(FINE, "(%s) /rate_limit returned 404 Not Found.", sendRequestTraceId.get()); - - // However some newer versions of GHE include rate limit header information - // If the header info is missing and the endpoint returns 404, fill the rate limit - // with unknown - result = GHRateLimit.fromRecord(GHRateLimit.UnknownLimitRecord.current(), rateLimitTarget); + } catch (UncheckedIOException e) { + if (FileNotFoundException.class.isInstance(e)) { + // For some versions of GitHub Enterprise, the rate_limit endpoint returns a 404. + LOGGER.log(FINE, "(%s) /rate_limit returned 404 Not Found.", sendRequestTraceId.get()); + + // However some newer versions of GHE include rate limit header information + // If the header info is missing and the endpoint returns 404, fill the rate limit + // with unknown + result = GHRateLimit.fromRecord(GHRateLimit.UnknownLimitRecord.current(), rateLimitTarget); + } + throw e; } return result; }); diff --git a/src/main/java/org/kohsuke/github/PagedIterable.java b/src/main/java/org/kohsuke/github/PagedIterable.java index 7dc17aa0eb..1860eb7edd 100644 --- a/src/main/java/org/kohsuke/github/PagedIterable.java +++ b/src/main/java/org/kohsuke/github/PagedIterable.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.io.UncheckedIOException; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; @@ -76,7 +77,7 @@ public final PagedIterator iterator() { * @throws IOException * if an I/O exception occurs. */ - protected T[] toArray(final PagedIterator iterator) throws IOException { + protected T[] toArray(final PagedIterator iterator) { try { ArrayList pages = new ArrayList<>(); int totalSize = 0; @@ -94,7 +95,7 @@ protected T[] toArray(final PagedIterator iterator) throws IOException { // if there was an exception inside the iterator it is wrapped as a GHException // if the wrapped exception is an IOException, throw that if (e.getCause() instanceof IOException) { - throw (IOException) e.getCause(); + throw new UncheckedIOException((IOException) e.getCause()); } else { throw e; } @@ -109,7 +110,7 @@ protected T[] toArray(final PagedIterator iterator) throws IOException { * if an I/O exception occurs. */ @Nonnull - public T[] toArray() throws IOException { + public T[] toArray() { return toArray(iterator()); } @@ -121,7 +122,7 @@ public T[] toArray() throws IOException { * if an I/O Exception occurs */ @Nonnull - public List toList() throws IOException { + public List toList() { return Collections.unmodifiableList(Arrays.asList(this.toArray())); } @@ -133,7 +134,7 @@ public List toList() throws IOException { * if an I/O Exception occurs */ @Nonnull - public Set toSet() throws IOException { + public Set toSet() { return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(this.toArray()))); } diff --git a/src/main/java/org/kohsuke/github/Refreshable.java b/src/main/java/org/kohsuke/github/Refreshable.java index c8a954b32f..73a2e9f277 100644 --- a/src/main/java/org/kohsuke/github/Refreshable.java +++ b/src/main/java/org/kohsuke/github/Refreshable.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.io.UncheckedIOException; // TODO: Auto-generated Javadoc /** @@ -30,4 +31,22 @@ default void refresh(Object value) throws IOException { this.refresh(); } } + + /** + * Calls refresh if the provided value is null. + * + * @param value + * the value + * @throws IOException + * the io exception + */ + default void refreshWithUnchecked(Object value) { + try { + if (value == null) { + this.refresh(); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 1e5e987657..006a6c3d49 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -31,6 +31,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.util.Iterator; import java.util.function.Consumer; @@ -64,10 +65,14 @@ class Requester extends GitHubRequest.Builder { * @throws IOException * the io exception */ - public void send() throws IOException { + public void send() { // Send expects there to be some body response, but doesn't care what it is. // If there isn't a body, this will throw. - client.sendRequest(this, (connectorResponse) -> GitHubResponse.getBodyAsString(connectorResponse)); + try { + client.sendRequest(this, (connectorResponse) -> GitHubResponse.getBodyAsString(connectorResponse)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } /** @@ -81,9 +86,14 @@ public void send() throws IOException { * @throws IOException * if the server returns 4xx/5xx responses. */ - public T fetch(@Nonnull Class type) throws IOException { - return client.sendRequest(this, (connectorResponse) -> GitHubResponse.parseBody(connectorResponse, type)) - .body(); + public T fetch(@Nonnull Class type) { + try { + return client.sendRequest(this, (connectorResponse) -> GitHubResponse.parseBody(connectorResponse, type)) + .body(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } /** @@ -97,10 +107,16 @@ public T fetch(@Nonnull Class type) throws IOException { * @throws IOException * the io exception */ - public T fetchInto(@Nonnull T existingInstance) throws IOException { - return client - .sendRequest(this, (connectorResponse) -> GitHubResponse.parseBody(connectorResponse, existingInstance)) - .body(); + public T fetchInto(@Nonnull T existingInstance) { + try { + return client + .sendRequest(this, + (connectorResponse) -> GitHubResponse.parseBody(connectorResponse, existingInstance)) + .body(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } /** @@ -111,8 +127,13 @@ public T fetchInto(@Nonnull T existingInstance) throws IOException { * @throws IOException * the io exception */ - public int fetchHttpStatusCode() throws IOException { - return client.sendRequest(build(), null).statusCode(); + public int fetchHttpStatusCode() { + try { + return client.sendRequest(build(), null).statusCode(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } /** @@ -127,8 +148,14 @@ public int fetchHttpStatusCode() throws IOException { * @throws IOException * the io exception */ - public T fetchStream(@Nonnull InputStreamFunction handler) throws IOException { - return client.sendRequest(this, (connectorResponse) -> handler.apply(connectorResponse.bodyStream())).body(); + public T fetchStream(@Nonnull InputStreamFunction handler) { + try { + return client.sendRequest(this, (connectorResponse) -> handler.apply(connectorResponse.bodyStream())) + .body(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } /** @@ -147,8 +174,13 @@ public T fetchStream(@Nonnull InputStreamFunction handler) throws IOExcep * if an error occurs while copying the stream */ @NonNull - public static InputStream copyInputStream(InputStream inputStream) throws IOException { - return new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); + public static InputStream copyInputStream(InputStream inputStream) { + try { + return new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } /** @@ -168,6 +200,5 @@ public static InputStream copyInputStream(InputStream inputStream) throws IOExce */ public PagedIterable toIterable(Class type, Consumer itemInitializer) { return new GitHubPageContentsIterable<>(client, build(), type, itemInitializer); - } } diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java index 7cea51bda0..076f83d2ad 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.*; import static org.hamcrest.Matchers.*; @@ -204,7 +205,7 @@ protected GHUser getUser() { protected static GHUser getUser(GitHub gitHub) { try { return gitHub.getMyself(); - } catch (IOException e) { + } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } @@ -287,8 +288,12 @@ protected void cleanupRepository(String fullName) throws IOException { if (repository != null) { repository.delete(); } - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { // Repo already deleted + if (!(e.getCause() instanceof GHFileNotFoundException)) { + throw e; + } + } } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 9f73194b15..c4bdfdfedd 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -14,6 +14,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; @@ -1608,8 +1609,8 @@ public void testRepoLabel() throws IOException { try { t = r.getLabel("test"); fail("Test label should be deleted."); - } catch (IOException ex) { - assertThat(ex, instanceOf(FileNotFoundException.class)); + } catch (UncheckedIOException ex) { + assertThat(ex.getCause(), instanceOf(FileNotFoundException.class)); } t = r.createLabel("test2", "123457", "this is a different test"); @@ -1645,7 +1646,7 @@ void cleanupLabel(String name) { try { GHLabel t = getNonRecordingGitHub().getRepository("hub4j-test-org/test-labels").getLabel(name); t.delete(); - } catch (IOException e) { + } catch (UncheckedIOException e) { } } diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index 27a3023636..56965edcc8 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -171,7 +171,7 @@ public void deleteInstallation() throws IOException { GHAppInstallation installation = app.getInstallationByUser("bogus"); try { installation.deleteInstallation(); - } catch (IOException e) { + } catch (Exception e) { fail("deleteInstallation wasn't suppose to fail in this test"); } } diff --git a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java index 36151cea4f..d3bf9d2902 100644 --- a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java @@ -8,6 +8,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.util.List; @@ -48,7 +49,7 @@ public void cleanup() throws Exception { if (content != null) { content.delete("Cleanup"); } - } catch (IOException e) { + } catch (Exception e) { } } } @@ -220,8 +221,8 @@ public void testCRUDContent() throws Exception { try { repo.getFileContent(createdFilename); fail("Delete didn't work!"); - } catch (GHFileNotFoundException e) { - assertThat(e.getMessage(), + } catch (UncheckedIOException e) { + assertThat(e.getCause().getMessage(), endsWith( "/repos/hub4j-test-org/GHContentIntegrationTest/contents/test+directory%20%2350/test%20file-to+create-%231.txt {\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/reference/repos#get-repository-content\"}")); } diff --git a/src/test/java/org/kohsuke/github/GHDiscussionTest.java b/src/test/java/org/kohsuke/github/GHDiscussionTest.java index a2b68db1b5..48b1f7508f 100644 --- a/src/test/java/org/kohsuke/github/GHDiscussionTest.java +++ b/src/test/java/org/kohsuke/github/GHDiscussionTest.java @@ -4,8 +4,8 @@ import org.junit.Before; import org.junit.Test; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Set; import static org.hamcrest.Matchers.*; @@ -94,9 +94,9 @@ public void testCreatedDiscussion() throws IOException { try { team.createDiscussion("Some Discussion").done(); fail("Body is required."); - } catch (HttpException e) { - assertThat(e, instanceOf(HttpException.class)); - assertThat(e.getMessage(), + } catch (UncheckedIOException e) { + assertThat(e.getCause(), instanceOf(HttpException.class)); + assertThat(e.getCause().getMessage(), containsString("https://developer.github.com/v3/teams/discussions/#create-a-discussion")); } } @@ -182,8 +182,8 @@ public void testToDeleteDiscussion() throws IOException { try { gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(TEAM_SLUG).getDiscussion(discussion.getNumber()); fail(); - } catch (FileNotFoundException e) { - assertThat(e.getMessage(), + } catch (UncheckedIOException e) { + assertThat(e.getCause().getMessage(), containsString("https://developer.github.com/v3/teams/discussions/#get-a-single-discussion")); } } diff --git a/src/test/java/org/kohsuke/github/GHGistTest.java b/src/test/java/org/kohsuke/github/GHGistTest.java index 14e02f1c23..a81c579799 100644 --- a/src/test/java/org/kohsuke/github/GHGistTest.java +++ b/src/test/java/org/kohsuke/github/GHGistTest.java @@ -3,6 +3,7 @@ import org.junit.Test; import java.io.FileNotFoundException; +import java.io.UncheckedIOException; import static org.hamcrest.Matchers.*; @@ -107,8 +108,8 @@ public void lifecycleTest() throws Exception { try { gitHub.getGist(id); fail("Gist should be deleted."); - } catch (FileNotFoundException e) { - assertThat(e, notNullValue()); + } catch (UncheckedIOException e) { + assertThat(e.getCause(), instanceOf(FileNotFoundException.class)); } } diff --git a/src/test/java/org/kohsuke/github/GHHookTest.java b/src/test/java/org/kohsuke/github/GHHookTest.java index ca6b1a7186..f4d0ad0c2b 100644 --- a/src/test/java/org/kohsuke/github/GHHookTest.java +++ b/src/test/java/org/kohsuke/github/GHHookTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -74,7 +75,8 @@ public void exposeResponceHeaders() throws Exception { // fails because application isn't approved in organisation and you can find it only after doing real call final GHHook hook = repository .createHook("my-hook", singletonMap("url", "http://localhost"), singletonList(GHEvent.PUSH), true); - } catch (IOException ex) { + } catch (UncheckedIOException e) { + IOException ex = e.getCause(); assertThat(ex, instanceOf(GHFileNotFoundException.class)); final GHFileNotFoundException ghFileNotFoundException = (GHFileNotFoundException) ex; final Map> responseHeaderFields = ghFileNotFoundException.getResponseHeaderFields(); diff --git a/src/test/java/org/kohsuke/github/GHIssueTest.java b/src/test/java/org/kohsuke/github/GHIssueTest.java index 5b1a45f3d6..65f8dc4551 100644 --- a/src/test/java/org/kohsuke/github/GHIssueTest.java +++ b/src/test/java/org/kohsuke/github/GHIssueTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import java.io.IOException; +import java.io.UncheckedIOException; import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.Date; @@ -16,6 +17,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; @@ -312,8 +314,9 @@ public void removeLabels() throws Exception { try { issue.removeLabel(label3); fail("Expected GHFileNotFoundException"); - } catch (GHFileNotFoundException e) { - assertThat(e.getMessage(), containsString("Label does not exist")); + } catch (UncheckedIOException e) { + assertThat(e.getCause(), instanceOf(GHFileNotFoundException.class)); + assertThat(e.getCause().getMessage(), containsString("Label does not exist")); } } diff --git a/src/test/java/org/kohsuke/github/GHProjectCardTest.java b/src/test/java/org/kohsuke/github/GHProjectCardTest.java index f3494b8a63..d360cfa727 100644 --- a/src/test/java/org/kohsuke/github/GHProjectCardTest.java +++ b/src/test/java/org/kohsuke/github/GHProjectCardTest.java @@ -4,8 +4,8 @@ import org.junit.Before; import org.junit.Test; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import static org.hamcrest.Matchers.*; @@ -143,7 +143,7 @@ public void testDeleteCard() throws IOException { try { card = gitHub.getProjectCard(card.getId()); assertThat(card, nullValue()); - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { card = null; } } @@ -162,7 +162,7 @@ public void after() throws IOException { try { card.delete(); card = null; - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { card = null; } } @@ -171,7 +171,7 @@ public void after() throws IOException { try { column.delete(); column = null; - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { column = null; } } @@ -180,7 +180,7 @@ public void after() throws IOException { try { project.delete(); project = null; - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { project = null; } } diff --git a/src/test/java/org/kohsuke/github/GHProjectColumnTest.java b/src/test/java/org/kohsuke/github/GHProjectColumnTest.java index ec09a4e3a2..a63c52dd4f 100644 --- a/src/test/java/org/kohsuke/github/GHProjectColumnTest.java +++ b/src/test/java/org/kohsuke/github/GHProjectColumnTest.java @@ -4,8 +4,8 @@ import org.junit.Before; import org.junit.Test; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; @@ -72,7 +72,7 @@ public void testDeleteColumn() throws IOException { try { column = gitHub.getProjectColumn(column.getId()); assertThat(column, nullValue()); - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { column = null; } } @@ -91,7 +91,7 @@ public void after() throws IOException { try { column.delete(); column = null; - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { column = null; } } @@ -100,7 +100,7 @@ public void after() throws IOException { try { project.delete(); project = null; - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { project = null; } } diff --git a/src/test/java/org/kohsuke/github/GHProjectTest.java b/src/test/java/org/kohsuke/github/GHProjectTest.java index 45f893e302..685a9e9865 100644 --- a/src/test/java/org/kohsuke/github/GHProjectTest.java +++ b/src/test/java/org/kohsuke/github/GHProjectTest.java @@ -4,8 +4,8 @@ import org.junit.Before; import org.junit.Test; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UncheckedIOException; import static org.hamcrest.Matchers.*; @@ -109,7 +109,7 @@ public void testDeleteProject() throws IOException { try { project = gitHub.getProject(project.getId()); assertThat(project, nullValue()); - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { project = null; } } @@ -128,7 +128,7 @@ public void after() throws IOException { try { project.delete(); project = null; - } catch (FileNotFoundException e) { + } catch (UncheckedIOException e) { project = null; } } diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index 0a2e4a2712..18ddf630a9 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -6,6 +6,7 @@ import org.kohsuke.github.GHPullRequest.AutoMerge; import java.io.IOException; +import java.io.UncheckedIOException; import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.Collections; @@ -217,8 +218,8 @@ public void getListOfCommits() throws Exception { try { String val = firstPR.get().listCommits().toArray()[0].getApiUrl().toString(); assertThat(val, notNullValue()); - } catch (GHFileNotFoundException e) { - if (e.getMessage().contains("/issues/")) { + } catch (UncheckedIOException e) { + if (e.getCause().getMessage().contains("/issues/")) { fail("Issued a request against the wrong path"); } } @@ -580,9 +581,9 @@ public void setBaseBranchNonExisting() throws Exception { try { pullRequest.setBaseBranch(newBaseBranch); - } catch (HttpException e) { - assertThat(e, instanceOf(HttpException.class)); - assertThat(e.toString(), containsString("Proposed base branch 'non-existing' was not found")); + } catch (UncheckedIOException e) { + assertThat(e.getCause(), instanceOf(HttpException.class)); + assertThat(e.getCause().toString(), containsString("Proposed base branch 'non-existing' was not found")); } pullRequest.close(); @@ -618,9 +619,9 @@ public void updateOutdatedBranchesUnexpectedHead() throws Exception { try { outdatedPullRequest.updateBranch(); - } catch (HttpException e) { - assertThat(e, instanceOf(HttpException.class)); - assertThat(e.toString(), containsString("expected head sha didn’t match current head ref.")); + } catch (UncheckedIOException e) { + assertThat(e.getCause(), instanceOf(HttpException.class)); + assertThat(e.getCause().toString(), containsString("expected head sha didn’t match current head ref.")); } outdatedPullRequest.close(); @@ -883,8 +884,9 @@ public void removeLabels() throws Exception { try { p.removeLabel(label3); fail("Expected GHFileNotFoundException"); - } catch (GHFileNotFoundException e) { - assertThat(e.getMessage(), containsString("Label does not exist")); + } catch (UncheckedIOException e) { + assertThat(e.getCause(), instanceOf(GHFileNotFoundException.class)); + assertThat(e.getCause().getMessage(), containsString("Label does not exist")); } } diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 4a339571a3..b711497f7e 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -11,9 +11,9 @@ import org.kohsuke.github.GHRepository.Visibility; import java.io.ByteArrayInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.net.URL; import java.time.LocalDate; import java.util.*; @@ -523,9 +523,9 @@ public void getPermission() throws Exception { try { r.getPermission("jglick"); fail(); - } catch (HttpException x) { + } catch (UncheckedIOException x) { // x.printStackTrace(); // good - assertThat(x.getResponseCode(), equalTo(403)); + assertThat(((HttpException) x.getCause()).getResponseCode(), equalTo(403)); } if (false) { @@ -535,7 +535,7 @@ public void getPermission() throws Exception { try { r.getPermission("jglick"); fail(); - } catch (FileNotFoundException x) { + } catch (UncheckedIOException x) { x.printStackTrace(); // good } } @@ -585,7 +585,7 @@ public void LatestRepositoryExist() { // add the repository that have latest release GHRelease release = gitHub.getRepository("kamontat/CheckIDNumber").getLatestRelease(); assertThat(release.getTagName(), equalTo("v3.0")); - } catch (IOException e) { + } catch (UncheckedIOException e) { e.printStackTrace(); fail(); } @@ -642,7 +642,7 @@ public void LatestRepositoryNotExist() { // add the repository that `NOT` have latest release GHRelease release = gitHub.getRepository("kamontat/Java8Example").getLatestRelease(); assertThat(release, nullValue()); - } catch (IOException e) { + } catch (UncheckedIOException e) { e.printStackTrace(); fail(); } @@ -1105,7 +1105,7 @@ public boolean add(URL url) { try { repo.createWebHook(url); return true; - } catch (IOException e) { + } catch (UncheckedIOException e) { throw new GHException("Failed to update post-commit hooks", e); } } @@ -1121,7 +1121,7 @@ public boolean remove(Object url) { } } return false; - } catch (IOException e) { + } catch (UncheckedIOException e) { throw new GHException("Failed to update post-commit hooks", e); } } diff --git a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java index 2f3ea77fb4..fce43a771c 100644 --- a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Arrays; import java.util.Date; @@ -57,7 +58,7 @@ public void cleanup() throws Exception { if (content != null) { content.delete("Cleanup"); } - } catch (IOException e) { + } catch (UncheckedIOException e) { } }); } diff --git a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java index d15f506672..c6dcd7eecb 100644 --- a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java +++ b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java @@ -10,6 +10,7 @@ import org.kohsuke.github.function.InputStreamFunction; import java.io.IOException; +import java.io.UncheckedIOException; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; @@ -202,7 +203,7 @@ public void testDelete() throws IOException { try { repo.getWorkflowRun(workflowRunToDelete.getId()); fail("The workflow " + workflowRunToDelete.getId() + " should have been deleted."); - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { // success } } @@ -347,7 +348,7 @@ public void testLogs() throws IOException { try { workflowRun.downloadLogs((is) -> ""); fail("Downloading logs should not be possible as they were deleted"); - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { assertThat(e.getMessage(), containsString("Not Found")); } } @@ -456,7 +457,7 @@ public void testArtifacts() throws IOException { try { repo.getArtifact(artifact1.getId()); fail("Getting the artifact should fail as it was deleted"); - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { assertThat(e.getMessage(), containsString("Not Found")); } } @@ -654,7 +655,7 @@ private Optional getWorkflowRun(String workflowName, String branc private static Status getWorkflowRunStatus(GHRepository repository, long workflowRunId) { try { return repository.getWorkflowRun(workflowRunId).getStatus(); - } catch (IOException e) { + } catch (UncheckedIOException e) { throw new IllegalStateException("Unable to get workflow run status", e); } } diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index ada391e326..39aeb91644 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -6,6 +6,7 @@ import org.kohsuke.github.example.dataobject.ReadOnlyObjects; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.*; import static org.hamcrest.Matchers.*; @@ -415,7 +416,7 @@ public void testCatchServiceDownException() { GHRepository repo = gitHub.getRepository("hub4j-test-org/github-api"); repo.getFileContent("ghcontent-ro/service-down"); fail("Exception was expected"); - } catch (IOException e) { + } catch (UncheckedIOException e) { assertThat(e.getClass().getName(), equalToIgnoringCase(ServiceDownException.class.getName())); } } diff --git a/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java b/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java index 2fd49958b6..7259866093 100644 --- a/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java @@ -130,12 +130,12 @@ public void testGetTrafficStatsAccessFailureDueToInsufficientPermissions() throw try { repo.getViewTraffic(); fail(errorMsg); - } catch (HttpException ex) { + } catch (Exception ex) { } try { repo.getCloneTraffic(); fail(errorMsg); - } catch (HttpException ex) { + } catch (Exception ex) { } } } diff --git a/src/test/java/org/kohsuke/github/extras/authorization/JWTTokenProviderTest.java b/src/test/java/org/kohsuke/github/extras/authorization/JWTTokenProviderTest.java index 4b98cc18c5..873e502e49 100644 --- a/src/test/java/org/kohsuke/github/extras/authorization/JWTTokenProviderTest.java +++ b/src/test/java/org/kohsuke/github/extras/authorization/JWTTokenProviderTest.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.security.GeneralSecurityException; import java.time.Duration; import java.time.Instant; @@ -114,7 +115,8 @@ Instant getIssuedAt(Instant now) { // for the authorization is present and has a the format of a valid JWT token gh.getApp(); fail(); - } catch (HttpException e) { + } catch (UncheckedIOException ex) { + HttpException e = (HttpException) ex.getCause(); assertThat(e.getResponseCode(), equalTo(401)); assertThat(e.getMessage(), containsString( diff --git a/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java b/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java index f66717f31a..5a03f10277 100644 --- a/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java +++ b/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java @@ -9,7 +9,6 @@ import org.junit.Before; import org.junit.Test; import org.kohsuke.github.AbstractGitHubWireMockTest; -import org.kohsuke.github.GHFileNotFoundException; import org.kohsuke.github.GHIssueState; import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRef; @@ -18,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import static org.junit.Assert.fail; @@ -125,7 +125,7 @@ public void testCached404() throws Exception { try { repo.getRef(testRefName); fail(); - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { // expected // FYI: Querying again when the item is actually not present does not produce a 304 @@ -134,7 +134,7 @@ public void testCached404() throws Exception { try { repo.getRef(testRefName); fail(); - } catch (GHFileNotFoundException ex) { + } catch (UncheckedIOException ex) { // expected } @@ -168,7 +168,7 @@ public void testCached404() throws Exception { try { repo.getRef(testRefName); - } catch (GHFileNotFoundException e) { + } catch (UncheckedIOException e) { // Sanity check: ref exists and can be queried from other client getRepository(gitHub2).getRef(testRefName);