Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code style fixes #609

Merged
merged 4 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Maven Download all dependencies
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
- name: Maven Build
run: mvn -B install site --file pom.xml
run: mvn -B install site -P ci --file pom.xml
43 changes: 32 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<hamcrest.version>2.2</hamcrest.version>
<okhttp3.version>4.2.2</okhttp3.version>
<okio.version>2.4.1</okio.version>
<formatter-maven-plugin.goal>format</formatter-maven-plugin.goal>
<jacoco.coverage.target.class>.80</jacoco.coverage.target.class>
<jacoco.coverage.target.method>0.20</jacoco.coverage.target.method>
<jacoco.coverage.target.line>0.50</jacoco.coverage.target.line>
Expand Down Expand Up @@ -152,17 +153,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.18</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.18</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.11.0</version>
<executions>
<execution>
<goals>
<goal>${formatter-maven-plugin.goal}</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
Expand Down Expand Up @@ -338,6 +351,14 @@
</pluginRepository>
</pluginRepositories>
<profiles>
<profile>
<id>ci</id>
<properties>
<formatter-maven-plugin.goal>validate</formatter-maven-plugin.goal>
</properties>
<build>
</build>
</profile>
<profile>
<id>jacoco</id>
<activation>
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/org/kohsuke/github/AbuseLimitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ public abstract class AbuseLimitHandler {
* Called when the library encounters HTTP error indicating that the API abuse limit is reached.
*
* <p>
* Any exception thrown from this method will cause the request to fail, and the caller of github-api
* will receive an exception. If this method returns normally, another request will be attempted.
* For that to make sense, the implementation needs to wait for some time.
* Any exception thrown from this method will cause the request to fail, and the caller of github-api will receive
* an exception. If this method returns normally, another request will be attempted. For that to make sense, the
* implementation needs to wait for some time.
*
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a>
* @param e
* Exception from Java I/O layer. If you decide to fail the processing, you can throw
* this exception (or wrap this exception into another exception and throw it).
* Exception from Java I/O layer. If you decide to fail the processing, you can throw this exception (or
* wrap this exception into another exception and throw it).
* @param uc
* Connection that resulted in an error. Useful for accessing other response headers.
* Connection that resulted in an error. Useful for accessing other response headers.
* @throws IOException
* on failure
*/
public abstract void onError(IOException e, HttpURLConnection uc) throws IOException;

Expand All @@ -40,15 +41,16 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
try {
Thread.sleep(parseWaitTime(uc));
} catch (InterruptedException ex) {
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
}

private long parseWaitTime(HttpURLConnection uc) {
String v = uc.getHeaderField("Retry-After");
if (v==null) return 60 * 1000; // can't tell, return 1 min
if (v == null)
return 60 * 1000; // can't tell, return 1 min

return Math.max(1000, Long.parseLong(v)*1000);
return Math.max(1000, Long.parseLong(v) * 1000);
}
};

Expand All @@ -58,7 +60,7 @@ private long parseWaitTime(HttpURLConnection uc) {
public static final AbuseLimitHandler FAIL = new AbuseLimitHandler() {
@Override
public void onError(IOException e, HttpURLConnection uc) throws IOException {
throw (IOException)new IOException("Abuse limit reached").initCause(e);
throw (IOException) new IOException("Abuse limit reached").initCause(e);
}
};
}
3 changes: 1 addition & 2 deletions src/main/java/org/kohsuke/github/DeleteToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/**
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
justification = "Being constructed by JSON deserialization")
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", justification = "Being constructed by JSON deserialization")
class DeleteToken {
public String delete_token;
}
94 changes: 59 additions & 35 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ public class GHApp extends GHObject {
private String description;
@JsonProperty("external_url")
private String externalUrl;
private Map<String,String> permissions;
private Map<String, String> permissions;
private List<GHEvent> events;
@JsonProperty("installations_count")
private long installationsCount;
@JsonProperty("html_url")
private String htmlUrl;


public GHUser getOwner() {
return owner;
}
Expand Down Expand Up @@ -93,80 +92,105 @@ public void setPermissions(Map<String, String> permissions) {
this.permissions = permissions;
}

/*package*/ GHApp wrapUp(GitHub root) {
GHApp wrapUp(GitHub root) {
this.root = root;
return this;
}

/**
* Obtains all the installations associated with this app.
*
* <p>
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
* @return a list of App installations
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
*/
@Preview @Deprecated
@Preview
@Deprecated
public PagedIterable<GHAppInstallation> listInstallations() {
return root.retrieve().withPreview(MACHINE_MAN)
.asPagedIterable(
"/app/installations",
GHAppInstallation[].class,
item -> item.wrapUp(root) );
return root.retrieve().withPreview(MACHINE_MAN).asPagedIterable("/app/installations", GHAppInstallation[].class,
item -> item.wrapUp(root));
}

/**
* Obtain an installation associated with this app
* @param id - Installation Id
*
* Obtain an installation associated with this app.
* <p>
* You must use a JWT to access this endpoint.
*
* @param id
* Installation Id
* @return a GHAppInstallation
* @throws IOException
* on error
* @see <a href="https://developer.github.com/v3/apps/#get-an-installation">Get an installation</a>
*/
@Preview @Deprecated
@Preview
@Deprecated
public GHAppInstallation getInstallationById(long id) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root);
return root.retrieve().withPreview(MACHINE_MAN)
.to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root);
}

