Do not ignore SubmitRecord status from Prolog rules

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
diff --git a/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java b/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java
index 1361122..d00e16d 100644
--- a/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java
+++ b/java/com/google/gerrit/server/project/SubmitRequirementsAdapter.java
@@ -184,7 +184,12 @@
     }
     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 b05f3c7..6de4e79 100644
--- a/javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java
+++ b/javatests/com/google/gerrit/server/project/SubmitRequirementsAdapterTest.java
@@ -333,6 +333,29 @@
   }
 
   @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(