use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeMessageProtoConverterTest method allValuesConvertedToProtoAndBackAgain.
@Test
public void allValuesConvertedToProtoAndBackAgain() {
ChangeMessage changeMessage = ChangeMessage.create(ChangeMessage.key(Change.id(543), "change-message-21"), Account.id(63), Instant.ofEpochMilli(9876543), PatchSet.id(Change.id(34), 13), "This is a change message.", Account.id(10003), "An arbitrary tag.");
ChangeMessage convertedChangeMessage = changeMessageProtoConverter.fromProto(changeMessageProtoConverter.toProto(changeMessage));
assertThat(convertedChangeMessage).isEqualTo(changeMessage);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixRemoveVoteChangeMessage.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixRemoveVoteChangeMessage() throws Exception {
Change c = newChange();
String approverIdentToFix = getAccountIdentToFix(otherUser.getAccount());
ChangeUpdate approvalUpdateByOtherUser = newUpdate(c, otherUser);
approvalUpdateByOtherUser.putApproval(CODE_REVIEW, (short) +2);
approvalUpdateByOtherUser.putApproval("Custom-Label", (short) -1);
approvalUpdateByOtherUser.putApprovalFor(changeOwner.getAccountId(), VERIFIED, (short) -1);
approvalUpdateByOtherUser.commit();
ImmutableList<ObjectId> commitsToFix = new ImmutableList.Builder<ObjectId>().add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Code-Review+2 by " + otherUser.getNameEmail(), "Label: -Code-Review " + approverIdentToFix), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Custom-Label-1 by " + otherUser.getNameEmail(), "Label: -Custom-Label " + getValidIdentAsString(otherUser.getAccount())), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
"Removed Verified+2 by " + changeOwner.getNameEmail(), "Label: -Verified"), getAuthorIdent(changeOwner.getAccount()))).build();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.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()));
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<PatchSetApproval> expectedApprovals = ImmutableList.of(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(VERIFIED))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label"))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create(CODE_REVIEW))).value(0).granted(updateTimestamp).build());
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(changeMessages(notesBeforeRewrite)).containsExactly("Removed Code-Review+2 by Other Account <other@account.com>", "Removed Custom-Label-1 by Other Account <other@account.com>", "Removed Verified+2 by Change Owner <change@owner.com>");
assertThat(notesBeforeRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
assertThat(changeMessages(notesAfterRewrite)).containsExactly("Removed Code-Review+2 by <GERRIT_ACCOUNT_2>", "Removed Custom-Label-1 by <GERRIT_ACCOUNT_2>", "Removed Verified+2 by <GERRIT_ACCOUNT_1>");
assertThat(notesAfterRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
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, result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -6 +6 @@\n" + "-Removed Code-Review+2 by Other Account <other@account.com>\n" + "+Removed Code-Review+2 by <GERRIT_ACCOUNT_2>\n" + "@@ -9 +9 @@\n" + "-Label: -Code-Review Other Account <2@gerrit>\n" + "+Label: -Code-Review Gerrit User 2 <2@gerrit>\n", "@@ -6 +6 @@\n" + "-Removed Custom-Label-1 by Other Account <other@account.com>\n" + "+Removed Custom-Label-1 by <GERRIT_ACCOUNT_2>\n", "@@ -6 +6 @@\n" + "-Removed Verified+2 by Change Owner <change@owner.com>\n" + "+Removed Verified+2 by <GERRIT_ACCOUNT_1>\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 CommitRewriterTest method fixLabelFooterIdent.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixLabelFooterIdent() throws Exception {
Change c = newChange();
String approverIdentToFix = getAccountIdentToFix(otherUser.getAccount());
String changeOwnerIdentToFix = getAccountIdentToFix(changeOwner.getAccount());
ChangeUpdate approvalUpdateByOtherUser = newUpdate(c, otherUser);
approvalUpdateByOtherUser.putApproval(VERIFIED, (short) -1);
approvalUpdateByOtherUser.commit();
ImmutableList<ObjectId> commitsToFix = new ImmutableList.Builder<ObjectId>().add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, "Label: -Verified " + approverIdentToFix, "Label: Custom-Label-1=-1 " + approverIdentToFix, "Label: Verified=+1", "Label: Custom-Label-1=+1", "Label: Custom-Label-2=+2 " + approverIdentToFix, "Label: Custom-Label-3=0 " + approverIdentToFix), getAuthorIdent(changeOwner.getAccount()))).add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
null, "Label: -Verified " + changeOwnerIdentToFix, "Label: Custom-Label-1=+1"), getAuthorIdent(otherUser.getAccount()))).build();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
ImmutableList<Integer> invalidCommits = commitsToFix.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()));
Instant updateTimestamp = serverIdent.getWhen().toInstant();
ImmutableList<PatchSetApproval> expectedApprovals = ImmutableList.of(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(VERIFIED))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create("Custom-Label-1"))).value(+1).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create(VERIFIED))).value(0).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label-1"))).value(+1).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label-2"))).value(+2).granted(updateTimestamp).build(), PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), otherUserId, LabelId.create("Custom-Label-3"))).value(0).granted(updateTimestamp).build());
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(notesBeforeRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
assertThat(notesAfterRewrite.getApprovals().get(c.currentPatchSetId())).containsExactlyElementsIn(expectedApprovals);
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, result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -7,2 +7,2 @@\n" + "-Label: -Verified Other Account <2@gerrit>\n" + "-Label: Custom-Label-1=-1 Other Account <2@gerrit>\n" + "+Label: -Verified Gerrit User 2 <2@gerrit>\n" + "+Label: Custom-Label-1=-1 Gerrit User 2 <2@gerrit>\n" + "@@ -11,2 +11,2 @@\n" + "-Label: Custom-Label-2=+2 Other Account <2@gerrit>\n" + "-Label: Custom-Label-3=0 Other Account <2@gerrit>\n" + "+Label: Custom-Label-2=+2 Gerrit User 2 <2@gerrit>\n" + "+Label: Custom-Label-3=0 Gerrit User 2 <2@gerrit>\n", "@@ -7 +7 @@\n" + "-Label: -Verified Change Owner <1@gerrit>\n" + "+Label: -Verified Gerrit User 1 <1@gerrit>\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 ChangeNotesParser method parseChangeMessage.
private boolean parseChangeMessage(PatchSet.Id psId, Account.Id accountId, Account.Id realAccountId, ChangeNotesCommit commit, Instant ts) {
Optional<String> changeMsgString = getChangeMessageString(commit);
if (!changeMsgString.isPresent()) {
return false;
}
ChangeMessage changeMessage = ChangeMessage.create(ChangeMessage.key(psId.changeId(), commit.name()), accountId, ts, psId, changeMsgString.get(), realAccountId, tag);
return allChangeMessages.add(changeMessage);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class DeleteChangeMessage method createUpdatedChangeMessageInfo.
private ChangeMessageInfo createUpdatedChangeMessageInfo(Change.Id cId, Project.NameKey project, int targetIdx) throws PermissionBackendException {
List<ChangeMessage> messages = changeMessagesUtil.byChange(notesFactory.createChecked(project, cId));
ChangeMessage updatedChangeMessage = messages.get(targetIdx);
AccountLoader accountLoader = accountLoaderFactory.create(true);
ChangeMessageInfo info = changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(updatedChangeMessage, accountLoader);
accountLoader.fill();
return info;
}
Aggregations