summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaushik Lingarkar <kaushik.lingarkar@linaro.org>2023-08-29 12:24:55 -0700
committerKaushik Lingarkar <kaushik.lingarkar@linaro.org>2023-09-05 16:11:43 +0000
commit002afb0f0815aada066b6d3d7d98c522d5f2757f (patch)
tree511fe4e2037fd69d76691484ea1d862624b52f5c
parent05985d0b925d188f7a4464206e69cf79cab616a8 (diff)
SSH Query: Show copied approvals on respective patchsets
Copied approvals are currently only shown on the current patch-set. CI systems parsing the query result to get approvals on non-current patch-sets will run into issues if copied approvals are not returned on respective patch-sets. Release-Notes: SSH queries now show copied approvals on respective patch-sets Bug: Issue 295457464 Change-Id: I40a605be7f27c70233d94130ae6c5aba22e8818c
-rw-r--r--java/com/google/gerrit/server/approval/ApprovalsUtil.java4
-rw-r--r--java/com/google/gerrit/server/query/change/ChangeData.java12
-rw-r--r--java/com/google/gerrit/server/query/change/OutputStreamQuery.java2
-rw-r--r--javatests/com/google/gerrit/acceptance/ssh/QueryIT.java29
4 files changed, 46 insertions, 1 deletions
diff --git a/java/com/google/gerrit/server/approval/ApprovalsUtil.java b/java/com/google/gerrit/server/approval/ApprovalsUtil.java
index 77ac2e2390..870485a5a3 100644
--- a/java/com/google/gerrit/server/approval/ApprovalsUtil.java
+++ b/java/com/google/gerrit/server/approval/ApprovalsUtil.java
@@ -346,6 +346,10 @@ public class ApprovalsUtil {
return notes.load().getApprovals();
}
+ public ListMultimap<PatchSet.Id, PatchSetApproval> byChangeWithCopied(ChangeNotes notes) {
+ return notes.load().getApprovalsWithCopied();
+ }
+
public Iterable<PatchSetApproval> byPatchSet(
ChangeNotes notes, PatchSet.Id psId, @Nullable RevWalk rw, @Nullable Config repoConfig) {
return approvalInference.forPatchSet(notes, psId, rw, repoConfig);
diff --git a/java/com/google/gerrit/server/query/change/ChangeData.java b/java/com/google/gerrit/server/query/change/ChangeData.java
index 9961519bf7..3b47aae56f 100644
--- a/java/com/google/gerrit/server/query/change/ChangeData.java
+++ b/java/com/google/gerrit/server/query/change/ChangeData.java
@@ -321,6 +321,8 @@ public class ChangeData {
private PatchSet currentPatchSet;
private Collection<PatchSet> patchSets;
private ListMultimap<PatchSet.Id, PatchSetApproval> allApprovals;
+
+ private ListMultimap<PatchSet.Id, PatchSetApproval> allApprovalsWithCopied;
private List<PatchSetApproval> currentApprovals;
private List<String> currentFiles;
private Optional<DiffSummary> diffSummary;
@@ -775,6 +777,16 @@ public class ChangeData {
return allApprovals;
}
+ public ListMultimap<PatchSet.Id, PatchSetApproval> conditionallyLoadApprovalsWithCopied() {
+ if (allApprovalsWithCopied == null) {
+ if (!lazyload()) {
+ return ImmutableListMultimap.of();
+ }
+ allApprovalsWithCopied = approvalsUtil.byChangeWithCopied(notes());
+ }
+ return allApprovalsWithCopied;
+ }
+
/* @return legacy submit ('SUBM') approval label */
// TODO(mariasavtchouk): Deprecate legacy submit label,
// see com.google.gerrit.entities.LabelId.LEGACY_SUBMIT_NAME
diff --git a/java/com/google/gerrit/server/query/change/OutputStreamQuery.java b/java/com/google/gerrit/server/query/change/OutputStreamQuery.java
index 961404adb7..d21f5b62a3 100644
--- a/java/com/google/gerrit/server/query/change/OutputStreamQuery.java
+++ b/java/com/google/gerrit/server/query/change/OutputStreamQuery.java
@@ -303,7 +303,7 @@ public class OutputStreamQuery {
rw,
c,
d.patchSets(),
- includeApprovals ? d.approvals().asMap() : null,
+ includeApprovals ? d.conditionallyLoadApprovalsWithCopied().asMap() : null,
includeFiles,
d.change(),
labelTypes,
diff --git a/javatests/com/google/gerrit/acceptance/ssh/QueryIT.java b/javatests/com/google/gerrit/acceptance/ssh/QueryIT.java
index cd4f57137b..59f80e9d9a 100644
--- a/javatests/com/google/gerrit/acceptance/ssh/QueryIT.java
+++ b/javatests/com/google/gerrit/acceptance/ssh/QueryIT.java
@@ -23,6 +23,8 @@ import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.acceptance.UseSsh;
+import com.google.gerrit.entities.LabelId;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.annotations.Exports;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.ReviewerInput;
@@ -325,6 +327,33 @@ public class QueryIT extends AbstractDaemonTest {
}
}
+ @Test
+ public void allApprovalsAllPatchSetsOptionsWithCopyConditionJSON() throws Exception {
+ // Copy min Code-Review votes
+ try (ProjectConfigUpdate u = updateProject(Project.NameKey.parse("All-Projects"))) {
+ u.getConfig().updateLabelType(LabelId.CODE_REVIEW, b -> b.setCopyCondition("is:MIN"));
+ u.save();
+ }
+
+ // Create a change and add Code-Review -2 on first patch-set
+ String changeId = createChange().getChangeId();
+ gApi.changes().id(changeId).current().review(ReviewInput.reject());
+
+ // Create second patch-set
+ amendChange(changeId);
+
+ // Assert that second patch-set has Code-Review -2 vote
+ List<ChangeAttribute> changes =
+ executeSuccessfulQuery("--all-approvals --patch-sets " + changeId);
+ assertThat(changes).hasSize(1);
+ assertThat(changes.get(0).patchSets).hasSize(2);
+ assertThat(changes.get(0).patchSets.get(1).approvals).isNotNull();
+ assertThat(changes.get(0).patchSets.get(1).approvals).hasSize(1);
+ assertThat(changes.get(0).patchSets.get(1).approvals.get(0).type)
+ .isEqualTo(LabelId.CODE_REVIEW);
+ assertThat(changes.get(0).patchSets.get(1).approvals.get(0).value).isEqualTo("-2");
+ }
+
protected static class SamplePluginModule extends AbstractModule {
@Override
public void configure() {