Search in sources :

Example 6 with CheckProjectResultInfo

use of com.google.gerrit.extensions.api.projects.CheckProjectResultInfo in project gerrit by GerritCodeReview.

the class CheckProjectIT method fixAutoCloseableChangeByCommit.

@Test
public void fixAutoCloseableChangeByCommit() throws Exception {
    RevCommit commit = pushCommitWithoutChangeIdForReview();
    ChangeInfo change = Iterables.getOnlyElement(gApi.changes().query("commit:" + commit.name()).get());
    String branch = "refs/heads/master";
    serverSideTestRepo.branch(branch).update(commit);
    ChangeInfo info = gApi.changes().id(change._number).info();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    CheckProjectInput input = checkProjectInputForAutoCloseableCheck(branch);
    input.autoCloseableChangesCheck.fix = true;
    CheckProjectResultInfo checkResult = gApi.projects().name(project.get()).check(input);
    assertThat(checkResult.autoCloseableChangesCheckResult.autoCloseableChanges.stream().map(i -> i._number).collect(toSet())).containsExactly(change._number);
    info = gApi.changes().id(change._number).info();
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
}
Also used : GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) Iterables(com.google.common.collect.Iterables) TestRepository(org.eclipse.jgit.junit.TestRepository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) Test(org.junit.Test) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Truth.assertThat(com.google.common.truth.Truth.assertThat) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PersonIdent(org.eclipse.jgit.lib.PersonIdent) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ProjectsConsistencyChecker(com.google.gerrit.server.project.ProjectsConsistencyChecker) Collectors.toList(java.util.stream.Collectors.toList) CheckProjectResultInfo(com.google.gerrit.extensions.api.projects.CheckProjectResultInfo) CheckProjectInput(com.google.gerrit.extensions.api.projects.CheckProjectInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) AutoCloseableChangesCheckInput(com.google.gerrit.extensions.api.projects.CheckProjectInput.AutoCloseableChangesCheckInput) Collectors.toSet(java.util.stream.Collectors.toSet) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) Before(org.junit.Before) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CheckProjectResultInfo(com.google.gerrit.extensions.api.projects.CheckProjectResultInfo) CheckProjectInput(com.google.gerrit.extensions.api.projects.CheckProjectInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with CheckProjectResultInfo

use of com.google.gerrit.extensions.api.projects.CheckProjectResultInfo in project gerrit by GerritCodeReview.

the class CheckProjectIT method skipCommits.

@Test
public void skipCommits() throws Exception {
    PushOneCommit.Result r = createChange("refs/for/master");
    String branch = r.getChange().change().getDest().branch();
    RevCommit amendedCommit = serverSideTestRepo.amend(r.getCommit()).create();
    serverSideTestRepo.branch(branch).update(amendedCommit);
    serverSideTestRepo.commit(amendedCommit);
    ChangeInfo info = change(r).info();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    CheckProjectInput input = checkProjectInputForAutoCloseableCheck(branch);
    input.autoCloseableChangesCheck.fix = true;
    input.autoCloseableChangesCheck.maxCommits = 1;
    CheckProjectResultInfo checkResult = gApi.projects().name(project.get()).check(input);
    assertThat(checkResult.autoCloseableChangesCheckResult.autoCloseableChanges).isEmpty();
    info = change(r).info();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    input.autoCloseableChangesCheck.skipCommits = 1;
    checkResult = gApi.projects().name(project.get()).check(input);
    assertThat(checkResult.autoCloseableChangesCheckResult.autoCloseableChanges.stream().map(i -> i._number).collect(toSet())).containsExactly(r.getChange().getId().get());
    info = change(r).info();
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
}
Also used : GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) Iterables(com.google.common.collect.Iterables) TestRepository(org.eclipse.jgit.junit.TestRepository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) Test(org.junit.Test) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Truth.assertThat(com.google.common.truth.Truth.assertThat) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PersonIdent(org.eclipse.jgit.lib.PersonIdent) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ProjectsConsistencyChecker(com.google.gerrit.server.project.ProjectsConsistencyChecker) Collectors.toList(java.util.stream.Collectors.toList) CheckProjectResultInfo(com.google.gerrit.extensions.api.projects.CheckProjectResultInfo) CheckProjectInput(com.google.gerrit.extensions.api.projects.CheckProjectInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) AutoCloseableChangesCheckInput(com.google.gerrit.extensions.api.projects.CheckProjectInput.AutoCloseableChangesCheckInput) Collectors.toSet(java.util.stream.Collectors.toSet) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) Before(org.junit.Before) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CheckProjectResultInfo(com.google.gerrit.extensions.api.projects.CheckProjectResultInfo) CheckProjectInput(com.google.gerrit.extensions.api.projects.CheckProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 CheckProjectResultInfo (com.google.gerrit.extensions.api.projects.CheckProjectResultInfo)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)7 Test (org.junit.Test)7 Iterables (com.google.common.collect.Iterables)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 GitUtil.pushHead (com.google.gerrit.acceptance.GitUtil.pushHead)6 CheckProjectInput (com.google.gerrit.extensions.api.projects.CheckProjectInput)6 AutoCloseableChangesCheckInput (com.google.gerrit.extensions.api.projects.CheckProjectInput.AutoCloseableChangesCheckInput)6 ChangeStatus (com.google.gerrit.extensions.client.ChangeStatus)6 InheritableBoolean (com.google.gerrit.extensions.client.InheritableBoolean)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)6 ProjectsConsistencyChecker (com.google.gerrit.server.project.ProjectsConsistencyChecker)6 GerritJUnit.assertThrows (com.google.gerrit.testing.GerritJUnit.assertThrows)6 Collectors.toList (java.util.stream.Collectors.toList)6 Collectors.toSet (java.util.stream.Collectors.toSet)6 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)6 TestRepository (org.eclipse.jgit.junit.TestRepository)6