use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class TestSubmitType method apply.
@Override
public Response<SubmitType> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, BadRequestException {
if (input == null) {
input = new TestSubmitRuleInput();
}
if (input.rule == null) {
throw new BadRequestException("rule is required");
}
if (!rules.isProjectRulesEnabled()) {
throw new AuthException("project rules are disabled");
}
input.filters = MoreObjects.firstNonNull(input.filters, filters);
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
SubmitTypeRecord rec = prologRule.getSubmitType(cd, PrologOptions.dryRunOptions(input.rule, input.filters == Filters.SKIP));
if (rec.status != SubmitTypeRecord.Status.OK) {
throw new BadRequestException(String.format("rule produced invalid result: %s", rec));
}
return Response.ok(rec.type);
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class CheckConsistency method apply.
@Override
public Response<ConsistencyCheckInfo> apply(ConfigResource resource, ConsistencyCheckInput input) throws RestApiException, IOException, PermissionBackendException, ConfigInvalidException {
permissionBackend.currentUser().check(GlobalPermission.ACCESS_DATABASE);
if (input == null || (input.checkAccounts == null && input.checkAccountExternalIds == null && input.checkGroups == null)) {
throw new BadRequestException("input required");
}
ConsistencyCheckInfo consistencyCheckInfo = new ConsistencyCheckInfo();
if (input.checkAccounts != null) {
consistencyCheckInfo.checkAccountsResult = new CheckAccountsResultInfo(accountsConsistencyChecker.check());
}
if (input.checkAccountExternalIds != null) {
consistencyCheckInfo.checkAccountExternalIdsResult = new CheckAccountExternalIdsResultInfo(externalIdsConsistencyChecker.check());
}
if (input.checkGroups != null) {
consistencyCheckInfo.checkGroupsResult = new CheckGroupsResultInfo(groupsConsistencyChecker.check());
}
return Response.ok(consistencyCheckInfo);
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickMergeUsingInvalidParent.
@Test
public void cherryPickMergeUsingInvalidParent() throws Exception {
String parent1FileName = "a.txt";
String parent2FileName = "b.txt";
PushOneCommit.Result mergeChangeResult = createCherryPickableMerge(parent1FileName, parent2FileName);
String cherryPickBranchName = "branch_for_cherry_pick";
createBranch(BranchNameKey.create(project, cherryPickBranchName));
CherryPickInput cherryPickInput = new CherryPickInput();
cherryPickInput.destination = cherryPickBranchName;
cherryPickInput.message = "Cherry-pick a merge commit to another branch";
cherryPickInput.parent = 0;
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput));
assertThat(thrown).hasMessageThat().contains("Cherry Pick: Parent 0 does not exist. Please specify a parent in range [1, 2].");
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class RevisionIT method listFilesWithInvalidParent.
@Test
public void listFilesWithInvalidParent() throws Exception {
PushOneCommit.Result result1 = createChange();
String changeId = result1.getChangeId();
PushOneCommit.Result result2 = amendChange(changeId, SUBJECT, "b.txt", "b");
String revId2 = result2.getCommit().name();
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId).revision(revId2).files(2));
assertThat(thrown).hasMessageThat().isEqualTo("invalid parent number: 2");
thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId).revision(revId2).files(-1));
assertThat(thrown).hasMessageThat().isEqualTo("invalid parent number: -1");
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class RobotCommentsIT method robotCommentInvalidInReplyTo.
@Test
public void robotCommentInvalidInReplyTo() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
RobotCommentInput input = TestCommentHelper.createRobotCommentInput(PATCHSET_LEVEL);
input.inReplyTo = "invalid";
BadRequestException ex = assertThrows(BadRequestException.class, () -> testCommentHelper.addRobotComment(changeId, input));
assertThat(ex.getMessage()).contains("inReplyTo");
}
Aggregations