Search in sources :

Example 1 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorImpl method evaluateRequirement.

@Override
public SubmitRequirementResult evaluateRequirement(SubmitRequirement sr, ChangeData cd) {
    try (ManualRequestContext ignored = requestContext.open()) {
        // Use a request context to execute predicates as an internal user with expanded visibility.
        // This is so that the evaluation does not depend on who is running the current request (e.g.
        // a "ownerin" predicate with group that is not visible to the person making this request).
        Optional<SubmitRequirementExpressionResult> applicabilityResult = sr.applicabilityExpression().isPresent() ? Optional.of(evaluateExpression(sr.applicabilityExpression().get(), cd)) : Optional.empty();
        Optional<SubmitRequirementExpressionResult> submittabilityResult = Optional.empty();
        Optional<SubmitRequirementExpressionResult> overrideResult = Optional.empty();
        if (!sr.applicabilityExpression().isPresent() || SubmitRequirementResult.assertPass(applicabilityResult)) {
            submittabilityResult = Optional.of(evaluateExpression(sr.submittabilityExpression(), cd));
            overrideResult = sr.overrideExpression().isPresent() ? Optional.of(evaluateExpression(sr.overrideExpression().get(), cd)) : Optional.empty();
        }
        return SubmitRequirementResult.builder().legacy(Optional.of(false)).submitRequirement(sr).patchSetCommitId(cd.currentPatchSet().commitId()).submittabilityExpressionResult(submittabilityResult).applicabilityExpressionResult(applicabilityResult).overrideExpressionResult(overrideResult).build();
    }
}
Also used : SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) ManualRequestContext(com.google.gerrit.server.util.ManualRequestContext)

Example 2 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_deletedContent_nonMatching.

@Test
public void byFileEdits_deletedContent_nonMatching() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 1\n", "")).childOf().change(parent).create();
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line 2'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method expressionWithPassingPredicate.

@Test
public void expressionWithPassingPredicate() throws Exception {
    SubmitRequirementExpression expression = SubmitRequirementExpression.create("branch:refs/heads/master");
    SubmitRequirementExpressionResult result = evaluator.evaluateExpression(expression, changeData);
    assertThat(result.status()).isEqualTo(Status.PASS);
    assertThat(result.errorMessage()).isEqualTo(Optional.empty());
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_deletedContent_matching.

@Test
public void byFileEdits_deletedContent_matching() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 2\n", "")).childOf().change(parent).create();
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line 2'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_escapeDoubleQuotes.

@Test
public void byFileEdits_escapeDoubleQuotes() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 3\n", "line \"three\" is modified\n")).childOf().change(parent).create();
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line \\\"three\\\" is'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

SubmitRequirementExpressionResult (com.google.gerrit.entities.SubmitRequirementExpressionResult)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)23 SubmitRequirementExpression (com.google.gerrit.entities.SubmitRequirementExpression)23 Test (org.junit.Test)23 Change (com.google.gerrit.entities.Change)16 ChangeData (com.google.gerrit.server.query.change.ChangeData)16 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 ManualRequestContext (com.google.gerrit.server.util.ManualRequestContext)1