Allow evaluating submit rules for draft changes
When actually submitting changes, we should continue short-circuiting and refusing to say draft changes are submittable. But for purely informational pre-submit operations, such as rendering the approval table, it makes sense to treat draft changes the same as any other open changes. Change-Id: I012c274c3e6a4b95adead3008a9c0ff56942d56b
This commit is contained in:
@@ -304,7 +304,7 @@ public class ChangeJson {
|
||||
if (ps == null) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
cd.setSubmitRecords(ctl.canSubmit(db.get(), ps, cd, true, false));
|
||||
cd.setSubmitRecords(ctl.canSubmit(db.get(), ps, cd, true, false, true));
|
||||
return cd.getSubmitRecords();
|
||||
}
|
||||
|
||||
|
@@ -100,7 +100,8 @@ public class ReviewerJson {
|
||||
ChangeData cd = new ChangeData(ctl);
|
||||
PatchSet ps = cd.currentPatchSet(db);
|
||||
if (ps != null) {
|
||||
for (SubmitRecord rec : ctl.canSubmit(db.get(), ps, cd, true, false)) {
|
||||
for (SubmitRecord rec :
|
||||
ctl.canSubmit(db.get(), ps, cd, true, false, true)) {
|
||||
if (rec.labels == null) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -316,7 +316,7 @@ public class ChangeControl {
|
||||
}
|
||||
|
||||
public List<SubmitRecord> getSubmitRecords(ReviewDb db, PatchSet patchSet) {
|
||||
return canSubmit(db, patchSet, null, false, true);
|
||||
return canSubmit(db, patchSet, null, false, true, false);
|
||||
}
|
||||
|
||||
public boolean canSubmit() {
|
||||
@@ -324,12 +324,13 @@ public class ChangeControl {
|
||||
}
|
||||
|
||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet) {
|
||||
return canSubmit(db, patchSet, null, false, false);
|
||||
return canSubmit(db, patchSet, null, false, false, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet,
|
||||
@Nullable ChangeData cd, boolean fastEvalLabels, boolean allowClosed) {
|
||||
@Nullable ChangeData cd, boolean fastEvalLabels, boolean allowClosed,
|
||||
boolean allowDraft) {
|
||||
if (!allowClosed && change.getStatus().isClosed()) {
|
||||
SubmitRecord rec = new SubmitRecord();
|
||||
rec.status = SubmitRecord.Status.CLOSED;
|
||||
@@ -340,23 +341,9 @@ public class ChangeControl {
|
||||
return ruleError("Patch set " + patchSet.getPatchSetId() + " is not current");
|
||||
}
|
||||
|
||||
try {
|
||||
if (change.getStatus() == Change.Status.DRAFT) {
|
||||
if (!isDraftVisible(db, cd)) {
|
||||
return ruleError("Patch set " + patchSet.getPatchSetId() + " not found");
|
||||
} else {
|
||||
return ruleError("Cannot submit draft changes");
|
||||
}
|
||||
}
|
||||
if (patchSet.isDraft()) {
|
||||
if (!isDraftVisible(db, cd)) {
|
||||
return ruleError("Patch set " + patchSet.getPatchSetId() + " not found");
|
||||
} else {
|
||||
return ruleError("Cannot submit draft patch sets");
|
||||
}
|
||||
}
|
||||
} catch (OrmException err) {
|
||||
return logRuleError("Cannot read patch set " + patchSet.getId(), err);
|
||||
if ((change.getStatus() == Change.Status.DRAFT || patchSet.isDraft())
|
||||
&& !allowDraft) {
|
||||
return cannotSubmitDraft(db, patchSet, cd);
|
||||
}
|
||||
|
||||
List<Term> results;
|
||||
@@ -387,6 +374,21 @@ public class ChangeControl {
|
||||
return resultsToSubmitRecord(evaluator.getSubmitRule(), results);
|
||||
}
|
||||
|
||||
private List<SubmitRecord> cannotSubmitDraft(ReviewDb db, PatchSet patchSet,
|
||||
ChangeData cd) {
|
||||
try {
|
||||
if (!isDraftVisible(db, cd)) {
|
||||
return ruleError("Patch set " + patchSet.getPatchSetId() + " not found");
|
||||
} else if (patchSet.isDraft()) {
|
||||
return ruleError("Cannot submit draft patch sets");
|
||||
} else {
|
||||
return ruleError("Cannot submit draft changes");
|
||||
}
|
||||
} catch (OrmException err) {
|
||||
return logRuleError("Cannot read patch set " + patchSet.getId(), err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the results from Prolog Cafe's format to Gerrit's common format.
|
||||
*
|
||||
|
@@ -283,7 +283,7 @@ public class QueryProcessor {
|
||||
PatchSet.Id psId = d.getChange().currentPatchSetId();
|
||||
PatchSet patchSet = db.get().patchSets().get(psId);
|
||||
List<SubmitRecord> submitResult = d.changeControl().canSubmit( //
|
||||
db.get(), patchSet, null, false, true);
|
||||
db.get(), patchSet, null, false, true, true);
|
||||
eventFactory.addSubmitRecords(c, submitResult);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user