use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method sticky_copiedToLatestPatchSetFromSubmitRecords.
@Test
public void sticky_copiedToLatestPatchSetFromSubmitRecords() throws Exception {
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().updateLabelType(LabelId.VERIFIED, b -> b.setFunction(LabelFunction.NO_BLOCK));
u.save();
}
// mentioned in the Submitted-With footer) is returned from the API.
try (Registration registration = extensionRegistry.newRegistration().add(new TestSubmitRule(user.id()))) {
// We want to add a vote on PS1, then not copy it to PS2, but include it in submit records
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
// Vote on patch-set 1
vote(admin, changeId, 2, 1);
vote(user, changeId, 1, -1);
// Upload patch-set 2. Change user's "Verified" vote on PS2.
changeOperations.change(Change.id(r.getChange().getId().get())).newPatchset().file("new_file").content("content").commitMessage("Upload PS2").create();
vote(admin, changeId, 2, 1);
vote(user, changeId, 1, 1);
// Upload patch-set 3
changeOperations.change(Change.id(r.getChange().getId().get())).newPatchset().file("another_file").content("content").commitMessage("Upload PS3").create();
vote(admin, changeId, 2, 1);
List<PatchSetApproval> patchSetApprovals = notesFactory.create(project, r.getChange().getId()).getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
// There's no verified approval on PS#3.
assertThat(patchSetApprovals.stream().filter(a -> a.accountId().equals(user.id()) && a.label().equals(TestLabels.verified().getName()) && a.patchSetId().get() == 3).collect(Collectors.toList())).isEmpty();
// Submit the change. The TestSubmitRule will store a "submit record" containing a label
// voted by user, but the latest patch-set does not have an approval for this user, hence
// it will be copied if we request approvals after the change is merged.
requestScopeOperations.setApiUser(admin.id());
gApi.changes().id(changeId).current().submit();
patchSetApprovals = notesFactory.create(project, r.getChange().getId()).getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
// Get the copied approval for user on PS3 for the "Verified" label.
PatchSetApproval verifiedApproval = patchSetApprovals.stream().filter(a -> a.accountId().equals(user.id()) && a.label().equals(TestLabels.verified().getName()) && a.patchSetId().get() == 3).collect(MoreCollectors.onlyElement());
assertCopied(verifiedApproval, /* psId= */
3, TestLabels.verified().getName(), (short) 1, /* copied= */
true);
}
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method stickyWithCopyAllScoresIfListOfFilesDidNotChangeWhenFileIsModifiedDueToRebase_withoutCopyCondition.
@Test
public void stickyWithCopyAllScoresIfListOfFilesDidNotChangeWhenFileIsModifiedDueToRebase_withoutCopyCondition() throws Exception {
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().updateLabelType(LabelId.CODE_REVIEW, b -> b.setCopyAllScoresIfListOfFilesDidNotChange(true));
u.save();
}
// Create two changes both with the same parent
PushOneCommit.Result r = createChange();
testRepo.reset("HEAD~1");
PushOneCommit.Result r2 = createChange();
// Modify f.txt in change 1. Approve and submit the first change
gApi.changes().id(r.getChangeId()).edit().modifyFile("f.txt", RawInputUtil.create("content"));
gApi.changes().id(r.getChangeId()).edit().publish();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
revision.review(ReviewInput.approve().label(LabelId.VERIFIED, 1));
revision.submit();
// Add an approval whose score should be copied on change 2.
gApi.changes().id(r2.getChangeId()).current().review(ReviewInput.recommend());
// Rebase the second change. The rebase adds f1.txt.
gApi.changes().id(r2.getChangeId()).rebase();
// The code-review approval is copied for the second change between PS1 and PS2 since the only
// modified file is due to rebase.
List<PatchSetApproval> patchSetApprovals = r2.getChange().notes().getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
PatchSetApproval nonCopied = patchSetApprovals.get(0);
PatchSetApproval copied = patchSetApprovals.get(1);
assertCopied(nonCopied, /* psId= */
1, LabelId.CODE_REVIEW, (short) 1, false);
assertCopied(copied, /* psId= */
2, LabelId.CODE_REVIEW, (short) 1, true);
}
use of com.google.gerrit.entities.PatchSetApproval 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.PatchSetApproval 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.PatchSetApproval in project gerrit by GerritCodeReview.
the class AbstractSubmit method assertNoSubmitter.
protected void assertNoSubmitter(String changeId, int psId) throws Throwable {
Change c = getOnlyElement(queryProvider.get().byKeyPrefix(changeId)).change();
ChangeNotes cn = notesFactory.createChecked(c);
PatchSetApproval submitter = approvalsUtil.getSubmitter(cn, PatchSet.id(cn.getChangeId(), psId));
assertThat(submitter).isNull();
}
Aggregations