use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeData method reviewedBy.
public Set<Account.Id> reviewedBy() {
if (reviewedBy == null) {
if (!lazyload()) {
return Collections.emptySet();
}
Change c = change();
if (c == null) {
return Collections.emptySet();
}
List<ReviewedByEvent> events = new ArrayList<>();
for (ChangeMessage msg : messages()) {
if (msg.getAuthor() != null) {
events.add(ReviewedByEvent.create(msg));
}
}
events = Lists.reverse(events);
reviewedBy = new LinkedHashSet<>();
Account.Id owner = c.getOwner();
for (ReviewedByEvent event : events) {
if (owner.equals(event.author())) {
break;
}
reviewedBy.add(event.author());
}
}
return reviewedBy;
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ListChangeMessages method apply.
@Override
public Response<List<ChangeMessageInfo>> apply(ChangeResource resource) throws PermissionBackendException {
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<ChangeMessage> messages = changeMessagesUtil.byChange(resource.getNotes());
List<ChangeMessageInfo> messageInfos = messages.stream().map(m -> changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(m, accountLoader)).collect(Collectors.toList());
accountLoader.fill();
return Response.ok(messageInfos);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ListChangeRobotComments method apply.
@Override
public Response<Map<String, List<RobotCommentInfo>>> apply(ChangeResource rsrc) throws AuthException, PermissionBackendException {
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
Map<String, List<RobotCommentInfo>> robotCommentsMap = commentJson.get().setFillAccounts(true).setFillPatchSet(true).newRobotCommentFormatter().format(commentsUtil.robotCommentsByChange(cd.notes()));
List<RobotCommentInfo> commentInfos = robotCommentsMap.values().stream().flatMap(List::stream).collect(toList());
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, false);
return Response.ok(robotCommentsMap);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixAttentionFooter.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixAttentionFooter() throws Exception {
Change c = newChange();
ImmutableList.Builder<ObjectId> commitsToFix = new ImmutableList.Builder<>();
// Only 'reason' fix is required
ChangeUpdate invalidAttentionSetUpdate = newUpdate(c, changeOwner);
invalidAttentionSetUpdate.putReviewer(otherUserId, REVIEWER);
invalidAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", otherUser.getName())));
commitsToFix.add(invalidAttentionSetUpdate.commit());
ChangeUpdate invalidMultipleAttentionSetUpdate = newUpdate(c, changeOwner);
invalidMultipleAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", otherUser.getName())));
invalidMultipleAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", otherUser.getName())));
commitsToFix.add(invalidMultipleAttentionSetUpdate.commit());
String otherUserIdentToFix = getAccountIdentToFix(otherUser.getAccount());
String changeOwnerIdentToFix = getAccountIdentToFix(changeOwner.getAccount());
commitsToFix.add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, // Only 'person_ident' fix is required
"Attention: " + gson.toJson(new AttentionStatusInNoteDb(otherUserIdentToFix, Operation.ADD, "Added by someone using the hovercard menu")), // Both 'reason' and 'person_ident' fix is required
"Attention: " + gson.toJson(new AttentionStatusInNoteDb(changeOwnerIdentToFix, Operation.REMOVE, String.format("%s replied on the change", otherUser.getName())))), getAuthorIdent(changeOwner.getAccount())));
ChangeUpdate validAttentionSetUpdate = newUpdate(c, changeOwner);
validAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, "Removed by someone"));
validAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, "Added by someone"));
validAttentionSetUpdate.commit();
ChangeUpdate invalidRemovedByClickUpdate = newUpdate(c, changeOwner);
invalidRemovedByClickUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", otherUser.getName())));
commitsToFix.add(invalidRemovedByClickUpdate.commit());
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.build().stream().map(commit -> commitsBeforeRewrite.indexOf(commit)).collect(toImmutableList());
ChangeNotes notesBeforeRewrite = newNotes(c);
RunOptions options = new RunOptions();
options.dryRun = false;
BackfillResult result = rewriter.backfillProject(project, repo, options);
assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
notesBeforeRewrite.getAttentionSetUpdates();
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<AttentionSetUpdate> attentionSetUpdatesBeforeRewrite = ImmutableList.of(AttentionSetUpdate.createFromRead(invalidRemovedByClickUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", otherUser.getName())), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Added by someone"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone"), AttentionSetUpdate.createFromRead(updateTimestamp, changeOwner.getAccountId(), Operation.REMOVE, String.format("%s replied on the change", otherUser.getName())), AttentionSetUpdate.createFromRead(updateTimestamp, otherUserId, Operation.ADD, "Added by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", otherUser.getName())), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", otherUser.getName())), AttentionSetUpdate.createFromRead(invalidAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", otherUser.getName())));
ImmutableList<AttentionSetUpdate> attentionSetUpdatesAfterRewrite = ImmutableList.of(AttentionSetUpdate.createFromRead(invalidRemovedByClickUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, "Removed by someone by clicking the attention icon"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Added by someone"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone"), AttentionSetUpdate.createFromRead(updateTimestamp, changeOwner.getAccountId(), Operation.REMOVE, "Someone replied on the change"), AttentionSetUpdate.createFromRead(updateTimestamp, otherUserId, Operation.ADD, "Added by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Someone replied on the change"), AttentionSetUpdate.createFromRead(invalidAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, "Added by someone using the hovercard menu"));
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesBeforeRewrite);
assertThat(notesAfterRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesAfterRewrite);
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, invalidCommits);
assertFixedCommits(commitsToFix.build(), result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).hasSize(4);
assertThat(commitHistoryDiff.get(0)).isEqualTo("@@ -8 +8 @@\n" + "-Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by Other Account using the hovercard menu\"}\n" + "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}\n");
assertThat(Arrays.asList(commitHistoryDiff.get(1).split("\n"))).containsExactly("@@ -7,2 +7,2 @@", "-Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Other Account replied on the change\"}", "-Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by Other Account using the hovercard menu\"}", "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Someone replied on the change\"}", "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by someone using the hovercard menu\"}");
assertThat(Arrays.asList(commitHistoryDiff.get(2).split("\n"))).containsExactly("@@ -7,2 +7,2 @@", "-Attention: {\"person_ident\":\"Other Account \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}", "-Attention: {\"person_ident\":\"Change Owner \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Other Account replied on the change\"}", "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}", "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Someone replied on the change\"}");
assertThat(commitHistoryDiff.get(3)).isEqualTo("@@ -7 +7 @@\n" + "-Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by Other Account by clicking the attention icon\"}\n" + "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by someone by clicking the attention icon\"}\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeNotesStateTest method serializeChangeMessages.
@Test
public void serializeChangeMessages() throws Exception {
ChangeMessage m1 = ChangeMessage.create(ChangeMessage.key(ID, "uuid1"), Account.id(1000), Instant.ofEpochMilli(1212L), PatchSet.id(ID, 1));
Entities.ChangeMessage m1Proto = ChangeMessageProtoConverter.INSTANCE.toProto(m1);
ByteString m1Bytes = Protos.toByteString(m1Proto);
assertThat(m1Bytes.size()).isEqualTo(35);
ChangeMessage m2 = ChangeMessage.create(ChangeMessage.key(ID, "uuid2"), Account.id(2000), Instant.ofEpochMilli(3434L), PatchSet.id(ID, 2));
Entities.ChangeMessage m2Proto = ChangeMessageProtoConverter.INSTANCE.toProto(m2);
ByteString m2Bytes = Protos.toByteString(m2Proto);
assertThat(m2Bytes.size()).isEqualTo(35);
assertThat(m2Bytes).isNotEqualTo(m1Bytes);
assertRoundTrip(newBuilder().changeMessages(ImmutableList.of(m2, m1)).build(), ChangeNotesStateProto.newBuilder().setMetaId(SHA_BYTES).setChangeId(ID.get()).setColumns(colsProto).addChangeMessage(m2Proto).addChangeMessage(m1Proto).build());
}
Aggregations