From 84024d0d140c07142dd746c20c596bfb62a25501 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 14 Sep 2024 13:06:50 -0700 Subject: [PATCH] Streamlining --- pom.xml | 3 -- .../github/GHAppCreateTokenBuilder.java | 17 ----------- .../org/kohsuke/github/GHAppInstallation.java | 6 +--- .../github/GHAppInstallationToken.java | 2 +- .../github/GHBranchProtectionBuilder.java | 29 ------------------- .../java/org/kohsuke/github/GHContent.java | 17 +++++++++-- .../org/kohsuke/github/GHPullRequest.java | 5 +--- .../org/kohsuke/github/GHTeamBuilder.java | 3 +- src/main/java/org/kohsuke/github/GitHub.java | 2 +- .../org/kohsuke/github/GitHubBuilder.java | 2 +- .../java/org/kohsuke/github/GHAppTest.java | 3 +- .../github/GHBranchProtectionTest.java | 2 +- 12 files changed, 23 insertions(+), 68 deletions(-) diff --git a/pom.xml b/pom.xml index 6d970057ef..10d17f74f8 100644 --- a/pom.xml +++ b/pom.xml @@ -163,9 +163,6 @@ org.kohsuke.github.GHRepositorySearchBuilder.Fork - - org.kohsuke.github.GHPerson.1 - org.kohsuke.github.example.* diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 348282ecf6..edab276e90 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -10,7 +10,6 @@ * Creates a access token for a GitHub App Installation. * * @author Paulo Miguel Almeida - * @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map) * @see GHAppInstallation#createToken() GHAppInstallation#createToken() */ public class GHAppCreateTokenBuilder extends GitHubInteractiveObject { @@ -34,22 +33,6 @@ public class GHAppCreateTokenBuilder extends GitHubInteractiveObject { this.builder = root.createRequest(); } - /** - * Instantiates a new GH app create token builder. - * - * @param root - * the root - * @param apiUrlTail - * the api url tail - * @param permissions - * the permissions - */ - @BetaApi - GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { - this(root, apiUrlTail); - permissions(permissions); - } - /** * By default the installation token has access to all repositories that the installation can access. To restrict * the access to specific repositories, you can provide the repository_ids when creating the token. When you omit diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index ee45788c72..72731cdd03 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -221,12 +221,9 @@ public void deleteInstallation() throws IOException { * @return a GHAppCreateTokenBuilder instance * @deprecated Use {@link GHAppInstallation#createToken()} instead. */ - @BetaApi @Deprecated public GHAppCreateTokenBuilder createToken(Map permissions) { - return new GHAppCreateTokenBuilder(root(), - String.format("/app/installations/%d/access_tokens", getId()), - permissions); + return createToken().permissions(permissions); } /** @@ -238,7 +235,6 @@ public GHAppCreateTokenBuilder createToken(Map permiss * * @return a GHAppCreateTokenBuilder instance */ - @BetaApi public GHAppCreateTokenBuilder createToken() { return new GHAppCreateTokenBuilder(root(), String.format("/app/installations/%d/access_tokens", getId())); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java index 2461207952..e9bccdb139 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -8,7 +8,7 @@ * A Github App Installation Token. * * @author Paulo Miguel Almeida - * @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map) + * @see GHAppInstallation#createToken() GHAppInstallation#createToken() */ public class GHAppInstallationToken extends GitHubInteractiveObject { private String token; diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index 640818af17..c56e7f2197 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; // TODO: Auto-generated Javadoc /** @@ -54,34 +53,6 @@ public GHBranchProtectionBuilder addRequiredStatusChecks(Collection checks) { - getStatusChecks().checks.addAll(checks.stream() - .map(context -> new GHBranchProtection.Check(context, null)) - .collect(Collectors.toList())); - return this; - } - - /** - * Add required checks gh branch protection builder. - * - * @param checks - * the checks - * @return the gh branch protection builder - */ - @Deprecated - public GHBranchProtectionBuilder addRequiredChecks(String... checks) { - addRequiredChecks(Arrays.asList(checks)); - return this; - } - /** * Add required checks gh branch protection builder. * diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 7a406f3587..d3d86ecb39 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -124,7 +124,7 @@ public String getTarget() { @Deprecated @SuppressFBWarnings("DM_DEFAULT_ENCODING") public String getContent() throws IOException { - return new String(Base64.getMimeDecoder().decode(getEncodedContent())); + return new String(readDecodedContent()); } /** @@ -180,11 +180,22 @@ public String getHtmlUrl() { * the io exception */ public InputStream read() throws IOException { - refresh(content); + return new ByteArrayInputStream(readDecodedContent()); + } + + /** + * Retrieves the decoded bytes of the blob. + * + * @return the input stream + * @throws IOException + * the io exception + */ + private byte[] readDecodedContent() throws IOException { + String encodedContent = getEncodedContent(); if (encoding.equals("base64")) { try { Base64.Decoder decoder = Base64.getMimeDecoder(); - return new ByteArrayInputStream(decoder.decode(content.getBytes(StandardCharsets.US_ASCII))); + return decoder.decode(encodedContent.getBytes(StandardCharsets.US_ASCII)); } catch (IllegalArgumentException e) { throw new AssertionError(e); // US-ASCII is mandatory } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index ae31952c6f..98a9abfc98 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -295,11 +295,8 @@ public Boolean getMergeable() throws IOException { * for test purposes only. * * @return the mergeable no refresh - * @throws IOException - * Signals that an I/O exception has occurred. */ - @Deprecated - Boolean getMergeableNoRefresh() throws IOException { + Boolean getMergeableNoRefresh() { return mergeable; } diff --git a/src/main/java/org/kohsuke/github/GHTeamBuilder.java b/src/main/java/org/kohsuke/github/GHTeamBuilder.java index 53b1b8b446..6db44008af 100644 --- a/src/main/java/org/kohsuke/github/GHTeamBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTeamBuilder.java @@ -76,7 +76,8 @@ public GHTeamBuilder repositories(String... repoNames) { * @param permission * permssion to be applied * @return a builder to continue with building - * @deprecated https://docs.github.com/en/free-pro-team@latest/rest/teams/teams?apiVersion=2022-11-28#create-a-team + * @deprecated see + * https://docs.github.com/en/free-pro-team@latest/rest/teams/teams?apiVersion=2022-11-28#create-a-team */ @Deprecated public GHTeamBuilder permission(GHOrganization.Permission permission) { diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 6abca9c027..aa5b6239e3 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -97,7 +97,7 @@ public class GitHub { * The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or * "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has /api/v3 in the URL. For * historical reasons, this parameter still accepts the bare domain name, but that's considered - * deprecated. Password is also considered deprecated as it is no longer required for api usage. + * deprecated. * @param connector * a connector * @param rateLimitHandler diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index b89031738b..19f4c4a957 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -238,7 +238,7 @@ public GitHubBuilder withAuthorizationProvider(final AuthorizationProvider autho * @param appInstallationToken * A string containing the GitHub App installation token * @return the configured Builder from given GitHub App installation token. - * @see GHAppInstallation#createToken(java.util.Map) GHAppInstallation#createToken(java.util.Map) + * @see GHAppInstallation#createToken() GHAppInstallation#createToken() */ public GitHubBuilder withAppInstallationToken(String appInstallationToken) { return withAuthorizationProvider(ImmutableAuthorizationProvider.fromAppInstallationToken(appInstallationToken)); diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index 7d2fc347bc..431dd13037 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -188,8 +188,7 @@ public void createToken() throws IOException { permissions.put("metadata", GHPermissionType.READ); // Create token specifying both permissions and repository ids - GHAppInstallationToken installationToken = installation.createToken() - .permissions(permissions) + GHAppInstallationToken installationToken = installation.createToken(permissions) .repositoryIds(Collections.singletonList((long) 111111111)) .create(); diff --git a/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java b/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java index bee19e8e0c..17d7d85f01 100755 --- a/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java +++ b/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java @@ -51,7 +51,7 @@ public void setUp() throws Exception { public void testEnableBranchProtections() throws Exception { // team/user restrictions require an organization repo to test against GHBranchProtection protection = branch.enableProtection() - .addRequiredChecks("test-status-check") + .addRequiredChecks(new GHBranchProtection.Check("test-status-check", null)) .requireBranchIsUpToDate() .requireCodeOwnReviews() .requireLastPushApproval()