use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.
the class CancellationIT method handleClientDisconnectedForPush.
@Test
public void handleClientDisconnectedForPush() throws Exception {
CommitValidationListener commitValidationListener = new CommitValidationListener() {
@Override
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
// to the client.
throw new RequestCancelledException(RequestStateProvider.Reason.CLIENT_CLOSED_REQUEST, /* cancellationMessage= */
null);
}
};
try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/heads/master");
r.assertErrorStatus("Client Closed Request");
}
}
use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.
the class CancellationIT method handleServerDeadlineExceededForPush.
@Test
public void handleServerDeadlineExceededForPush() throws Exception {
CommitValidationListener commitValidationListener = new CommitValidationListener() {
@Override
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
// Simulate an exceeded deadline by throwing RequestCancelledException.
throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, /* cancellationMessage= */
null);
}
};
try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/heads/master");
r.assertErrorStatus("Server Deadline Exceeded");
}
}
use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.
the class SubmitRequirementExpressionsValidator method validateSubmitRequirementExpressions.
private ImmutableList<CommitValidationMessage> validateSubmitRequirementExpressions(Collection<SubmitRequirement> submitRequirements) {
List<CommitValidationMessage> validationMessages = new ArrayList<>();
for (SubmitRequirement submitRequirement : submitRequirements) {
validateSubmitRequirementExpression(validationMessages, submitRequirement, submitRequirement.submittabilityExpression(), ProjectConfig.KEY_SR_SUBMITTABILITY_EXPRESSION);
submitRequirement.applicabilityExpression().ifPresent(expression -> validateSubmitRequirementExpression(validationMessages, submitRequirement, expression, ProjectConfig.KEY_SR_APPLICABILITY_EXPRESSION));
submitRequirement.overrideExpression().ifPresent(expression -> validateSubmitRequirementExpression(validationMessages, submitRequirement, expression, ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION));
}
return ImmutableList.copyOf(validationMessages);
}
use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.
the class ReceiveCommits method rejectImplicitMerges.
private void rejectImplicitMerges(Set<RevCommit> mergedParents) throws IOException {
try (TraceTimer traceTimer = newTimer("rejectImplicitMerges")) {
if (!mergedParents.isEmpty()) {
Ref targetRef = receivePackRefCache.exactRef(magicBranch.dest.branch());
if (targetRef != null) {
RevWalk rw = receivePack.getRevWalk();
RevCommit tip = rw.parseCommit(targetRef.getObjectId());
boolean containsImplicitMerges = true;
for (RevCommit p : mergedParents) {
containsImplicitMerges &= !rw.isMergedInto(p, tip);
}
if (containsImplicitMerges) {
rw.reset();
for (RevCommit p : mergedParents) {
rw.markStart(p);
}
rw.markUninteresting(tip);
RevCommit c;
while ((c = rw.next()) != null) {
rw.parseBody(c);
messages.add(new CommitValidationMessage("Implicit Merge of " + abbreviateName(c, rw.getObjectReader()) + " " + c.getShortMessage(), ValidationMessage.Type.ERROR));
}
reject(magicBranch.cmd, "implicit merges detected");
}
}
}
}
}
use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.
the class ReceiveCommits method rejectImplicitMerges.
private void rejectImplicitMerges(Set<RevCommit> mergedParents) throws IOException {
if (!mergedParents.isEmpty()) {
Ref targetRef = allRefs.get(magicBranch.ctl.getRefName());
if (targetRef != null) {
RevWalk rw = rp.getRevWalk();
RevCommit tip = rw.parseCommit(targetRef.getObjectId());
boolean containsImplicitMerges = true;
for (RevCommit p : mergedParents) {
containsImplicitMerges &= !rw.isMergedInto(p, tip);
}
if (containsImplicitMerges) {
rw.reset();
for (RevCommit p : mergedParents) {
rw.markStart(p);
}
rw.markUninteresting(tip);
RevCommit c;
while ((c = rw.next()) != null) {
rw.parseBody(c);
messages.add(new CommitValidationMessage("ERROR: Implicit Merge of " + c.abbreviate(7).name() + " " + c.getShortMessage(), false));
}
reject(magicBranch.cmd, "implicit merges detected");
}
}
}
}
Aggregations