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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations