use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ReviewCommand method reviewPatchSet.
private void reviewPatchSet(PatchSet patchSet) throws Exception {
ReviewInput review = new ReviewInput();
review.message = Strings.emptyToNull(changeComment);
review.tag = Strings.emptyToNull(changeTag);
review.notify = notify;
review.labels = new TreeMap<>();
review.drafts = ReviewInput.DraftHandling.PUBLISH;
for (LabelSetter setter : optionMap.values()) {
setter.getValue().ifPresent(v -> review.labels.put(setter.getLabelName(), v));
}
review.labels.putAll(customLabels);
// We don't need to add the review comment when abandoning/restoring.
if (abandonChange || restoreChange || moveToBranch != null) {
review.message = null;
}
try {
if (abandonChange) {
AbandonInput input = new AbandonInput();
input.message = Strings.emptyToNull(changeComment);
applyReview(patchSet, review);
changeApi(patchSet).abandon(input);
} else if (restoreChange) {
RestoreInput input = new RestoreInput();
input.message = Strings.emptyToNull(changeComment);
changeApi(patchSet).restore(input);
applyReview(patchSet, review);
} else {
applyReview(patchSet, review);
}
if (moveToBranch != null) {
MoveInput moveInput = new MoveInput();
moveInput.destinationBranch = moveToBranch;
moveInput.message = Strings.emptyToNull(changeComment);
changeApi(patchSet).move(moveInput);
}
if (rebaseChange) {
revisionApi(patchSet).rebase();
}
if (submitChange) {
revisionApi(patchSet).submit();
}
} catch (IllegalStateException | RestApiException e) {
throw die(e);
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ReviewCommand method run.
@Override
protected void run() throws UnloggedFailure {
enableGracefulStop();
if (abandonChange) {
if (restoreChange) {
throw die("abandon and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("abandon and submit actions are mutually exclusive");
}
if (rebaseChange) {
throw die("abandon and rebase actions are mutually exclusive");
}
if (moveToBranch != null) {
throw die("abandon and move actions are mutually exclusive");
}
}
if (json) {
if (restoreChange) {
throw die("json and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("json and submit actions are mutually exclusive");
}
if (abandonChange) {
throw die("json and abandon actions are mutually exclusive");
}
if (changeComment != null) {
throw die("json and message are mutually exclusive");
}
if (rebaseChange) {
throw die("json and rebase actions are mutually exclusive");
}
if (moveToBranch != null) {
throw die("json and move actions are mutually exclusive");
}
if (changeTag != null) {
throw die("json and tag actions are mutually exclusive");
}
}
if (rebaseChange) {
if (submitChange) {
throw die("rebase and submit actions are mutually exclusive");
}
}
boolean ok = true;
ReviewInput input = null;
if (json) {
input = reviewFromJson();
}
for (PatchSet patchSet : patchSets) {
try {
if (input != null) {
applyReview(patchSet, input);
} else {
reviewPatchSet(patchSet);
}
} catch (RestApiException | UnloggedFailure e) {
ok = false;
writeError("error", e.getMessage() + "\n");
} catch (NoSuchChangeException e) {
ok = false;
writeError("error", "no such change " + patchSet.id().changeId().get());
} catch (Exception e) {
ok = false;
writeError("fatal", "internal server error while reviewing " + patchSet.id() + "\n");
logger.atSevere().withCause(e).log("internal error while reviewing %s", patchSet.id());
}
}
if (!ok) {
throw die("one or more reviews failed; review output above");
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf.
@Test
public void voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf() throws Exception {
allowRunAs();
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
DraftInput di = new DraftInput();
di.path = Patch.COMMIT_MSG;
di.side = Side.REVISION;
di.line = 1;
di.message = "inline comment";
gApi.changes().id(r.getChangeId()).current().createDraft(di);
requestScopeOperations.setApiUser(admin.id());
// Things that aren't allowed with on_behalf_of:
// - no labels.
// - publish other user's drafts.
ReviewInput in = new ReviewInput();
in.message = "message";
in.drafts = DraftHandling.PUBLISH;
RestResponse res = adminRestSession.postWithHeaders("/changes/" + r.getChangeId() + "/revisions/current/review", in, runAsHeader(user.id()));
res.assertOK();
ChangeMessageInfo m = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
assertThat(m.message).endsWith(in.message);
assertThat(m.author._accountId).isEqualTo(user.id().get());
CommentInfo c = Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).commentsRequest().get().get(di.path));
assertThat(c.author._accountId).isEqualTo(user.id().get());
assertThat(c.message).isEqualTo(di.message);
requestScopeOperations.setApiUser(user.id());
assertThat(gApi.changes().id(r.getChangeId()).drafts()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOf.
@Test
public void voteOnBehalfOf() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = ReviewInput.recommend();
in.onBehalfOf = user.id().toString();
in.message = "Message on behalf of";
revision.review(in);
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.patchSetId().get()).isEqualTo(1);
assertThat(psa.label()).isEqualTo("Code-Review");
assertThat(psa.accountId()).isEqualTo(user.id());
assertThat(psa.value()).isEqualTo(1);
assertThat(psa.realAccountId()).isEqualTo(admin.id());
ChangeData cd = r.getChange();
ChangeMessage m = Iterables.getLast(cmUtil.byChange(cd.notes()));
assertThat(m.getMessage()).endsWith(in.message);
assertThat(m.getAuthor()).isEqualTo(user.id());
assertThat(m.getRealAuthor()).isEqualTo(admin.id());
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ImpersonationIT method testVoteOnBehalfOfWithComment.
private void testVoteOnBehalfOfWithComment() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id().toString();
in.label("Code-Review", 1);
CommentInput ci = new CommentInput();
ci.path = Patch.COMMIT_MSG;
ci.side = Side.REVISION;
ci.line = 1;
ci.message = "message";
in.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
gApi.changes().id(r.getChangeId()).current().review(in);
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.patchSetId().get()).isEqualTo(1);
assertThat(psa.label()).isEqualTo("Code-Review");
assertThat(psa.accountId()).isEqualTo(user.id());
assertThat(psa.value()).isEqualTo(1);
assertThat(psa.realAccountId()).isEqualTo(admin.id());
ChangeData cd = r.getChange();
HumanComment c = Iterables.getOnlyElement(commentsUtil.publishedHumanCommentsByChange(cd.notes()));
assertThat(c.message).isEqualTo(ci.message);
assertThat(c.author.getId()).isEqualTo(user.id());
assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id());
}
Aggregations