Skip to content
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
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,20 @@
</includes>

<eclipse>
<version>4.35</version>
<file>${basedir}/src/build/eclipse/formatter.xml</file>
<sortMembersEnabled>true</sortMembersEnabled>
<sortMembersVisibilityOrderEnabled>true</sortMembersVisibilityOrderEnabled>
<sortMembersDoNotSortFields>false</sortMembersDoNotSortFields>
</eclipse>

<importOrder>
<file>${basedir}/src/build/eclipse/eclipse.importorder</file>
</importOrder>

<removeUnusedImports></removeUnusedImports>

<formatAnnotations />

<trimTrailingWhitespace></trimTrailingWhitespace>
<endWithNewline></endWithNewline>

Expand Down
48 changes: 24 additions & 24 deletions src/main/java/org/kohsuke/github/AbstractBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
*/
abstract class AbstractBuilder<R, S> extends GitHubInteractiveObject implements GitHubRequestBuilderDone<R> {

@Nonnull
private final Class<R> returnType;
@CheckForNull
private final R baseInstance;

private final boolean commitChangesImmediately;

@CheckForNull
private final R baseInstance;
@Nonnull
private final Class<R> returnType;

/** The requester. */
@Nonnull
Expand Down Expand Up @@ -111,54 +111,54 @@ public R done() throws IOException {
}

/**
* Applies a value to a name for this builder.
* Chooses whether to return a continuing builder or an updated data record
*
* If {@code S} is the same as {@code R}, this method will commit changes after the first value change and return a
* {@code R} from {@link #done()}.
*
* If {@code S} is not the same as {@code R}, this method will return an {@code S} and letting the caller batch
* together multiple changes and call {@link #done()} when they are ready.
*
* @param name
* the name of the field
* @param value
* the value of the field
* @return either a continuing builder or an updated data record
* @throws IOException
* if an I/O error occurs
*/
@Nonnull
@BetaApi
protected S with(@Nonnull String name, Object value) throws IOException {
requester.with(name, value);
return continueOrDone();
protected S continueOrDone() throws IOException {
// 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.
if (commitChangesImmediately) {
// These casts look strange and risky, but they they're actually guaranteed safe due to the return path
// being based on the previous comparison of class instances passed to the constructor.
return (S) done();
} else {
return (S) this;
}
}

/**
* Chooses whether to return a continuing builder or an updated data record
* Applies a value to a name for this builder.
*
* If {@code S} is the same as {@code R}, this method will commit changes after the first value change and return a
* {@code R} from {@link #done()}.
*
* If {@code S} is not the same as {@code R}, this method will return an {@code S} and letting the caller batch
* together multiple changes and call {@link #done()} when they are ready.
*
* @param name
* the name of the field
* @param value
* the value of the field
* @return either a continuing builder or an updated data record
* @throws IOException
* if an I/O error occurs
*/
@Nonnull
@BetaApi
protected S continueOrDone() throws IOException {
// 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.
if (commitChangesImmediately) {
// These casts look strange and risky, but they they're actually guaranteed safe due to the return path
// being based on the previous comparison of class instances passed to the constructor.
return (S) done();
} else {
return (S) this;
}
protected S with(@Nonnull String name, Object value) throws IOException {
requester.with(name, value);
return continueOrDone();
}
}
42 changes: 21 additions & 21 deletions src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,38 @@
*/
class EnterpriseManagedSupport {

private static final Logger LOGGER = Logger.getLogger(EnterpriseManagedSupport.class.getName());
static final String COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS = "Could not retrieve organization external groups";
static final String NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR = "This organization is not part of externally managed enterprise.";

static final String TEAM_CANNOT_BE_EXTERNALLY_MANAGED_ERROR = "This team cannot be externally managed since it has explicit members.";

private static final Logger LOGGER = Logger.getLogger(EnterpriseManagedSupport.class.getName());
private static String logUnexpectedFailure(final JsonProcessingException exception, final String payload) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
return String.format("Could not parse GitHub error response: '%s'. Full stacktrace follows:%n%s", payload, sw);
}

static EnterpriseManagedSupport forOrganization(final GHOrganization org) {
return new EnterpriseManagedSupport(org);
}

private final GHOrganization organization;

private EnterpriseManagedSupport(GHOrganization organization) {
this.organization = organization;
}

Optional<GHException> filterException(final GHException e) {
if (e.getCause() instanceof HttpException) {
final HttpException he = (HttpException) e.getCause();
return filterException(he, COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS)
.map(translated -> new GHException(COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS, translated));
}
return Optional.empty();
}

Optional<GHIOException> filterException(final HttpException he, final String scenario) {
if (he.getResponseCode() == 400) {
final String responseMessage = he.getMessage();
Expand All @@ -46,24 +66,4 @@ Optional<GHIOException> filterException(final HttpException he, final String sce
return Optional.empty();
}

Optional<GHException> filterException(final GHException e) {
if (e.getCause() instanceof HttpException) {
final HttpException he = (HttpException) e.getCause();
return filterException(he, COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS)
.map(translated -> new GHException(COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS, translated));
}
return Optional.empty();
}

static EnterpriseManagedSupport forOrganization(final GHOrganization org) {
return new EnterpriseManagedSupport(org);
}

private static String logUnexpectedFailure(final JsonProcessingException exception, final String payload) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
return String.format("Could not parse GitHub error response: '%s'. Full stacktrace follows:%n%s", payload, sw);
}

}
Loading