Skip to content

Commit

Permalink
Streamlining
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 15, 2024
1 parent 2397b07 commit 84024d0
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 68 deletions.
3 changes: 0 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@
<!-- V2.x changes -->
<exclude>org.kohsuke.github.GHRepositorySearchBuilder.Fork</exclude>

<!-- Deprecated -->
<exclude>org.kohsuke.github.GHPerson.1</exclude>

<!-- Sample only -->
<exclude>org.kohsuke.github.example.*</exclude>

Expand Down
17 changes: 0 additions & 17 deletions src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String, GHPermissionType> 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
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, GHPermissionType> permissions) {
return new GHAppCreateTokenBuilder(root(),
String.format("/app/installations/%d/access_tokens", getId()),
permissions);
return createToken().permissions(permissions);
}

/**
Expand All @@ -238,7 +235,6 @@ public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permiss
*
* @return a GHAppCreateTokenBuilder instance
*/
@BetaApi
public GHAppCreateTokenBuilder createToken() {
return new GHAppCreateTokenBuilder(root(), String.format("/app/installations/%d/access_tokens", getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -54,34 +53,6 @@ public GHBranchProtectionBuilder addRequiredStatusChecks(Collection<GHBranchProt
return this;
}

/**
* Add required checks gh branch protection builder.
*
* @param checks
* the checks
* @return the gh branch protection builder
*/
@Deprecated
public GHBranchProtectionBuilder addRequiredChecks(Collection<String> 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.
*
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/kohsuke/github/GHContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/kohsuke/github/GHTeamBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>/api/v3</code> 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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GitHubBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/kohsuke/github/GHAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 84024d0

Please sign in to comment.