Support controlling the submit type for changes from Prolog
Similarly like the "submit_rule" there is now a "submit_type" predicate which returns the allowed submit type for a change. When the submit_type predicate is not provided in the rules.pl then the project default submit type is used for all changes for that project. Filtering the results of the submit_type is also supported in the same way like filtering the results of the submit_rule. Using a submit_type_filter predicate one can enforce a particular submit type from a parent project. For example, a release engineer may want to enforce the FAST_FORWARD_ONLY submit type for all changes pushed to stable release branches while, at the same time, use the project wide default submit type for changes pushed to the development branch. Change-Id: Iec08f412723856b40324a6e0ec00ac523be9a3b6 Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:

committed by
Gerrit Code Review

parent
162c801f4b
commit
680a5f80d9
@@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package gerrit;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
import com.google.gerrit.rules.StoredValues;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.Operation;
|
||||
import com.googlecode.prolog_cafe.lang.Predicate;
|
||||
import com.googlecode.prolog_cafe.lang.Prolog;
|
||||
import com.googlecode.prolog_cafe.lang.PrologException;
|
||||
import com.googlecode.prolog_cafe.lang.SymbolTerm;
|
||||
import com.googlecode.prolog_cafe.lang.Term;
|
||||
|
||||
public class PRED_project_default_submit_type_1 extends Predicate.P1 {
|
||||
|
||||
private static final SymbolTerm[] term;
|
||||
|
||||
static {
|
||||
SubmitType[] val = SubmitType.values();
|
||||
term = new SymbolTerm[val.length];
|
||||
for (int i = 0; i < val.length; i++) {
|
||||
term[i] = SymbolTerm.create(val[i].name());
|
||||
}
|
||||
}
|
||||
|
||||
public PRED_project_default_submit_type_1(Term a1, Operation n) {
|
||||
arg1 = a1;
|
||||
cont = n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation exec(Prolog engine) throws PrologException {
|
||||
engine.setB0();
|
||||
Term a1 = arg1.dereference();
|
||||
|
||||
ChangeControl control = StoredValues.CHANGE_CONTROL.get(engine);
|
||||
SubmitType submitType = control.getProject().getSubmitType();
|
||||
|
||||
if (!a1.unify(term[submitType.ordinal()], engine.trail)) {
|
||||
return engine.fail();
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user