Skip to content
Snippets Groups Projects
Commit 205b3343 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Iss #168 - Update status page for potential external ID display

We have the provider ID when GH commit status checks are requested,
which is a not small amount of our checks. We'll need additional work to
provide this functionality for Gitlab checks, but this should provide
the base.
parent 82b51a5b
No related branches found
No related tags found
No related merge requests found
Pipeline #51628 failed
......@@ -67,8 +67,8 @@ public class EclipseQuteTemplateExtensions {
/**
* <p>
* Obfuscates an email for public consumption, showing the first letter of the email address, and the domain of the
* address for identification, and stripping out the rest of the address.
* Obfuscates an email for public consumption, showing the first letter of the email address, and the domain of the address for
* identification, and stripping out the rest of the address.
* </p>
*
* <p>
......@@ -123,28 +123,26 @@ public class EclipseQuteTemplateExtensions {
String out = "";
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()));
.format("Committer does not have permission to push on behalf of another user (Legacy).%s",
EclipseQuteTemplateExtensions.getUserInfoForMessage(message));
} 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()));
.format("Committer did not have a signed ECA on file.%s",
EclipseQuteTemplateExtensions.getUserInfoForMessage(message));
} 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()));
.format("Author did not have a signed ECA on file.%s", EclipseQuteTemplateExtensions.getUserInfoForMessage(message));
} else if (message.getStatusCode() == APIStatusCode.ERROR_COMMITTER_NOT_FOUND.getValue()) {
out = String
.format("Committer Eclipse account cannot be found. (%s)",
EclipseQuteTemplateExtensions.obfuscateEmail(message.getCommitterEmail()));
.format("Committer Eclipse account cannot be found.%s",
EclipseQuteTemplateExtensions.getUserInfoForMessage(message));
} else if (message.getStatusCode() == APIStatusCode.ERROR_AUTHOR_NOT_FOUND.getValue()) {
out = String
.format("Author Eclipse account cannot be found. (%s)",
EclipseQuteTemplateExtensions.obfuscateEmail(message.getAuthorEmail()));
.format("Author Eclipse account cannot be found.%s", EclipseQuteTemplateExtensions.getUserInfoForMessage(message));
} 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()));
.format("Committer does not have permission to commit on specification projects.%s",
EclipseQuteTemplateExtensions.getUserInfoForMessage(message));
} else if (message.getStatusCode() == APIStatusCode.ERROR_SIGN_OFF.getValue()) {
out = "Sign-off not detected in the commit message (Legacy).";
} else if (message.getStatusCode() == APIStatusCode.ERROR_DEFAULT.getValue()) {
......@@ -155,6 +153,30 @@ public class EclipseQuteTemplateExtensions {
return out;
}
/**
* Generate the info list stored with the validation message to be appended to the actual status message for more information.
*
* @param message the validation message being printed
* @return HTML containing the user details
*/
private static String getUserInfoForMessage(CommitValidationMessage message) {
StringBuilder sb = new StringBuilder();
sb.append("<ul><li>Email: ");
// switch on email depending on error code
sb
.append(EclipseQuteTemplateExtensions
.obfuscateEmail(
APIStatusCode.getValueForCode(message.getStatusCode()).isCommitterError() ? message.getCommitterEmail()
: message.getAuthorEmail()));
// only add a provider ID section if it is set
if (StringUtils.isNotBlank(message.getProviderId())) {
sb.append("</li><li>Provider ID: ");
sb.append(message.getProviderId());
}
sb.append("</li></ul>");
return sb.toString();
}
private EclipseQuteTemplateExtensions() {
}
......
......@@ -11,6 +11,8 @@
**********************************************************************/
package org.eclipsefoundation.git.eca.namespace;
import java.util.stream.Stream;
import com.fasterxml.jackson.annotation.JsonValue;
public enum APIStatusCode {
......@@ -32,6 +34,19 @@ public enum APIStatusCode {
private APIStatusCode(int code) {
this.code = code;
}
/**
* Checks if the associated error is a committer error or a general author error.
*
* @return true if the current error is related to committer status, false otherwise
*/
public boolean isCommitterError() {
return this.equals(ERROR_COMMITTER) || this.equals(ERROR_COMMITTER_NOT_FOUND) || this.equals(ERROR_SPEC_PROJECT);
}
public static APIStatusCode getValueForCode(int code) {
return Stream.of(values()).filter(c -> c.code == code).findFirst().orElse(null);
}
@JsonValue
public int getValue() {
......
......@@ -153,7 +153,10 @@ public class DefaultValidationStatusService implements ValidationStatusService {
m.setStatusCode(err.getCode().getValue());
// TODO add a checked way to set this
m.setEclipseId(null);
m.setProviderId(null);
// if a committer status, provide the committer external ID, otherwise pass author external ID
m
.setProviderId(err.getCode().isCommitterError() ? c.getCommitter().getExternalId()
: c.getAuthor().getExternalId());
m.setCommit(base);
return m;
})
......
......@@ -106,7 +106,7 @@
<div class="panel-body background-white">
<ul class="list-group-item-text">
{#for error in statuses.getValidationErrors}
<li>{error.getMessageForError}</li>
<li>{error.getMessageForError.raw}</li>
{/for}
</ul>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment