Skip to content
Snippets Groups Projects

Iss #137 - Remove magic numbers, split out large lambdas for code smell

Merged Iss #137 - Remove magic numbers, split out large lambdas for code smell
Merged Martin Lowe requested to merge (removed):malowe/main/code-smell-fix into main
11 files
+ 248
211
Compare changes
  • Side-by-side
  • Inline
Files
11
@@ -17,12 +17,19 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.eclipsefoundation.git.eca.dto.CommitValidationMessage;
import org.eclipsefoundation.git.eca.dto.CommitValidationStatus;
import org.eclipsefoundation.git.eca.namespace.APIStatusCode;
import io.quarkus.qute.TemplateExtension;
@TemplateExtension
public class EclipseQuteTemplateExtensions {
private static final int EMAIL_ADDRESS_PARTS = 2;
private static final int DOMAIN_PARTS_MINIMUM = 2;
// division point where a character gets obfuscated in the email domain
private static final int OBFUSCATION_DIVISION_POINT = 2;
/**
* Made to count nested errors in a list of commit status objects.
*
@@ -64,18 +71,18 @@ public class EclipseQuteTemplateExtensions {
}
// split on the @ symbol
String[] emailParts = email.split("\\@");
if (emailParts.length != 2) {
if (emailParts.length != EMAIL_ADDRESS_PARTS) {
// valid emails will have 2 sections when split this way
return "";
}
String[] domainParts = emailParts[1].split("\\.");
if (domainParts.length < 2) {
if (domainParts.length < DOMAIN_PARTS_MINIMUM) {
// emails should have at least 2 parts here
return "";
}
// the index in the middle of the first domain part of the email address
int middleIndexDomain = Math.floorDiv(domainParts[0].length(), 2);
int middleIndexDomain = Math.floorDiv(domainParts[0].length(), OBFUSCATION_DIVISION_POINT);
// build the obfuscated email address in the pattern defined in the block comment
StringBuilder sb = new StringBuilder();
@@ -99,25 +106,25 @@ public class EclipseQuteTemplateExtensions {
*/
static String getMessageForError(CommitValidationMessage message) {
String out = "";
if (message.getStatusCode() == -406) {
if (message.getStatusCode() == APIStatusCode.ERROR_PROXY_PUSH.getValue()) {
out = String
.format("Committer does not have permission to push on behalf of another user (Legacy). (%s)",
EclipseQuteTemplateExtensions.obfuscateEmail(message.getCommitterEmail()));
} else if (message.getStatusCode() == -405) {
} else if (message.getStatusCode() == APIStatusCode.ERROR_COMMITTER.getValue()) {
out = String
.format("Committer did not have a signed ECA on file. (%s)",
EclipseQuteTemplateExtensions.obfuscateEmail(message.getCommitterEmail()));
} else if (message.getStatusCode() == -404) {
} else if (message.getStatusCode() == APIStatusCode.ERROR_AUTHOR.getValue()) {
out = String
.format("Author did not have a signed ECA on file. (%s)",
EclipseQuteTemplateExtensions.obfuscateEmail(message.getAuthorEmail()));
} else if (message.getStatusCode() == -403) {
} else if (message.getStatusCode() == APIStatusCode.ERROR_SPEC_PROJECT.getValue()) {
out = String
.format("Committer does not have permission to commit on specification projects. (%s)",
EclipseQuteTemplateExtensions.obfuscateEmail(message.getCommitterEmail()));
} else if (message.getStatusCode() == -402) {
} else if (message.getStatusCode() == APIStatusCode.ERROR_SIGN_OFF.getValue()) {
out = "Sign-off not detected in the commit message (Legacy).";
} else if (message.getStatusCode() == -401) {
} else if (message.getStatusCode() == APIStatusCode.ERROR_DEFAULT.getValue()) {
out = "Request format/state error detected.";
} else {
out = "Unaccounted for error detected, please contact administrators.";
@@ -126,6 +133,6 @@ public class EclipseQuteTemplateExtensions {
}
private EclipseQuteTemplateExtensions() {
}
}
Loading