use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.
the class DeleteReviewer method applyImpl.
@Override
protected Response<?> applyImpl(BatchUpdate.Factory updateFactory, ReviewerResource rsrc, DeleteReviewerInput input) throws RestApiException, UpdateException {
if (input == null) {
input = new DeleteReviewerInput();
}
if (input.notify == null) {
input.notify = NotifyHandling.ALL;
}
try (BatchUpdate bu = updateFactory.create(dbProvider.get(), rsrc.getChangeResource().getProject(), rsrc.getChangeResource().getUser(), TimeUtil.nowTs())) {
BatchUpdateOp op;
if (rsrc.isByEmail()) {
op = deleteReviewerByEmailOpFactory.create(rsrc.getReviewerByEmail(), input);
} else {
op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().getAccount(), input);
}
bu.addOp(rsrc.getChange().getId(), op);
bu.execute();
}
return Response.none();
}
use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.
the class DeleteReviewersUtil method addDeleteReviewerOpToBatchUpdate.
public void addDeleteReviewerOpToBatchUpdate(BatchUpdate batchUpdate, ChangeNotes changeNotes, ReviewerInput reviewerInput) throws IOException, ConfigInvalidException, AuthException, ResourceNotFoundException {
try {
AccountResolver.Result result = accountResolver.resolveIgnoreVisibility(reviewerInput.reviewer);
if (fetchAccountIds(changeNotes).contains(result.asUniqueUser().getAccountId())) {
DeleteReviewerInput deleteReviewerInput = new DeleteReviewerInput();
deleteReviewerInput.notify = reviewerInput.notify;
deleteReviewerInput.notifyDetails = reviewerInput.notifyDetails;
batchUpdate.addOp(changeNotes.getChangeId(), deleteReviewerOpFactory.create(result.asUnique().account(), deleteReviewerInput));
return;
}
return;
} catch (AccountResolver.UnresolvableAccountException e) {
if (e.isSelf()) {
throw new AuthException(e.getMessage(), e);
}
}
Address address = Address.tryParse(reviewerInput.reviewer);
if (address != null && changeNotes.getReviewersByEmail().all().contains(address)) {
batchUpdate.addOp(changeNotes.getChangeId(), deleteReviewerByEmailOpFactory.create(address));
return;
}
throw new ResourceNotFoundException(reviewerInput.reviewer);
}
use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.
the class ChangeNotificationsIT method removeReviewer.
private void removeReviewer(StagedChange sc, TestAccount account, NotifyHandling notify) throws Exception {
sender.clear();
DeleteReviewerInput in = new DeleteReviewerInput();
in.notify = notify;
gApi.changes().id(sc.changeId).reviewer(account.email()).remove(in);
}
use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.
the class SetReviewersCommand method modifyOne.
private boolean modifyOne(ChangeResource changeRsrc) throws Exception {
boolean ok = true;
//
for (Account.Id reviewer : toRemove) {
ReviewerResource rsrc = reviewerFactory.create(changeRsrc, reviewer);
String error = null;
try {
deleteReviewer.apply(rsrc, new DeleteReviewerInput());
} catch (ResourceNotFoundException e) {
error = String.format("could not remove %s: not found", reviewer);
} catch (Exception e) {
error = String.format("could not remove %s: %s", reviewer, e.getMessage());
}
if (error != null) {
ok = false;
writeError("error", error);
}
}
//
for (String reviewer : toAdd) {
ReviewerInput input = new ReviewerInput();
input.reviewer = reviewer;
input.confirmed = true;
String error;
try {
error = postReviewers.apply(changeRsrc, input).value().error;
} catch (Exception e) {
error = String.format("could not add %s: %s", reviewer, e.getMessage());
}
if (error != null) {
ok = false;
writeError("error", error);
}
}
return ok;
}
use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.
the class DeleteReviewer method apply.
@Override
public Response<Object> apply(ReviewerResource rsrc, DeleteReviewerInput input) throws RestApiException, UpdateException {
if (input == null) {
input = new DeleteReviewerInput();
}
try (BatchUpdate bu = updateFactory.create(rsrc.getChangeResource().getProject(), rsrc.getChangeResource().getUser(), TimeUtil.now())) {
bu.setNotify(getNotify(rsrc.getChange(), input));
BatchUpdateOp op;
if (rsrc.isByEmail()) {
op = deleteReviewerByEmailOpFactory.create(rsrc.getReviewerByEmail());
} else {
op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().getAccount(), input);
}
bu.addOp(rsrc.getChange().getId(), op);
bu.execute();
}
return Response.none();
}
Aggregations