CommitValidators: trim "ERROR" shouting from "forge committer" check

Change-Id: I848e210da540524142b0e44f7e826cc0d0a7646b
This commit is contained in:
Han-Wen Nienhuys
2018-08-28 19:40:36 +02:00
committed by David Pursehouse
parent de4dc899a5
commit 2c5b2c3bb5

View File

@@ -544,8 +544,7 @@ public class CommitValidators {
return Collections.emptyList();
} catch (AuthException e) {
throw new CommitValidationException(
"invalid author",
invalidEmail(receiveEvent.commit, "author", author, user, canonicalWebUrl));
"invalid author", invalidEmail("author", author, user, canonicalWebUrl));
} catch (PermissionBackendException e) {
log.error("cannot check FORGE_AUTHOR", e);
throw new CommitValidationException("internal auth error");
@@ -578,8 +577,7 @@ public class CommitValidators {
return Collections.emptyList();
} catch (AuthException e) {
throw new CommitValidationException(
"invalid committer",
invalidEmail(receiveEvent.commit, "committer", committer, user, canonicalWebUrl));
"invalid committer", invalidEmail("committer", committer, user, canonicalWebUrl));
} catch (PermissionBackendException e) {
log.error("cannot check FORGE_COMMITTER", e);
throw new CommitValidationException("internal auth error");
@@ -747,42 +745,30 @@ public class CommitValidators {
}
private static CommitValidationMessage invalidEmail(
RevCommit c,
String type,
PersonIdent who,
IdentifiedUser currentUser,
String canonicalWebUrl) {
String type, PersonIdent who, IdentifiedUser currentUser, String canonicalWebUrl) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
sb.append("ERROR: In commit ").append(c.name()).append("\n");
sb.append("ERROR: ")
.append(type)
.append(" email address ")
sb.append("email address ")
.append(who.getEmailAddress())
.append("\n");
sb.append("ERROR: does not match your user account and you have no 'forge ")
.append(" is not registered in your account, and you lack 'forge ")
.append(type)
.append("' permission.\n");
sb.append("ERROR:\n");
if (currentUser.getEmailAddresses().isEmpty()) {
sb.append("ERROR: You have not registered any email addresses.\n");
sb.append("You have not registered any email addresses.\n");
} else {
sb.append("ERROR: The following addresses are currently registered:\n");
sb.append("The following addresses are currently registered:\n");
for (String address : currentUser.getEmailAddresses()) {
sb.append("ERROR: ").append(address).append("\n");
sb.append(" ").append(address).append("\n");
}
}
sb.append("ERROR:\n");
if (canonicalWebUrl != null) {
sb.append("ERROR: To register an email address, please visit:\n");
sb.append("ERROR: ")
.append(canonicalWebUrl)
.append("#")
.append(PageLinks.SETTINGS_CONTACT)
.append("\n");
sb.append("To register an email address, visit:\n");
sb.append(canonicalWebUrl).append("#").append(PageLinks.SETTINGS_CONTACT).append("\n");
}
sb.append("\n");
return new CommitValidationMessage(sb.toString(), false);
return new CommitValidationMessage(sb.toString(), true);
}
/**