summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Milanesio <luca.milanesio@gmail.com>2024-05-28 14:36:18 +0100
committerLuca Milanesio <luca.milanesio@gmail.com>2024-05-28 18:13:37 +0000
commitde2ebbdc37b20cd78792c0ce25e0f2053c211842 (patch)
tree4786bf2528f82e7e360bdfe9dad717d7ef75d0d0
parenta5a51a94cc2df3a1cebcd9a98f4edd53c834adb9 (diff)
Do not ignore SubmitRecord status from Prolog rulesupstream/stable-3.6
When translating a SubmitRecord into a SubmitRequirement in Ie0fbf0e70, the status field was forgotten in the translation and ignored. A custom Prolog rule returning a status "OK" with extra labels was therefore considered as not satisifed requirement whilst it should have been passed them. When the overall SubmitRecord.status is OK, skip all the other labels that are not compatible with the SubmitRecord.status field. Restore the behaviour observed in Gerrit with custom Prolog rules in v3.5 or earlier versions. Bug: Issue 343218480 Release-Notes: Fix translation of custom Prolog rules SubmitRecord to SubmitRequirement(s) Change-Id: Ib0ac6c7638dece3d14261a3ac45c43825e7ecec8
-rw-r--r--java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java7
-rw-r--r--javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java23
2 files changed, 29 insertions, 1 deletions
diff --git a/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java b/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java
index 136112298d..d00e16d320 100644
--- a/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java
+++ b/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java
@@ -184,7 +184,12 @@ public class SubmitRequirementsAdapter {
}
ImmutableList.Builder<SubmitRequirementResult> result = ImmutableList.builder();
for (Label label : record.labels) {
- if (skipSubmitRequirementFor(label)) {
+ if (skipSubmitRequirementFor(label)
+ ||
+ // If SubmitRecord is a PASS, then skip all the requirements
+ // that are not a PASS as they would block the overall submit requirement
+ // status from being a PASS
+ (mapStatus(record) == Status.PASS && mapStatus(label) != Status.PASS)) {
continue;
}
String expressionString = String.format("label:%s=%s", label.label, ruleName);
diff --git a/javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java b/javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java
index b05f3c7170..6de4e7955b 100644
--- a/javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java
+++ b/javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java
@@ -333,6 +333,29 @@ public class SubmitRequirementsAdapterTest {
}
@Test
+ public void customSubmitRule_withLabels_withStatusOk() {
+ SubmitRecord submitRecord =
+ createSubmitRecord(
+ "gerrit~PrologRule",
+ Status.OK,
+ Arrays.asList(
+ createLabel("custom-need-label-1", Label.Status.NEED),
+ createLabel("custom-pass-label-2", Label.Status.OK),
+ createLabel("custom-may-label-3", Label.Status.MAY)));
+
+ List<SubmitRequirementResult> requirements =
+ SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, false);
+
+ assertThat(requirements).hasSize(1);
+ assertResult(
+ requirements.get(0),
+ /* reqName= */ "custom-pass-label-2",
+ /* submitExpression= */ "label:custom-pass-label-2=gerrit~PrologRule",
+ SubmitRequirementResult.Status.SATISFIED,
+ SubmitRequirementExpressionResult.Status.PASS);
+ }
+
+ @Test
public void customSubmitRule_withMixOfPassingAndFailingLabels() {
SubmitRecord submitRecord =
createSubmitRecord(