Search in sources :

Example 11 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method mergeChange.

private ChangeNotes mergeChange(ChangeNotes notes) throws Exception {
    ObjectId oldId = getDestRef(notes);
    ObjectId newId = psUtil.current(notes).commitId();
    String dest = notes.getChange().getDest().branch();
    try (BatchUpdate bu = newUpdate(adminId)) {
        bu.addOp(notes.getChangeId(), new BatchUpdateOp() {

            @Override
            public void updateRepo(RepoContext ctx) throws IOException {
                ctx.addRefUpdate(oldId, newId, dest);
            }

            @Override
            public boolean updateChange(ChangeContext ctx) {
                ctx.getChange().setStatus(Change.Status.MERGED);
                ctx.getUpdate(ctx.getChange().currentPatchSetId()).fixStatusToMerged(new SubmissionId(ctx.getChange()));
                return true;
            }
        });
        bu.execute();
    }
    return reload(notes);
}
Also used : RepoContext(com.google.gerrit.server.update.RepoContext) ChangeContext(com.google.gerrit.server.update.ChangeContext) ObjectId(org.eclipse.jgit.lib.ObjectId) SubmissionId(com.google.gerrit.entities.SubmissionId) IOException(java.io.IOException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp)

Example 12 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class OpenRepoTest method allowExceedingLimitWhenChangeIsSubmitted.

@Test
public void allowExceedingLimitWhenChangeIsSubmitted() throws Exception {
    try (OpenRepo openRepo = openRepo()) {
        Change c = newChange();
        ChangeUpdate update = newUpdate(c, changeOwner);
        update.merge(new SubmissionId(c), ImmutableList.of(submitRecord("NOT_READY", null, submitLabel("Verified", "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null))));
        ListMultimap<String, ChangeUpdate> changeUpdates = new ImmutableListMultimap.Builder<String, ChangeUpdate>().put("one", update).build();
        openRepo.addUpdates(changeUpdates, NO_UPDATES_AT_ALL, MAX_PATCH_SETS);
        assertThat(fakeChainedReceiveCommands.commands.size()).isEqualTo(1);
    }
}
Also used : SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 13 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class CommitMessageOutputTest method submitWithErrorMessage.

@Test
public void submitWithErrorMessage() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Submit patch set 1");
    SubmissionId submissionId = new SubmissionId(c);
    update.merge(submissionId, ImmutableList.of(submitRecord("RULE_ERROR", "Problem with patch set:\n1")));
    update.commit();
    assertBodyEquals("Submit patch set 1\n" + "\n" + "Patch-set: 1\n" + "Status: merged\n" + "Submission-id: " + submissionId.toString() + "\n" + "Submitted-with: RULE_ERROR Problem with patch set: 1\n", update.getResult());
}
Also used : SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 14 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class ChangeNotesTest method copiedApprovalsPostSubmit.

@Test
public void copiedApprovalsPostSubmit() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putCopiedApproval(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(LabelId.CODE_REVIEW))).value(1).copied(true).granted(TimeUtil.now()).build());
    update.putCopiedApproval(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(LabelId.VERIFIED))).value(1).copied(true).granted(TimeUtil.now()).build());
    update.commit();
    update = newUpdate(c, changeOwner);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null))));
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putCopiedApproval(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(LabelId.CODE_REVIEW))).value(2).copied(true).granted(TimeUtil.now()).build());
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<PatchSetApproval> approvals = Lists.newArrayList(notes.getApprovalsWithCopied().values());
    assertThat(approvals).hasSize(2);
    assertThat(approvals.get(0).label()).isEqualTo(LabelId.VERIFIED);
    assertThat(approvals.get(0).value()).isEqualTo((short) 1);
    assertThat(approvals.get(0).postSubmit()).isFalse();
    assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(approvals.get(1).value()).isEqualTo((short) 2);
    assertThat(approvals.get(1).postSubmit()).isTrue();
}
Also used : SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 15 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class ChangeNotesTest method mergedOnSetWhenSubmitted.

@Test
public void mergedOnSetWhenSubmitted() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Update patch set 1");
    update.merge(submissionId, ImmutableList.of(submitRecord("OK", null, submitLabel(LabelId.CODE_REVIEW, "OK", otherUser.getAccountId()))));
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getMergedOn()).isPresent();
    Instant mergedOn = notes.getMergedOn().get();
    assertThat(mergedOn).isEqualTo(notes.getChange().getLastUpdatedOn());
    // Next update does not change mergedOn date.
    update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) 1);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getMergedOn().get()).isEqualTo(mergedOn);
    assertThat(notes.getMergedOn().get()).isLessThan(notes.getChange().getLastUpdatedOn());
}
Also used : Instant(java.time.Instant) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

SubmissionId (com.google.gerrit.entities.SubmissionId)18 Change (com.google.gerrit.entities.Change)13 Test (org.junit.Test)12 ObjectId (org.eclipse.jgit.lib.ObjectId)5 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)4 Instant (java.time.Instant)4 Joiner (com.google.common.base.Joiner)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)3 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)3 ChangeContext (com.google.gerrit.server.update.ChangeContext)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 Account (com.google.gerrit.entities.Account)2 LabelTypes (com.google.gerrit.entities.LabelTypes)2