/**
* Obtain an organization installation associated with this app
* @param name - Organization name
*
* Obtain an organization installation associated with this app.
* <p>
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#get-an-organization-installation">Get an organization installation</a>
* @param name
* Organization name
* @return a GHAppInstallation
* @throws IOException
* on error
* @see <a href="https://developer.github.com/v3/apps/#get-an-organization-installation">Get an organization
* installation</a>
*/
@Preview @Deprecated
@Preview
@Deprecated
public GHAppInstallation getInstallationByOrganization(String name) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root);
return root.retrieve().withPreview(MACHINE_MAN)
.to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root);
}

/**
* Obtain an repository installation associated with this app
* @param ownerName - Organization or user name
* @param repositoryName - Repository name
*
* Obtain an repository installation associated with this app.
* <p>
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#get-a-repository-installation">Get a repository installation</a>
* @param ownerName
* Organization or user name
* @param repositoryName
* Repository name
* @return a GHAppInstallation
* @throws IOException
* on error
* @see <a href="https://developer.github.com/v3/apps/#get-a-repository-installation">Get a repository
* installation</a>
*/
@Preview @Deprecated
@Preview
@Deprecated
public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class).wrapUp(root);
return root.retrieve().withPreview(MACHINE_MAN)
.to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class)
.wrapUp(root);
}

/**
* Obtain a user installation associated with this app
* @param name - user name
*
* Obtain a user installation associated with this app.
* <p>
* You must use a JWT to access this endpoint.
*
* @param name
* user name
* @return a GHAppInstallation
* @throws IOException
* on error
* @see <a href="https://developer.github.com/v3/apps/#get-a-user-installation">Get a user installation</a>
*/
@Preview @Deprecated
@Preview
@Deprecated
public GHAppInstallation getInstallationByUser(String name) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root);
return root.retrieve().withPreview(MACHINE_MAN)
.to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root);
}

}

26 changes: 18 additions & 8 deletions src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,46 @@ public class GHAppCreateTokenBuilder {
protected final Requester builder;
private final String apiUrlTail;

@Preview @Deprecated
/*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
@Preview
@Deprecated
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = new Requester(root);
this.builder.withPermissions("permissions",permissions);
this.builder.withPermissions("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
* repository_ids, the response does not contain neither the repositories nor the permissions key.
*
* @param repositoryIds - Array containing the repositories Ids
* @param repositoryIds
* Array containing the repositories Ids
*
* @return a GHAppCreateTokenBuilder
*/
@Preview @Deprecated
@Preview
@Deprecated
public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
this.builder.with("repository_ids",repositoryIds);
this.builder.with("repository_ids", repositoryIds);
return this;
}

/**
* Creates an app token with all the parameters.
*
* You must use a JWT to access this endpoint.
*
* @return a GHAppInstallationToken
* @throws IOException
* on error
*/
@Preview @Deprecated
@Preview
@Deprecated
public GHAppInstallationToken create() throws IOException {
return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class).wrapUp(root);
return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class)
.wrapUp(root);
}

}
23 changes: 15 additions & 8 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
this.repositorySelection = repositorySelection;
}

/*package*/ GHAppInstallation wrapUp(GitHub root) {
GHAppInstallation wrapUp(GitHub root) {
this.root = root;
return this;
}
Expand All @@ -145,23 +145,30 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
*
* You must use a JWT to access this endpoint.
*
* @throws IOException
* on error
* @see <a href="https://developer.github.com/v3/apps/#delete-an-installation">Delete an installation</a>
*/
@Preview @Deprecated
@Preview
@Deprecated
public void deleteInstallation() throws IOException {
root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id));
}


/**
* Starts a builder that creates a new App Installation Token.
*
* <p>
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()}
* to finally create an access token.
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} to
* finally create an access token.
*
* @param permissions
* map of permissions for the created token
* @return a GHAppCreateTokenBuilder on error
*/
@Preview @Deprecated
public GHAppCreateTokenBuilder createToken(Map<String,GHPermissionType> permissions){
return new GHAppCreateTokenBuilder(root,String.format("/app/installations/%d/access_tokens", id), permissions);
@Preview
@Deprecated
public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permissions) {
return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", id), permissions);
}
}
Loading