use of com.google.gerrit.extensions.api.changes.PublishChangeEditInput in project gerrit by GerritCodeReview.
the class PublishChangeEdit method apply.
@Override
public Response<Object> apply(ChangeResource rsrc, PublishChangeEditInput in) throws IOException, RestApiException, UpdateException, ConfigInvalidException, NoSuchProjectException {
contributorAgreementsChecker.check(rsrc.getProject(), rsrc.getUser());
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getNotes(), rsrc.getUser());
if (!edit.isPresent()) {
throw new ResourceConflictException(String.format("no edit exists for change %s", rsrc.getChange().getChangeId()));
}
if (in == null) {
in = new PublishChangeEditInput();
}
editUtil.publish(updateFactory, rsrc.getNotes(), rsrc.getUser(), edit.get(), notifyResolver.resolve(firstNonNull(in.notify, NotifyHandling.ALL), in.notifyDetails));
return Response.none();
}
use of com.google.gerrit.extensions.api.changes.PublishChangeEditInput in project gerrit by GerritCodeReview.
the class ChangeEditIT method publishEdit.
@Test
public void publishEdit() throws Exception {
createArbitraryEditFor(changeId);
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
gApi.changes().id(changeId).addReviewer(in);
PublishChangeEditInput publishInput = new PublishChangeEditInput();
gApi.changes().id(changeId).edit().publish(publishInput);
assertThat(getEdit(changeId)).isAbsent();
assertChangeMessages(changeId, ImmutableList.of("Uploaded patch set 1.", "Uploaded patch set 2.", "Patch Set 3: Published edit on patch set 2."));
// The tag for the publish edit change message should vary according
// to whether the change was WIP at the time of publishing.
ChangeInfo info = get(changeId, MESSAGES);
assertThat(info.messages).isNotEmpty();
assertThat(Iterables.getLast(info.messages).tag).isEqualTo(ChangeMessagesUtil.TAG_UPLOADED_PATCH_SET);
assertThat(sender.getMessages()).isNotEmpty();
// Move the change to WIP, repeat, and verify.
sender.clear();
gApi.changes().id(changeId).setWorkInProgress();
createEmptyEditFor(changeId);
gApi.changes().id(changeId).edit().modifyFile(FILE_NAME, RawInputUtil.create(CONTENT_NEW2));
gApi.changes().id(changeId).edit().publish();
info = get(changeId, MESSAGES);
assertThat(info.messages).isNotEmpty();
assertThat(Iterables.getLast(info.messages).tag).isEqualTo(ChangeMessagesUtil.TAG_UPLOADED_WIP_PATCH_SET);
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.PublishChangeEditInput in project gerrit by GerritCodeReview.
the class ChangeEditIT method publishEditNotifyRest.
@Test
public void publishEditNotifyRest() throws Exception {
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
gApi.changes().id(changeId).addReviewer(in);
createArbitraryEditFor(changeId);
sender.clear();
PublishChangeEditInput input = new PublishChangeEditInput();
input.notify = NotifyHandling.NONE;
adminRestSession.post(urlPublish(changeId), input).assertNoContent();
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.PublishChangeEditInput in project gerrit by GerritCodeReview.
the class ChangeEditIT method editCommitMessageCopiesLabelScores.
@Test
public void editCommitMessageCopiesLabelScores() throws Exception {
String cr = LabelId.CODE_REVIEW;
try (ProjectConfigUpdate u = updateProject(project)) {
LabelType codeReview = TestLabels.codeReview();
u.getConfig().upsertLabelType(codeReview);
u.getConfig().updateLabelType(codeReview.getName(), lt -> lt.setCopyAllScoresIfNoCodeChange(true));
u.save();
}
ReviewInput r = new ReviewInput();
r.labels = ImmutableMap.of(cr, (short) 1);
gApi.changes().id(changeId).current().review(r);
createEmptyEditFor(changeId);
String newSubj = "New commit message";
String newMsg = newSubj + "\n\nChange-Id: " + changeId + "\n";
gApi.changes().id(changeId).edit().modifyCommitMessage(newMsg);
PublishChangeEditInput publishInput = new PublishChangeEditInput();
publishInput.notify = NotifyHandling.NONE;
gApi.changes().id(changeId).edit().publish(publishInput);
ChangeInfo info = get(changeId, DETAILED_LABELS);
assertThat(info.subject).isEqualTo(newSubj);
List<ApprovalInfo> approvals = info.labels.get(cr).all;
assertThat(approvals).hasSize(1);
assertThat(approvals.get(0).value).isEqualTo(1);
}
use of com.google.gerrit.extensions.api.changes.PublishChangeEditInput in project gerrit by GerritCodeReview.
the class ChangeEditIT method updateMessageRest.
@Test
public void updateMessageRest() throws Exception {
adminRestSession.get(urlEditMessage(changeId, false)).assertNotFound();
EditMessage.Input in = new EditMessage.Input();
in.message = String.format("New commit message\n\n" + CONTENT_NEW2_STR + "\n\nChange-Id: %s\n", changeId);
adminRestSession.put(urlEditMessage(changeId, false), in).assertNoContent();
RestResponse r = adminRestSession.getJsonAccept(urlEditMessage(changeId, false));
r.assertOK();
assertThat(readContentFromJson(r)).isEqualTo(in.message);
String commitMessage = gApi.changes().id(changeId).edit().getCommitMessage();
assertThat(commitMessage).isEqualTo(in.message);
in.message = String.format("New commit message2\n\nChange-Id: %s\n", changeId);
adminRestSession.put(urlEditMessage(changeId, false), in).assertNoContent();
String updatedCommitMessage = gApi.changes().id(changeId).edit().getCommitMessage();
assertThat(updatedCommitMessage).isEqualTo(in.message);
r = adminRestSession.getJsonAccept(urlEditMessage(changeId, true));
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(ObjectId.fromString(ps.commitId().name()));
assertThat(readContentFromJson(r)).isEqualTo(commit.getFullMessage());
}
PublishChangeEditInput publishInput = new PublishChangeEditInput();
publishInput.notify = NotifyHandling.NONE;
gApi.changes().id(changeId).edit().publish(publishInput);
assertChangeMessages(changeId, ImmutableList.of("Uploaded patch set 1.", "Uploaded patch set 2.", "Patch Set 3: Commit message was updated."));
}
Aggregations