Search in sources :

Example 1 with PublishChangeEditInput

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();
}
Also used : ChangeEdit(com.google.gerrit.server.edit.ChangeEdit) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput)

Example 2 with PublishChangeEditInput

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();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with PublishChangeEditInput

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();
}
Also used : PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with PublishChangeEditInput

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);
}
Also used : ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelType(com.google.gerrit.entities.LabelType) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with PublishChangeEditInput

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."));
}
Also used : FileContentInput(com.google.gerrit.extensions.api.changes.FileContentInput) RawInput(com.google.gerrit.extensions.restapi.RawInput) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) RestResponse(com.google.gerrit.acceptance.RestResponse) EditMessage(com.google.gerrit.server.restapi.change.ChangeEdits.EditMessage) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PublishChangeEditInput (com.google.gerrit.extensions.api.changes.PublishChangeEditInput)9 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 Test (org.junit.Test)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)3 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)2 RestResponse (com.google.gerrit.acceptance.RestResponse)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 LabelType (com.google.gerrit.entities.LabelType)1 FileContentInput (com.google.gerrit.extensions.api.changes.FileContentInput)1 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)1 RawInput (com.google.gerrit.extensions.restapi.RawInput)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ChangeEdit (com.google.gerrit.server.edit.ChangeEdit)1 EditMessage (com.google.gerrit.server.restapi.change.ChangeEdits.EditMessage)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1 TestRepository (org.eclipse.jgit.junit.TestRepository)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1