Search in sources :

Example 96 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class ChangeEditIT method editCannotBeCreatedOnMergedChange.

@Test
public void editCannotBeCreatedOnMergedChange() throws Exception {
    ChangeInfo change = gApi.changes().id(changeId).get();
    gApi.changes().id(changeId).current().review(ReviewInput.approve());
    gApi.changes().id(changeId).current().submit();
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> createArbitraryEditFor(changeId));
    assertThat(thrown).hasMessageThat().contains(String.format("change %s is merged", change._number));
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 97 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class ChangeEditIT method retrieveEdit.

@Test
public void retrieveEdit() throws Exception {
    adminRestSession.get(urlEdit(changeId)).assertNoContent();
    createArbitraryEditFor(changeId);
    Optional<EditInfo> maybeEditInfo = gApi.changes().id(changeId).edit().get();
    assertThat(maybeEditInfo).isPresent();
    EditInfo editInfo = maybeEditInfo.get();
    ChangeInfo changeInfo = get(changeId, CURRENT_REVISION, CURRENT_COMMIT);
    assertThat(editInfo.commit.commit).isNotEqualTo(changeInfo.currentRevision);
    assertThat(editInfo).commit().parents().hasSize(1);
    assertThat(editInfo).baseRevision().isEqualTo(changeInfo.currentRevision);
    gApi.changes().id(changeId).edit().delete();
    adminRestSession.get(urlEdit(changeId)).assertNoContent();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) EditInfo(com.google.gerrit.extensions.common.EditInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 98 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo 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 99 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class ChangeEditIT method assertChangeMessages.

private void assertChangeMessages(String changeId, List<String> expectedMessages) throws Exception {
    ChangeInfo ci = get(changeId, MESSAGES);
    assertThat(ci.messages).isNotNull();
    assertThat(ci.messages).hasSize(expectedMessages.size());
    List<String> actualMessages = ci.messages.stream().map(message -> message.message).collect(toList());
    assertThat(actualMessages).containsExactlyElementsIn(expectedMessages).inOrder();
}
Also used : Patch(com.google.gerrit.entities.Patch) TypeToken(com.google.gson.reflect.TypeToken) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) FileContentInput(com.google.gerrit.extensions.api.changes.FileContentInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) LabelType(com.google.gerrit.entities.LabelType) ChangeEditDetailOption(com.google.gerrit.extensions.client.ChangeEditDetailOption) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) Post(com.google.gerrit.server.restapi.change.ChangeEdits.Post) RawInput(com.google.gerrit.extensions.restapi.RawInput) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) UseClockStep(com.google.gerrit.acceptance.UseClockStep) List(java.util.List) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) EditInfo(com.google.gerrit.extensions.common.EditInfo) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) Iterables(com.google.common.collect.Iterables) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) RawInputUtil(com.google.gerrit.common.RawInputUtil) EditMessage(com.google.gerrit.server.restapi.change.ChangeEdits.EditMessage) BinaryResultSubject.assertThat(com.google.gerrit.extensions.restapi.testing.BinaryResultSubject.assertThat) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) TestLabels(com.google.gerrit.server.project.testing.TestLabels) JsonReader(com.google.gson.stream.JsonReader) CURRENT_COMMIT(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) FileInfo(com.google.gerrit.extensions.common.FileInfo) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) Before(org.junit.Before) TestRepository(org.eclipse.jgit.junit.TestRepository) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Permission(com.google.gerrit.entities.Permission) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) Collectors.toList(java.util.stream.Collectors.toList) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Project(com.google.gerrit.entities.Project) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.EditInfoSubject.assertThat) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) Repository(org.eclipse.jgit.lib.Repository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo)

Example 100 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickWithoutMessage.

@Test
public void cherryPickWithoutMessage() throws Exception {
    String branch = "foo";
    // Create change to cherry-pick
    PushOneCommit.Result change = createChange();
    RevCommit revCommit = change.getCommit();
    // Create target branch to cherry-pick to.
    gApi.projects().name(project.get()).branch(branch).create(new BranchInput());
    // Cherry-pick without message.
    CherryPickInput input = new CherryPickInput();
    input.destination = branch;
    String changeId = gApi.changes().id(change.getChangeId()).revision(revCommit.name()).cherryPickAsInfo(input).id;
    // Expect that the message of the cherry-picked commit was used for the cherry-pick change.
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
    assertThat(revInfo).isNotNull();
    assertThat(revInfo.commit.message).isEqualTo(revCommit.getFullMessage());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)504 Test (org.junit.Test)434 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)393 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)276 Change (com.google.gerrit.entities.Change)73 RevCommit (org.eclipse.jgit.revwalk.RevCommit)67 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)52 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)50 Project (com.google.gerrit.entities.Project)45 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)45 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)36 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)36 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)35 Repository (org.eclipse.jgit.lib.Repository)35 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)32 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)32 TestRepository (org.eclipse.jgit.junit.TestRepository)32 ObjectId (org.eclipse.jgit.lib.ObjectId)30 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)29 List (java.util.List)29