Search in sources :

Example 6 with SubmitRuleEvaluator

use of com.google.gerrit.server.project.SubmitRuleEvaluator in project gerrit by GerritCodeReview.

the class SubmitRuleIT method submitRecordsForClosedChanges_recomputedIfRequested.

@Test
public void submitRecordsForClosedChanges_recomputedIfRequested() throws Exception {
    SubmitRuleEvaluator submitRuleEvaluator = submitRuleEvaluatorFactory.create(SubmitRuleOptions.builder().recomputeOnClosedChanges(true).build());
    PushOneCommit.Result r = createChange();
    approve(r.getChangeId());
    List<SubmitRecord> recordsBeforeSubmission = submitRuleEvaluator.evaluate(r.getChange());
    assertThat(recordsBeforeSubmission.stream().map(record -> record.ruleName).collect(Collectors.toList())).containsExactly(DefaultSubmitRule.RULE_NAME);
    gApi.changes().id(r.getChangeId()).current().submit();
    // Add a new label that blocks submission if not granted. In case we reevaluate the rules,
    // this would show up as blocking submission.
    setupCustomBlockingLabel();
    List<SubmitRecord> recordsAfterSubmission = submitRuleEvaluator.evaluate(r.getChange());
    assertThat(recordsBeforeSubmission).isNotEqualTo(recordsAfterSubmission);
    assertThat(recordsAfterSubmission).hasSize(1);
    List<SubmitRecord.Label> recordLabels = recordsAfterSubmission.get(0).labels;
    assertThat(recordLabels).hasSize(2);
    assertCodeReviewApproved(recordLabels);
    assertMyLabelNeed(recordLabels);
}
Also used : SubmitRuleEvaluator(com.google.gerrit.server.project.SubmitRuleEvaluator) Inject(com.google.inject.Inject) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmitRuleOptions(com.google.gerrit.server.project.SubmitRuleOptions) DefaultSubmitRule(com.google.gerrit.server.rules.DefaultSubmitRule) Collectors(java.util.stream.Collectors) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) List(java.util.List) SubmitRuleEvaluator(com.google.gerrit.server.project.SubmitRuleEvaluator) ImmutableList(com.google.common.collect.ImmutableList) LabelValue(com.google.gerrit.entities.LabelValue) LabelType(com.google.gerrit.entities.LabelType) LabelFunction(com.google.gerrit.entities.LabelFunction) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) SubmitRecord(com.google.gerrit.entities.SubmitRecord) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with SubmitRuleEvaluator

use of com.google.gerrit.server.project.SubmitRuleEvaluator in project gerrit by GerritCodeReview.

the class RulesIT method getStatus.

private SubmitRecord.Status getStatus(PushOneCommit.Result result) throws Exception {
    ChangeData cd = result.getChange();
    Collection<SubmitRecord> records;
    try (AutoCloseable ignored1 = disableChangeIndex();
        AutoCloseable ignored2 = disableAccountIndex()) {
        SubmitRuleEvaluator ruleEvaluator = evaluatorFactory.create(SubmitRuleOptions.defaults());
        records = ruleEvaluator.evaluate(cd);
    }
    assertThat(records).hasSize(1);
    SubmitRecord record = records.iterator().next();
    return record.status;
}
Also used : SubmitRuleEvaluator(com.google.gerrit.server.project.SubmitRuleEvaluator) SubmitRecord(com.google.gerrit.entities.SubmitRecord) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Aggregations

SubmitRuleEvaluator (com.google.gerrit.server.project.SubmitRuleEvaluator)7 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3 ImmutableList (com.google.common.collect.ImmutableList)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 LabelFunction (com.google.gerrit.entities.LabelFunction)2 LabelType (com.google.gerrit.entities.LabelType)2 LabelValue (com.google.gerrit.entities.LabelValue)2 TestSubmitRuleInput (com.google.gerrit.extensions.common.TestSubmitRuleInput)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 SubmitRuleOptions (com.google.gerrit.server.project.SubmitRuleOptions)2 DefaultSubmitRule (com.google.gerrit.server.rules.DefaultSubmitRule)2 Inject (com.google.inject.Inject)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 LabelType (com.google.gerrit.common.data.LabelType)1 LabelTypes (com.google.gerrit.common.data.LabelTypes)1