Fix comments rendering with imported changes
Resetting change message counter if no commments are matched.
Imported changes might lead to situations where change messages and
comments don't always match.
Only skip setting the changeMessageId for the broken message
and start checking from the beginning of the change messages.
This fixes the test added in I72e3af09.
Bug: Issue 318079520
Release-Notes: Fix comments rendering with imported changes
Change-Id: Ia3d693ac7ea9d38578814872ef33dd442ec0fdc9
diff --git a/java/com/google/gerrit/server/CommentsUtil.java b/java/com/google/gerrit/server/CommentsUtil.java
index deaff4b..a204920 100644
--- a/java/com/google/gerrit/server/CommentsUtil.java
+++ b/java/com/google/gerrit/server/CommentsUtil.java
@@ -268,6 +268,15 @@
}
if (cmItr < changeMessages.size()) {
comment.changeMessageId = sortedChangeMessages.get(cmItr).getKey().uuid();
+ } else {
+ // In case of no match "cmItr" will never be less than "changeMessages" size, hance the
+ // changeMessageId won't be set for any comment.
+ //
+ // Reset the search from the beginning, since we can't assume there will always be a match
+ // between change messages and comments. This could be the case of imported changes.
+ //
+ // More details here: https://issues.gerritcodereview.com/issues/318079520
+ cmItr = 0;
}
}
}
diff --git a/javatests/com/google/gerrit/server/restapi/change/ListChangeCommentsTest.java b/javatests/com/google/gerrit/server/restapi/change/ListChangeCommentsTest.java
index db97d17..326f4da 100644
--- a/javatests/com/google/gerrit/server/restapi/change/ListChangeCommentsTest.java
+++ b/javatests/com/google/gerrit/server/restapi/change/ListChangeCommentsTest.java
@@ -34,7 +34,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -126,7 +125,6 @@
.doesNotContain(getChangeMessage(changeMessages, "cm2.2").getKey().uuid());
}
- @Ignore
@Test
public void commentsLinkedToCorrectAccountsIaUserNotMatched() {