Search in sources :

Example 26 with PatchSet

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

the class PatchSetProtoConverterTest method mandatoryValuesConvertedToProto.

@Test
public void mandatoryValuesConvertedToProto() {
    PatchSet patchSet = PatchSet.builder().id(PatchSet.id(Change.id(103), 73)).commitId(ObjectId.fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")).uploader(Account.id(452)).createdOn(Instant.ofEpochMilli(930349320L)).build();
    Entities.PatchSet proto = patchSetProtoConverter.toProto(patchSet);
    Entities.PatchSet expectedProto = Entities.PatchSet.newBuilder().setId(Entities.PatchSet_Id.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(103)).setId(73)).setCommitId(Entities.ObjectId.newBuilder().setName("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")).setUploaderAccountId(Entities.Account_Id.newBuilder().setId(452)).setCreatedOn(930349320L).build();
    assertThat(proto).isEqualTo(expectedProto);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 27 with PatchSet

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

the class MergeOp method checkSubmitRequirements.

public static void checkSubmitRequirements(ChangeData cd) throws ResourceConflictException {
    PatchSet patchSet = cd.currentPatchSet();
    if (patchSet == null) {
        throw new ResourceConflictException("missing current patch set for change " + cd.getId());
    }
    Map<SubmitRequirement, SubmitRequirementResult> srResults = cd.submitRequirementsIncludingLegacy();
    if (srResults.values().stream().allMatch(SubmitRequirementResult::fulfilled)) {
        return;
    } else if (srResults.isEmpty()) {
        throw new IllegalStateException(String.format("Submit requirement results for change '%s' and patchset '%s' " + "are empty in project '%s'", cd.getId(), patchSet.id(), cd.change().getProject().get()));
    }
    for (SubmitRequirementResult srResult : srResults.values()) {
        switch(srResult.status()) {
            case SATISFIED:
            case NOT_APPLICABLE:
            case OVERRIDDEN:
            case FORCED:
                break;
            case ERROR:
                throw new ResourceConflictException(String.format("submit requirement '%s' has an error: %s", srResult.submitRequirement().name(), srResult.errorMessage().orElse("")));
            case UNSATISFIED:
                throw new ResourceConflictException(String.format("submit requirement '%s' is unsatisfied.", srResult.submitRequirement().name()));
            default:
                throw new IllegalStateException(String.format("Unexpected submit requirement status %s for %s in %s", srResult.status().name(), patchSet.id().getId(), cd.change().getProject().get()));
        }
    }
    throw new IllegalStateException();
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) PatchSet(com.google.gerrit.entities.PatchSet) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult)

Example 28 with PatchSet

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

the class SubmitStrategyOp method getOrCreateAlreadyMergedPatchSet.

private PatchSet getOrCreateAlreadyMergedPatchSet(ChangeContext ctx) throws IOException {
    PatchSet.Id psId = alreadyMergedCommit.getPatchsetId();
    logger.atFine().log("Fixing up already-merged patch set %s", psId);
    PatchSet prevPs = args.psUtil.current(ctx.getNotes());
    ctx.getRevWalk().parseBody(alreadyMergedCommit);
    ctx.getChange().setCurrentPatchSet(psId, alreadyMergedCommit.getShortMessage(), ctx.getChange().getOriginalSubject());
    PatchSet existing = args.psUtil.get(ctx.getNotes(), psId);
    if (existing != null) {
        logger.atFine().log("Patch set row exists, only updating change");
        return existing;
    }
    // No patch set for the already merged commit, although we know it came form
    // a patch set ref. Fix up the database. Note that this uses the current
    // user as the uploader, which is as good a guess as any.
    List<String> groups = prevPs != null ? prevPs.groups() : GroupCollector.getDefaultGroups(alreadyMergedCommit);
    return args.psUtil.insert(ctx.getRevWalk(), ctx.getUpdate(psId), psId, alreadyMergedCommit, groups, null, null);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet)

Example 29 with PatchSet

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

the class AbstractSubmitOnPush method mergeOnPushToBranchWithOldPatchset.

@Test
public void mergeOnPushToBranchWithOldPatchset() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/heads/master").group(adminGroupUuid())).update();
    PushOneCommit.Result r = pushTo("refs/for/master");
    r.assertOkStatus();
    RevCommit c1 = r.getCommit();
    PatchSet.Id psId1 = r.getPatchSetId();
    String changeId = r.getChangeId();
    assertThat(psId1.get()).isEqualTo(1);
    r = amendChange(changeId);
    ChangeData cd = r.getChange();
    PatchSet.Id psId2 = cd.change().currentPatchSetId();
    assertThat(psId2.changeId()).isEqualTo(psId1.changeId());
    assertThat(psId2.get()).isEqualTo(2);
    testRepo.reset(c1);
    assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master");
    cd = changeDataFactory.create(project, psId1.changeId());
    Change c = cd.change();
    assertThat(c.isMerged()).isTrue();
    assertThat(c.currentPatchSetId()).isEqualTo(psId1);
    assertThat(cd.patchSets().stream().map(PatchSet::id).collect(toList())).containsExactly(psId1, psId2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 30 with PatchSet

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

the class AbstractSubmitOnPush method mergeMultipleOnPushToBranchWithNewPatchset.

@Test
public void mergeMultipleOnPushToBranchWithNewPatchset() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/heads/master").group(adminGroupUuid())).update();
    // Create 2 changes.
    ObjectId initialHead = projectOperations.project(project).getHead("master");
    PushOneCommit.Result r1 = createChange("Change 1", "a", "a");
    r1.assertOkStatus();
    PushOneCommit.Result r2 = createChange("Change 2", "b", "b");
    r2.assertOkStatus();
    RevCommit c1_1 = r1.getCommit();
    RevCommit c2_1 = r2.getCommit();
    PatchSet.Id psId1_1 = r1.getPatchSetId();
    PatchSet.Id psId2_1 = r2.getPatchSetId();
    assertThat(c1_1.getParent(0)).isEqualTo(initialHead);
    assertThat(c2_1.getParent(0)).isEqualTo(c1_1);
    // Amend both changes.
    testRepo.reset(initialHead);
    RevCommit c1_2 = testRepo.branch("HEAD").commit().message(c1_1.getShortMessage() + "v2").insertChangeId(r1.getChangeId().substring(1)).create();
    RevCommit c2_2 = testRepo.cherryPick(c2_1);
    // Push directly to branch.
    assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master");
    ChangeData cd2 = r2.getChange();
    assertThat(cd2.change().isMerged()).isTrue();
    PatchSet.Id psId2_2 = cd2.change().currentPatchSetId();
    assertThat(psId2_2.get()).isEqualTo(2);
    assertThat(cd2.patchSet(psId2_1).commitId()).isEqualTo(c2_1);
    assertThat(cd2.patchSet(psId2_2).commitId()).isEqualTo(c2_2);
    ChangeData cd1 = r1.getChange();
    assertThat(cd1.change().isMerged()).isTrue();
    PatchSet.Id psId1_2 = cd1.change().currentPatchSetId();
    assertThat(psId1_2.get()).isEqualTo(2);
    assertThat(cd1.patchSet(psId1_1).commitId()).isEqualTo(c1_1);
    assertThat(cd1.patchSet(psId1_2).commitId()).isEqualTo(c1_2);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11