use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.
the class MergeOp method validateChangeList.
private BranchBatch validateChangeList(OpenRepo or, Collection<ChangeData> submitted) throws IntegrationException {
logDebug("Validating {} changes", submitted.size());
Set<CodeReviewCommit> toSubmit = new LinkedHashSet<>(submitted.size());
SetMultimap<ObjectId, PatchSet.Id> revisions = getRevisions(or, submitted);
SubmitType submitType = null;
ChangeData choseSubmitTypeFrom = null;
for (ChangeData cd : submitted) {
Change.Id changeId = cd.getId();
ChangeControl ctl;
Change chg;
try {
ctl = cd.changeControl();
chg = cd.change();
} catch (OrmException e) {
commitStatus.logProblem(changeId, e);
continue;
}
SubmitType st = getSubmitType(cd);
if (st == null) {
commitStatus.logProblem(changeId, "No submit type for change");
continue;
}
if (submitType == null) {
submitType = st;
choseSubmitTypeFrom = cd;
} else if (st != submitType) {
commitStatus.problem(changeId, String.format("Change has submit type %s, but previously chose submit type %s " + "from change %s in the same batch", st, submitType, choseSubmitTypeFrom.getId()));
continue;
}
if (chg.currentPatchSetId() == null) {
String msg = "Missing current patch set on change";
logError(msg + " " + changeId);
commitStatus.problem(changeId, msg);
continue;
}
PatchSet ps;
Branch.NameKey destBranch = chg.getDest();
try {
ps = cd.currentPatchSet();
} catch (OrmException e) {
commitStatus.logProblem(changeId, e);
continue;
}
if (ps == null || ps.getRevision() == null || ps.getRevision().get() == null) {
commitStatus.logProblem(changeId, "Missing patch set or revision on change");
continue;
}
String idstr = ps.getRevision().get();
ObjectId id;
try {
id = ObjectId.fromString(idstr);
} catch (IllegalArgumentException e) {
commitStatus.logProblem(changeId, e);
continue;
}
if (!revisions.containsEntry(id, ps.getId())) {
// TODO this is actually an error, the branch is gone but we
// want to merge the issue. We can't safely do that if the
// tip is not reachable.
//
commitStatus.logProblem(changeId, "Revision " + idstr + " of patch set " + ps.getPatchSetId() + " does not match " + ps.getId().toRefName() + " for change");
continue;
}
CodeReviewCommit commit;
try {
commit = or.rw.parseCommit(id);
} catch (IOException e) {
commitStatus.logProblem(changeId, e);
continue;
}
// TODO(dborowitz): Consider putting ChangeData in CodeReviewCommit.
commit.setControl(ctl);
commit.setPatchsetId(ps.getId());
commitStatus.put(commit);
MergeValidators mergeValidators = mergeValidatorsFactory.create();
try {
mergeValidators.validatePreMerge(or.repo, commit, or.project, destBranch, ps.getId(), caller);
} catch (MergeValidationException mve) {
commitStatus.problem(changeId, mve.getMessage());
continue;
}
commit.add(or.canMergeFlag);
toSubmit.add(commit);
}
logDebug("Submitting on this run: {}", toSubmit);
return new AutoValue_MergeOp_BranchBatch(submitType, toSubmit);
}
use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_storedForClosedChanges.
@Test
public void submitRequirement_storedForClosedChanges() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
voteLabel(changeId, "Code-Review", 2);
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
revision.review(ReviewInput.approve());
revision.submit();
ChangeNotes notes = notesFactory.create(project, r.getChange().getId());
SubmitRequirementResult result = notes.getSubmitRequirementsResult().stream().collect(MoreCollectors.onlyElement());
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
assertThat(result.submittabilityExpressionResult().get().expression().expressionString()).isEqualTo("label:Code-Review=MAX");
}
}
use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_retrievedFromNoteDbForAbandonedChanges.
@Test
public void submitRequirement_retrievedFromNoteDbForAbandonedChanges() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
voteLabel(changeId, "Code-Review", 2);
gApi.changes().id(changeId).abandon();
// Add another submit requirement. This will not get returned for the abandoned change, since
// we return the state of the SR results when the change was abandoned.
configSubmitRequirement(project, SubmitRequirement.builder().setName("New-Requirement").setSubmittabilityExpression(SubmitRequirementExpression.create("-has:unresolved")).setAllowOverrideInChildProjects(false).build());
ChangeInfo changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMIT_REQUIREMENTS);
assertThat(changeInfo.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false, /* submittabilityCondition= */
"label:Code-Review=MAX");
// Restore the change, the new requirement will show up
gApi.changes().id(changeId).restore();
changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMIT_REQUIREMENTS);
assertThat(changeInfo.submitRequirements).hasSize(2);
assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false, /* submittabilityCondition= */
"label:Code-Review=MAX");
assertSubmitRequirementStatus(changeInfo.submitRequirements, "New-Requirement", Status.SATISFIED, /* isLegacy= */
false, /* submittabilityCondition= */
"-has:unresolved");
// Abandon again, make sure the new requirement was persisted
gApi.changes().id(changeId).abandon();
changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMIT_REQUIREMENTS);
assertThat(changeInfo.submitRequirements).hasSize(2);
assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false, /* submittabilityCondition= */
"label:Code-Review=MAX");
assertSubmitRequirementStatus(changeInfo.submitRequirements, "New-Requirement", Status.SATISFIED, /* isLegacy= */
false, /* submittabilityCondition= */
"-has:unresolved");
}
}
use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_loadedFromTheLatestRevisionNoteForClosedChanges.
@Test
public void submitRequirement_loadedFromTheLatestRevisionNoteForClosedChanges() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
// Abandon change. Submit requirements get stored in the revision note of patch-set 1.
gApi.changes().id(changeId).abandon();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
// Restore the change.
gApi.changes().id(changeId).restore();
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
// Upload a second patch-set, fulfill the CR submit requirement.
amendChange(changeId, "refs/for/master", user, repo);
change = gApi.changes().id(changeId).get();
assertThat(change.revisions).hasSize(2);
voteLabel(changeId, "Code-Review", 2);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
// Abandon the change.
gApi.changes().id(changeId).abandon();
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
}
}
use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_storedForAbandonedChanges.
@Test
public void submitRequirement_storedForAbandonedChanges() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
voteLabel(changeId, "Code-Review", 2);
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
gApi.changes().id(r.getChangeId()).abandon();
ChangeNotes notes = notesFactory.create(project, r.getChange().getId());
SubmitRequirementResult result = notes.getSubmitRequirementsResult().stream().collect(MoreCollectors.onlyElement());
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
assertThat(result.submittabilityExpressionResult().get().expression().expressionString()).isEqualTo("label:Code-Review=MAX");
}
}
Aggregations