Commit 16db7e01 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Add strict mode to force full validation in some cases


Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent 6c729375
/*******************************************************************************
* Copyright (C) 2020 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/
/**
* ***************************************************************************** Copyright (C) 2020
* Eclipse Foundation
*
* <p>This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/
*
* <p>SPDX-License-Identifier: EPL-2.0
* ****************************************************************************
*/
package org.eclipsefoundation.git.eca.model;
import java.net.URI;
......@@ -17,68 +18,65 @@ import org.eclipsefoundation.git.eca.namespace.ProviderType;
/**
* Represents a request to validate a list of commits.
*
* @author Martin Lowe
*
* @author Martin Lowe
*/
public class ValidationRequest {
private URI repoUrl;
private List<Commit> commits;
private ProviderType provider;
private URI repoUrl;
private List<Commit> commits;
private ProviderType provider;
private boolean strictMode;
/** @return the repoUrl */
public URI getRepoUrl() {
return repoUrl;
}
/** @param repoUrl the repoUrl to set */
public void setRepoUrl(URI repoUrl) {
this.repoUrl = repoUrl;
}
/**
* @return the repoUrl
*/
public URI getRepoUrl() {
return repoUrl;
}
/** @return the commits */
public List<Commit> getCommits() {
return new ArrayList<>(commits);
}
/**
* @param repoUrl the repoUrl to set
*/
public void setRepoUrl(URI repoUrl) {
this.repoUrl = repoUrl;
}
/** @param commits the commits to set */
public void setCommits(List<Commit> commits) {
this.commits = new ArrayList<>(commits);
}
/**
* @return the commits
*/
public List<Commit> getCommits() {
return new ArrayList<>(commits);
}
/** @return the provider */
public ProviderType getProvider() {
return provider;
}
/**
* @param commits the commits to set
*/
public void setCommits(List<Commit> commits) {
this.commits = new ArrayList<>(commits);
}
/** @param provider the provider to set */
public void setProvider(ProviderType provider) {
this.provider = provider;
}
/**
* @return the provider
*/
public ProviderType getProvider() {
return provider;
}
/** @return the strictMode */
public boolean isStrictMode() {
return strictMode;
}
/**
* @param provider the provider to set
*/
public void setProvider(ProviderType provider) {
this.provider = provider;
}
/** @param strictMode the strictMode to set */
public void setStrictMode(boolean strictMode) {
this.strictMode = strictMode;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ValidationRequest [repoUrl=");
builder.append(repoUrl);
builder.append(", commits=");
builder.append(commits);
builder.append(", provider=");
builder.append(provider);
builder.append("]");
return builder.toString();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ValidationRequest [repoUrl=");
builder.append(repoUrl);
builder.append(", commits=");
builder.append(commits);
builder.append(", provider=");
builder.append(provider);
builder.append("]");
return builder.toString();
}
}
/*******************************************************************************
* Copyright (C) 2020 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
/**
* Copyright (C) 2020
* Eclipse Foundation
*
* <p>This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/
*
* <p>SPDX-License-Identifier: EPL-2.0
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/
*/
package org.eclipsefoundation.git.eca.model;
import java.util.Date;
......@@ -20,130 +21,115 @@ import org.eclipsefoundation.git.eca.namespace.APIStatusCode;
/**
* Represents an internal response for a call to this API.
*
* @author Martin Lowe
*
* @author Martin Lowe
*/
public class ValidationResponse {
private boolean passed;
private int errorCount;
private Date time;
private Map<String, CommitStatus> commits;
private boolean trackedProject;
public ValidationResponse() {
this.commits = new HashMap<>();
this.time = new Date();
}
/**
* @return the passed
*/
public boolean isPassed() {
return passed;
}
/**
* @param passed the passed to set
*/
public void setPassed(boolean passed) {
this.passed = passed;
}
/**
* @return the errorCount
*/
public int getErrorCount() {
this.errorCount = commits.values().stream().mapToInt(s -> s.getErrors().size()).sum();
return errorCount;
}
/**
* @param errorCount the errorCount to set
*/
public void setErrorCount(int errorCount) {
this.errorCount = errorCount;
}
/**
* @return the time
*/
public Date getTime() {
return time;
}
/**
* @param time the time to set
*/
public void setTime(Date time) {
this.time = time;
}
/**
* @return the commits
*/
public Map<String, CommitStatus> getCommits() {
return commits;
}
/**
* @param commits the commits to set
*/
public void setCommits(Map<String, CommitStatus> commits) {
this.commits = commits;
}
/**
* @param message message to add to the API response
*/
public void addMessage(String hash, String message, APIStatusCode code) {
commits.computeIfAbsent(getHashKey(hash), k -> new CommitStatus()).addMessage(message, code);
}
/**
* @param warning message to add to the API response
*/
public void addWarning(String hash, String warning, APIStatusCode code) {
commits.computeIfAbsent(getHashKey(hash), k -> new CommitStatus()).addWarning(warning, code);
}
/**
* @param error message to add to the API response
*/
public void addError(String hash, String error, APIStatusCode code) {
commits.computeIfAbsent(getHashKey(hash), k -> new CommitStatus()).addError(error, code);
}
/**
* @return the trackedProject
*/
public boolean isTrackedProject() {
return trackedProject;
}
/**
* @param trackedProject the trackedProject to set
*/
public void setTrackedProject(boolean trackedProject) {
this.trackedProject = trackedProject;
}
private String getHashKey(String hash) {
return hash == null ? "_nil" : hash;
}
/**
* Converts the APIResponse to a web response with appropriate status.
*
* @return a web response with status {@link Status.OK} if the commits pass
* validation, {@link Status.FORBIDDEN} otherwise.
*/
public Response toResponse() {
// update error count before returning
if (passed) {
return Response.ok(this).build();
} else {
return Response.status(Status.FORBIDDEN).entity(this).build();
}
}
private boolean passed;
private int errorCount;
private Date time;
private Map<String, CommitStatus> commits;
private boolean trackedProject;
private boolean strictMode;
public ValidationResponse() {
this.commits = new HashMap<>();
this.time = new Date();
this.strictMode = false;
}
/** @return the passed */
public boolean isPassed() {
return passed;
}
/** @param passed the passed to set */
public void setPassed(boolean passed) {
this.passed = passed;
}
/** @return the errorCount */
public int getErrorCount() {
this.errorCount = commits.values().stream().mapToInt(s -> s.getErrors().size()).sum();
return errorCount;
}
/** @param errorCount the errorCount to set */
public void setErrorCount(int errorCount) {
this.errorCount = errorCount;
}
/** @return the time */
public Date getTime() {
return time;
}
/** @param time the time to set */
public void setTime(Date time) {
this.time = time;
}
/** @return the commits */
public Map<String, CommitStatus> getCommits() {
return commits;
}
/** @param commits the commits to set */
public void setCommits(Map<String, CommitStatus> commits) {
this.commits = commits;
}
/** @param message message to add to the API response */
public void addMessage(String hash, String message, APIStatusCode code) {
commits.computeIfAbsent(getHashKey(hash), k -> new CommitStatus()).addMessage(message, code);
}
/** @param warning message to add to the API response */
public void addWarning(String hash, String warning, APIStatusCode code) {
commits.computeIfAbsent(getHashKey(hash), k -> new CommitStatus()).addWarning(warning, code);
}
/** @param error message to add to the API response */
public void addError(String hash, String error, APIStatusCode code) {
commits.computeIfAbsent(getHashKey(hash), k -> new CommitStatus()).addError(error, code);
}
/** @return the trackedProject */
public boolean isTrackedProject() {
return trackedProject;
}
/** @param trackedProject the trackedProject to set */
public void setTrackedProject(boolean trackedProject) {
this.trackedProject = trackedProject;
}
/** @return the strictMode */
public boolean isStrictMode() {
return strictMode;
}
/** @param strictMode the strictMode to set */
public void setStrictMode(boolean strictMode) {
this.strictMode = strictMode;
}
private String getHashKey(String hash) {
return hash == null ? "_nil" : hash;
}
/**
* Converts the APIResponse to a web response with appropriate status.
*
* @return a web response with status {@link Status.OK} if the commits pass validation, {@link
* Status.FORBIDDEN} otherwise.
*/
public Response toResponse() {
// update error count before returning
if (passed) {
return Response.ok(this).build();
} else {
return Response.status(Status.FORBIDDEN).entity(this).build();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment