Remove ChangeControl.canSubmit(...) methods
All callers but one already had a ChangeData available, so they can just create their own SubmitRuleEvaluators, and we can get rid of this ugly method signature. Change-Id: I21c64f26de10de096f469982e5cf5d10b704e473
This commit is contained in:
@@ -89,6 +89,7 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.project.SubmitRuleEvaluator;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeData.ChangedLines;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -364,7 +365,10 @@ public class ChangeJson {
|
||||
if (ps == null) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
cd.setSubmitRecords(ctl.canSubmit(db.get(), ps, cd, true, false, true));
|
||||
cd.setSubmitRecords(new SubmitRuleEvaluator(cd).setPatchSet(ps)
|
||||
.setFastEvalLabels(true)
|
||||
.setAllowDraft(true)
|
||||
.canSubmit());
|
||||
return cd.getSubmitRecords();
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,7 @@ import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.SubmitRuleEvaluator;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -109,8 +110,11 @@ public class ReviewerJson {
|
||||
ChangeData cd = changeDataFactory.create(db.get(), ctl);
|
||||
PatchSet ps = cd.currentPatchSet();
|
||||
if (ps != null) {
|
||||
for (SubmitRecord rec :
|
||||
ctl.canSubmit(db.get(), ps, cd, true, false, true)) {
|
||||
for (SubmitRecord rec : new SubmitRuleEvaluator(cd)
|
||||
.setPatchSet(ps)
|
||||
.setFastEvalLabels(true)
|
||||
.setAllowDraft(true)
|
||||
.canSubmit()) {
|
||||
if (rec.labels == null) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -60,6 +60,8 @@ import com.google.gerrit.server.git.VersionedMetaData.BatchMetaDataUpdate;
|
||||
import com.google.gerrit.server.index.ChangeIndexer;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.SubmitRuleEvaluator;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gwtorm.server.AtomicUpdate;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -102,6 +104,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final ChangeData.Factory changeDataFactory;
|
||||
private final ChangeUpdate.Factory updateFactory;
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
@@ -118,6 +121,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
GitRepositoryManager repoManager,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
ChangeUpdate.Factory updateFactory,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
ChangeMessagesUtil cmUtil,
|
||||
@@ -131,6 +135,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
this.dbProvider = dbProvider;
|
||||
this.repoManager = repoManager;
|
||||
this.userFactory = userFactory;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
this.updateFactory = updateFactory;
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
this.cmUtil = cmUtil;
|
||||
@@ -374,10 +379,12 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
}
|
||||
|
||||
private List<SubmitRecord> checkSubmitRule(RevisionResource rsrc,
|
||||
boolean force) throws ResourceConflictException {
|
||||
List<SubmitRecord> results = rsrc.getControl().canSubmit(
|
||||
dbProvider.get(),
|
||||
rsrc.getPatchSet());
|
||||
boolean force) throws ResourceConflictException, OrmException {
|
||||
ChangeData cd =
|
||||
changeDataFactory.create(dbProvider.get(), rsrc.getControl());
|
||||
List<SubmitRecord> results = new SubmitRuleEvaluator(cd)
|
||||
.setPatchSet(rsrc.getPatchSet())
|
||||
.canSubmit();
|
||||
Optional<SubmitRecord> ok = findOkRecord(results);
|
||||
if (ok.isPresent()) {
|
||||
// Rules supplied a valid solution.
|
||||
|
@@ -20,7 +20,6 @@ import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.RefConfigSection;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
import com.google.gerrit.common.data.SubmitTypeRecord;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -38,9 +37,6 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.SymbolTerm;
|
||||
import com.googlecode.prolog_cafe.lang.Term;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -402,11 +398,6 @@ public class ChangeControl {
|
||||
|| getRefControl().canEditHashtags(); // user can edit hashtag on a specific ref
|
||||
}
|
||||
|
||||
|
||||
public List<SubmitRecord> getSubmitRecords(ReviewDb db, PatchSet patchSet) {
|
||||
return canSubmit(db, patchSet, null, false, true, false);
|
||||
}
|
||||
|
||||
public boolean canSubmit() {
|
||||
return getRefControl().canSubmit();
|
||||
}
|
||||
@@ -415,33 +406,11 @@ public class ChangeControl {
|
||||
return getRefControl().canSubmitAs();
|
||||
}
|
||||
|
||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet) {
|
||||
return canSubmit(db, patchSet, null, false, false, false);
|
||||
}
|
||||
|
||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet,
|
||||
@Nullable ChangeData cd, boolean fastEvalLabels, boolean allowClosed,
|
||||
boolean allowDraft) {
|
||||
cd = changeData(db, cd);
|
||||
try {
|
||||
return new SubmitRuleEvaluator(cd)
|
||||
.setPatchSet(patchSet)
|
||||
.setFastEvalLabels(fastEvalLabels)
|
||||
.setAllowClosed(allowClosed)
|
||||
.setAllowDraft(allowDraft)
|
||||
.canSubmit();
|
||||
} catch (OrmException e) {
|
||||
log.error("Error evaluating submit rule", e);
|
||||
return SubmitRuleEvaluator.defaultRuleError();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean match(String destBranch, String refPattern) {
|
||||
return RefPatternMatcher.getMatcher(refPattern).match(destBranch,
|
||||
this.getRefControl().getCurrentUser().getUserName());
|
||||
}
|
||||
|
||||
|
||||
public SubmitTypeRecord getSubmitTypeRecord(ReviewDb db, PatchSet patchSet) {
|
||||
return getSubmitTypeRecord(db, patchSet, null);
|
||||
}
|
||||
|
@@ -20,9 +20,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.config.TrackingFooters;
|
||||
import com.google.gerrit.server.data.ChangeAttribute;
|
||||
@@ -31,13 +29,13 @@ import com.google.gerrit.server.data.QueryStatsAttribute;
|
||||
import com.google.gerrit.server.events.EventFactory;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.SubmitRuleEvaluator;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.util.io.DisabledOutputStream;
|
||||
import org.slf4j.Logger;
|
||||
@@ -97,7 +95,6 @@ public class QueryProcessor {
|
||||
private final EventFactory eventFactory;
|
||||
private final ChangeQueryBuilder queryBuilder;
|
||||
private final ChangeQueryRewriter queryRewriter;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final TrackingFooters trackingFooters;
|
||||
private final CurrentUser user;
|
||||
private final int maxLimit;
|
||||
@@ -124,12 +121,11 @@ public class QueryProcessor {
|
||||
@Inject
|
||||
QueryProcessor(EventFactory eventFactory,
|
||||
ChangeQueryBuilder.Factory queryBuilder, CurrentUser currentUser,
|
||||
ChangeQueryRewriter queryRewriter, Provider<ReviewDb> db,
|
||||
ChangeQueryRewriter queryRewriter,
|
||||
TrackingFooters trackingFooters) {
|
||||
this.eventFactory = eventFactory;
|
||||
this.queryBuilder = queryBuilder.create(currentUser);
|
||||
this.queryRewriter = queryRewriter;
|
||||
this.db = db;
|
||||
this.trackingFooters = trackingFooters;
|
||||
this.user = currentUser;
|
||||
this.maxLimit = currentUser.getCapabilities()
|
||||
@@ -325,11 +321,10 @@ public class QueryProcessor {
|
||||
}
|
||||
|
||||
if (includeSubmitRecords) {
|
||||
PatchSet.Id psId = d.change().currentPatchSetId();
|
||||
PatchSet patchSet = db.get().patchSets().get(psId);
|
||||
List<SubmitRecord> submitResult = cc.canSubmit( //
|
||||
db.get(), patchSet, null, false, true, true);
|
||||
eventFactory.addSubmitRecords(c, submitResult);
|
||||
eventFactory.addSubmitRecords(c, new SubmitRuleEvaluator(d)
|
||||
.setAllowClosed(true)
|
||||
.setAllowDraft(true)
|
||||
.canSubmit());
|
||||
}
|
||||
|
||||
if (includeCommitMessage) {
|
||||
|
Reference in New Issue
Block a user