Search in sources :

Example 51 with ChangeInfo

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

the class StickyApprovalsIT method notStickyWithCopyAllScoresIfListOfFilesDidNotChangeWhenFileIsRenamed.

private void notStickyWithCopyAllScoresIfListOfFilesDidNotChangeWhenFileIsRenamed() throws Exception {
    Change.Id changeId = changeOperations.newChange().project(project).file("file").content("content").create();
    vote(admin, changeId.toString(), 2, 1);
    vote(user, changeId.toString(), -2, -1);
    changeOperations.change(changeId).newPatchset().file("file").renameTo("new_file").create();
    ChangeInfo c = detailedChange(changeId.toString());
    // no votes are copied since the list of files changed (rename).
    assertVotes(c, admin, 0, 0);
    assertVotes(c, user, 0, 0);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change)

Example 52 with ChangeInfo

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

the class StickyApprovalsIT method stickyWhenCopyConditionIsTrue.

@Test
public void stickyWhenCopyConditionIsTrue() throws Exception {
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(LabelId.CODE_REVIEW, b -> b.setCopyCondition("is:ANY"));
        u.save();
    }
    for (ChangeKind changeKind : EnumSet.of(REWORK, TRIVIAL_REBASE, NO_CODE_CHANGE, MERGE_FIRST_PARENT_UPDATE, NO_CHANGE)) {
        testRepo.reset(projectOperations.project(project).getHead("master"));
        String changeId = changeKindCreator.createChange(changeKind, testRepo, admin);
        vote(admin, changeId, 2, 1);
        vote(user, changeId, 1, -1);
        changeKindCreator.updateChange(changeId, changeKind, testRepo, admin, project);
        ChangeInfo c = detailedChange(changeId);
        assertVotes(c, admin, 2, 0, changeKind);
        assertVotes(c, user, 1, 0, changeKind);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 53 with ChangeInfo

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

the class StickyApprovalsIT method stickyAcrossMultiplePatchSets.

@Test
public void stickyAcrossMultiplePatchSets() throws Exception {
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(LabelId.CODE_REVIEW, b -> b.setCopyMaxScore(true));
        u.getConfig().updateLabelType(LabelId.VERIFIED, b -> b.setCopyAllScoresIfNoCodeChange(true));
        u.save();
    }
    String changeId = changeKindCreator.createChange(REWORK, testRepo, admin);
    vote(admin, changeId, 2, 1);
    for (int i = 0; i < 5; i++) {
        changeKindCreator.updateChange(changeId, NO_CODE_CHANGE, testRepo, admin, project);
        ChangeInfo c = detailedChange(changeId);
        assertVotes(c, admin, 2, 1, NO_CODE_CHANGE);
    }
    changeKindCreator.updateChange(changeId, REWORK, testRepo, admin, project);
    ChangeInfo c = detailedChange(changeId);
    assertVotes(c, admin, 2, 0, REWORK);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 54 with ChangeInfo

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

the class AbandonIT method batchAbandon.

@Test
public void batchAbandon() throws Exception {
    CurrentUser user = atrScope.get().getUser();
    PushOneCommit.Result a = createChange();
    PushOneCommit.Result b = createChange();
    List<ChangeData> list = ImmutableList.of(a.getChange(), b.getChange());
    batchAbandon.batchAbandon(batchUpdateFactory, a.getChange().project(), user, list, "deadbeef");
    ChangeInfo info = get(a.getChangeId(), MESSAGES);
    assertThat(info.status).isEqualTo(ChangeStatus.ABANDONED);
    assertThat(Iterables.getLast(info.messages).message.toLowerCase()).contains("abandoned");
    assertThat(Iterables.getLast(info.messages).message.toLowerCase()).contains("deadbeef");
    info = get(b.getChangeId(), MESSAGES);
    assertThat(info.status).isEqualTo(ChangeStatus.ABANDONED);
    assertThat(Iterables.getLast(info.messages).message.toLowerCase()).contains("abandoned");
    assertThat(Iterables.getLast(info.messages).message.toLowerCase()).contains("deadbeef");
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 55 with ChangeInfo

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

the class ChangeReviewersIT method addCcGroup.

@Test
public void addCcGroup() throws Exception {
    List<TestAccount> users = createAccounts(6, "addCcGroup");
    List<String> usernames = new ArrayList<>(6);
    for (TestAccount u : users) {
        usernames.add(u.username());
    }
    List<TestAccount> firstUsers = users.subList(0, 3);
    List<String> firstUsernames = usernames.subList(0, 3);
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = groupOperations.newGroup().name("cc1").create().get();
    in.state = CC;
    gApi.groups().id(in.reviewer).addMembers(firstUsernames.toArray(new String[firstUsernames.size()]));
    ReviewerResult result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(in.reviewer);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    assertThat(result.reviewers).isNull();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, CC, firstUsers);
    // Verify emails were sent to each of the group's accounts.
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    List<Address> expectedAddresses = new ArrayList<>(firstUsers.size());
    for (TestAccount u : firstUsers) {
        expectedAddresses.add(u.getNameEmail());
    }
    assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
    // CC a group that overlaps with some existing reviewers and CCed accounts.
    TestAccount reviewer = accountCreator.create(name("reviewer"), "addCcGroup-reviewer@example.com", "Reviewer", null);
    result = addReviewer(changeId, reviewer.username());
    assertThat(result.error).isNull();
    sender.clear();
    in.reviewer = groupOperations.newGroup().name("cc2").create().get();
    gApi.groups().id(in.reviewer).addMembers(usernames.toArray(new String[usernames.size()]));
    gApi.groups().id(in.reviewer).addMembers(reviewer.username());
    result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(in.reviewer);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(result.ccs).hasSize(3);
    assertThat(result.reviewers).isNull();
    assertReviewers(c, REVIEWER, reviewer);
    assertReviewers(c, CC, users);
    messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    m = messages.get(0);
    expectedAddresses = new ArrayList<>(4);
    for (int i = 0; i < 3; i++) {
        expectedAddresses.add(users.get(users.size() - i - 1).getNameEmail());
    }
    expectedAddresses.add(reviewer.getNameEmail());
    assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) Address(com.google.gerrit.entities.Address) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) ArrayList(java.util.ArrayList) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) 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