Search in sources :

Example 41 with PatchSetApproval

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);
    }
}
Also used : NO_CHANGE(com.google.gerrit.extensions.client.ChangeKind.NO_CHANGE) Arrays(java.util.Arrays) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) REWORK(com.google.gerrit.extensions.client.ChangeKind.REWORK) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeKindCreator(com.google.gerrit.acceptance.testsuite.change.ChangeKindCreator) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MoreCollectors(com.google.common.collect.MoreCollectors) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) Set(java.util.Set) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) SubmitRecord(com.google.gerrit.entities.SubmitRecord) Collectors(java.util.stream.Collectors) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RawInputUtil(com.google.gerrit.common.RawInputUtil) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) TestLabels(com.google.gerrit.server.project.testing.TestLabels) CURRENT_COMMIT(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT) ImmutableList(com.google.common.collect.ImmutableList) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) LabelFunction(com.google.gerrit.entities.LabelFunction) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Comparator.comparing(java.util.Comparator.comparing) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) SubmitRule(com.google.gerrit.server.rules.SubmitRule) TestLabels.labelBuilder(com.google.gerrit.server.project.testing.TestLabels.labelBuilder) ChangeKindCacheImpl(com.google.gerrit.server.change.ChangeKindCacheImpl) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) NO_CODE_CHANGE(com.google.gerrit.extensions.client.ChangeKind.NO_CODE_CHANGE) MERGE_FIRST_PARENT_UPDATE(com.google.gerrit.extensions.client.ChangeKind.MERGE_FIRST_PARENT_UPDATE) ObjectId(org.eclipse.jgit.lib.ObjectId) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) TRIVIAL_REBASE(com.google.gerrit.extensions.client.ChangeKind.TRIVIAL_REBASE) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) Named(com.google.inject.name.Named) Cache(com.google.common.cache.Cache) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 42 with PatchSetApproval

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);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 43 with PatchSetApproval

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();
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Inject(com.google.inject.Inject) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) CommitDiff(com.google.gerrit.server.notedb.CommitRewriter.CommitDiff) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) OutputFormat(com.google.gerrit.json.OutputFormat) Gson(com.google.gson.Gson) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Map(java.util.Map) After(org.junit.After) RefNames(com.google.gerrit.entities.RefNames) RefUpdateUtil(com.google.gerrit.git.RefUpdateUtil) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) Set(java.util.Set) RevSort(org.eclipse.jgit.revwalk.RevSort) ReviewerStatusUpdate(com.google.gerrit.server.ReviewerStatusUpdate) Instant(java.time.Instant) SubmitRecord(com.google.gerrit.entities.SubmitRecord) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) VERIFIED(com.google.gerrit.entities.LabelId.VERIFIED) Ref(org.eclipse.jgit.lib.Ref) IntStream(java.util.stream.IntStream) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CC(com.google.gerrit.server.notedb.ReviewerStateInternal.CC) HashSet(java.util.HashSet) ChangeMessage(com.google.gerrit.entities.ChangeMessage) ImmutableList(com.google.common.collect.ImmutableList) CODE_REVIEW(com.google.gerrit.entities.LabelId.CODE_REVIEW) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) REVIEWER(com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER) Before(org.junit.Before) Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) CurrentUser(com.google.gerrit.server.CurrentUser) AttentionStatusInNoteDb(com.google.gerrit.server.notedb.ChangeNoteUtil.AttentionStatusInNoteDb) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) REMOVED(com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Repository(org.eclipse.jgit.lib.Repository) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Ref(org.eclipse.jgit.lib.Ref) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 44 with PatchSetApproval

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();
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Inject(com.google.inject.Inject) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) CommitDiff(com.google.gerrit.server.notedb.CommitRewriter.CommitDiff) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) OutputFormat(com.google.gerrit.json.OutputFormat) Gson(com.google.gson.Gson) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Map(java.util.Map) After(org.junit.After) RefNames(com.google.gerrit.entities.RefNames) RefUpdateUtil(com.google.gerrit.git.RefUpdateUtil) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) Set(java.util.Set) RevSort(org.eclipse.jgit.revwalk.RevSort) ReviewerStatusUpdate(com.google.gerrit.server.ReviewerStatusUpdate) Instant(java.time.Instant) SubmitRecord(com.google.gerrit.entities.SubmitRecord) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) VERIFIED(com.google.gerrit.entities.LabelId.VERIFIED) Ref(org.eclipse.jgit.lib.Ref) IntStream(java.util.stream.IntStream) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CC(com.google.gerrit.server.notedb.ReviewerStateInternal.CC) HashSet(java.util.HashSet) ChangeMessage(com.google.gerrit.entities.ChangeMessage) ImmutableList(com.google.common.collect.ImmutableList) CODE_REVIEW(com.google.gerrit.entities.LabelId.CODE_REVIEW) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) REVIEWER(com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER) Before(org.junit.Before) Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) CurrentUser(com.google.gerrit.server.CurrentUser) AttentionStatusInNoteDb(com.google.gerrit.server.notedb.ChangeNoteUtil.AttentionStatusInNoteDb) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) REMOVED(com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Repository(org.eclipse.jgit.lib.Repository) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) ObjectId(org.eclipse.jgit.lib.ObjectId) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Instant(java.time.Instant) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Ref(org.eclipse.jgit.lib.Ref) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 45 with PatchSetApproval

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();
}
Also used : Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)93 Test (org.junit.Test)57 Change (com.google.gerrit.entities.Change)41 LabelType (com.google.gerrit.entities.LabelType)22 Account (com.google.gerrit.entities.Account)20 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 Map (java.util.Map)14 ObjectId (org.eclipse.jgit.lib.ObjectId)14 LabelId (com.google.gerrit.entities.LabelId)13 PatchSet (com.google.gerrit.entities.PatchSet)12 SubmitRecord (com.google.gerrit.entities.SubmitRecord)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 SubmissionId (com.google.gerrit.entities.SubmissionId)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Inject (com.google.inject.Inject)9 Instant (java.time.Instant)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ChangeMessage (com.google.gerrit.entities.ChangeMessage)8