Fix /submit_type to return only uppercase names

Instead of returning the literal string from Prolog, force it to
uppercase the way ChangeControl does as it casts the name through
the Project.SubmitType enum.

Change-Id: I8caca1c92d8ff30a70270f1e1b004a4c5265ab5b
This commit is contained in:
Shawn Pearce 2013-08-20 22:11:51 -07:00
parent 8ab132bf31
commit 7076f4e646
3 changed files with 19 additions and 19 deletions

View File

@ -1611,7 +1611,7 @@ a project-specific rule.
Content-Type: application/json;charset=UTF-8
)]}'
"cherry_pick"
"CHERRY_PICK"
----
[[test-submit-rule]]

View File

@ -58,7 +58,7 @@ public class Mergeable implements RestReadView<RevisionResource> {
private static final Logger log = LoggerFactory.getLogger(Mergeable.class);
public static class MergeableInfo {
public String submitType;
public Project.SubmitType submitType;
public boolean mergeable;
}
@ -123,21 +123,10 @@ public class Mergeable implements RestReadView<RevisionResource> {
private boolean refresh(Change change,
PatchSet ps,
String submitType,
Project.SubmitType type,
Repository git,
Map<String, Ref> refs,
Ref ref) throws IOException, OrmException {
Project.SubmitType type;
try {
type = Project.SubmitType.valueOf(submitType);
} catch (IllegalArgumentException unsupported) {
log.warn(String.format(
"Change %d uses unsupported submit_type \"%s\"",
change.getId().get(),
submitType));
return false;
}
RevWalk rw = new RevWalk(git) {
@Override
protected CodeReviewCommit createCommit(AnyObjectId id) {

View File

@ -20,6 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.rules.RulesCache;
import com.google.gerrit.server.change.TestSubmitRule.Filters;
@ -30,6 +31,7 @@ import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.googlecode.prolog_cafe.lang.SymbolTerm;
import com.googlecode.prolog_cafe.lang.Term;
import org.kohsuke.args4j.Option;
@ -51,8 +53,8 @@ public class TestSubmitType implements RestModifyView<RevisionResource, Input> {
}
@Override
public String apply(RevisionResource rsrc, Input input) throws OrmException,
BadRequestException, AuthException {
public SubmitType apply(RevisionResource rsrc, Input input)
throws OrmException, BadRequestException, AuthException {
if (input == null) {
input = new Input();
}
@ -96,7 +98,16 @@ public class TestSubmitType implements RestModifyView<RevisionResource, Input> {
evaluator.getSubmitRule().toString(),
type));
}
return type.toString();
String typeName = ((SymbolTerm) type).name();
try {
return SubmitType.valueOf(typeName.toUpperCase());
} catch (IllegalArgumentException e) {
throw new BadRequestException(String.format(
"rule %s produced invalid result: %s",
evaluator.getSubmitRule().toString(),
type));
}
}
static class Get implements RestReadView<RevisionResource> {
@ -108,8 +119,8 @@ public class TestSubmitType implements RestModifyView<RevisionResource, Input> {
}
@Override
public String apply(RevisionResource resource) throws BadRequestException,
OrmException, AuthException {
public SubmitType apply(RevisionResource resource)
throws BadRequestException, OrmException, AuthException {
return test.apply(resource, null);
}
}