Search in sources :

Example 91 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class SubmitByMergeIfNecessaryIT method submitWithOpenAncestorsOnOtherBranch.

@Test
public void submitWithOpenAncestorsOnOtherBranch() throws Exception {
    RevCommit initialHead = getRemoteHead();
    PushOneCommit.Result change1 = createChange(testRepo, "master", "base commit", "a.txt", "1", "");
    submit(change1.getChangeId());
    RevCommit headAfterFirstSubmit = getRemoteHead();
    gApi.projects().name(project.get()).branch("branch").create(new BranchInput());
    PushOneCommit.Result change2 = createChange(testRepo, "master", "We want to commit this to master first", "a.txt", "2", "");
    approve(change2.getChangeId());
    RevCommit tip1 = getRemoteLog(project, "master").get(0);
    assertThat(tip1.getShortMessage()).isEqualTo(change1.getCommit().getShortMessage());
    RevCommit tip2 = getRemoteLog(project, "branch").get(0);
    assertThat(tip2.getShortMessage()).isEqualTo(change1.getCommit().getShortMessage());
    PushOneCommit.Result change3a = createChange(testRepo, "branch", "This commit is based on change2 pending for master, " + "but is targeted itself at branch, which doesn't include it.", "a.txt", "3", "a-topic-here");
    Project.NameKey p3 = createProject("project-related-to-change3");
    TestRepository<?> repo3 = cloneProject(p3);
    RevCommit repo3Head = getRemoteHead(p3, "master");
    PushOneCommit.Result change3b = createChange(repo3, "master", "some accompanying changes for change3a in another repo tied together via topic", "a.txt", "1", "a-topic-here");
    approve(change3b.getChangeId());
    String cnt = isSubmitWholeTopicEnabled() ? "2 changes" : "1 change";
    submitWithConflict(change3a.getChangeId(), "Failed to submit " + cnt + " due to the following problems:\n" + "Change " + change3a.getChange().getId() + ": depends on change that" + " was not submitted");
    RevCommit tipbranch = getRemoteLog(project, "branch").get(0);
    assertThat(tipbranch.getShortMessage()).isEqualTo(change1.getCommit().getShortMessage());
    RevCommit tipmaster = getRemoteLog(p3, "master").get(0);
    assertThat(tipmaster.getShortMessage()).isEqualTo(repo3Head.getShortMessage());
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change1.getChangeId(), headAfterFirstSubmit.name());
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 92 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class SubmitByMergeIfNecessaryIT method submitChangesAcrossRepos.

@Test
public void submitChangesAcrossRepos() throws Exception {
    Project.NameKey p1 = createProject("project-where-we-submit");
    Project.NameKey p2 = createProject("project-impacted-via-topic");
    Project.NameKey p3 = createProject("project-impacted-indirectly-via-topic");
    RevCommit initialHead2 = getRemoteHead(p2, "master");
    RevCommit initialHead3 = getRemoteHead(p3, "master");
    TestRepository<?> repo1 = cloneProject(p1);
    TestRepository<?> repo2 = cloneProject(p2);
    TestRepository<?> repo3 = cloneProject(p3);
    PushOneCommit.Result change1a = createChange(repo1, "master", "An ancestor of the change we want to submit", "a.txt", "1", "dependent-topic");
    PushOneCommit.Result change1b = createChange(repo1, "master", "We're interested in submitting this change", "a.txt", "2", "topic-to-submit");
    PushOneCommit.Result change2a = createChange(repo2, "master", "indirection level 1", "a.txt", "1", "topic-indirect");
    PushOneCommit.Result change2b = createChange(repo2, "master", "should go in with first change", "a.txt", "2", "dependent-topic");
    PushOneCommit.Result change3 = createChange(repo3, "master", "indirection level 2", "a.txt", "1", "topic-indirect");
    approve(change1a.getChangeId());
    approve(change2a.getChangeId());
    approve(change2b.getChangeId());
    approve(change3.getChangeId());
    // get a preview before submitting:
    Map<Branch.NameKey, ObjectId> preview = fetchFromSubmitPreview(change1b.getChangeId());
    submit(change1b.getChangeId());
    RevCommit tip1 = getRemoteLog(p1, "master").get(0);
    RevCommit tip2 = getRemoteLog(p2, "master").get(0);
    RevCommit tip3 = getRemoteLog(p3, "master").get(0);
    assertThat(tip1.getShortMessage()).isEqualTo(change1b.getCommit().getShortMessage());
    if (isSubmitWholeTopicEnabled()) {
        assertThat(tip2.getShortMessage()).isEqualTo(change2b.getCommit().getShortMessage());
        assertThat(tip3.getShortMessage()).isEqualTo(change3.getCommit().getShortMessage());
        // check that the preview matched what happened:
        assertThat(preview).hasSize(3);
        assertThat(preview).containsKey(new Branch.NameKey(p1, "refs/heads/master"));
        assertTrees(p1, preview);
        assertThat(preview).containsKey(new Branch.NameKey(p2, "refs/heads/master"));
        assertTrees(p2, preview);
        assertThat(preview).containsKey(new Branch.NameKey(p3, "refs/heads/master"));
        assertTrees(p3, preview);
    } else {
        assertThat(tip2.getShortMessage()).isEqualTo(initialHead2.getShortMessage());
        assertThat(tip3.getShortMessage()).isEqualTo(initialHead3.getShortMessage());
        assertThat(preview).hasSize(1);
        assertThat(preview.get(new Branch.NameKey(p1, "refs/heads/master"))).isNotNull();
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ObjectId(org.eclipse.jgit.lib.ObjectId) Branch(com.google.gerrit.reviewdb.client.Branch) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 93 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class SuggestReviewersIT method reviewerRankingProjectIsolation.

@Test
public void reviewerRankingProjectIsolation() throws Exception {
    // Create new project
    Project.NameKey newProject = createProject("test");
    // Create users who review changes in both the default and the new project
    String fullName = "Primum Finalis";
    TestAccount userWhoOwns = user("customuser1", fullName);
    TestAccount reviewer1 = user("customuser2", fullName);
    TestAccount reviewer2 = user("customuser3", fullName);
    setApiUser(userWhoOwns);
    String changeId1 = createChangeFromApi();
    setApiUser(reviewer1);
    reviewChange(changeId1);
    setApiUser(userWhoOwns);
    String changeId2 = createChangeFromApi(newProject);
    setApiUser(reviewer2);
    reviewChange(changeId2);
    setApiUser(userWhoOwns);
    String changeId3 = createChangeFromApi(newProject);
    setApiUser(reviewer2);
    reviewChange(changeId3);
    setApiUser(userWhoOwns);
    List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChangeFromApi(), "Prim", 4);
    // Assert that reviewer1 is on top, even though reviewer2 has more reviews
    // in other projects
    assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get()).inOrder();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 94 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ProjectAssert method assertThatNameList.

public static IterableSubject assertThatNameList(Iterable<ProjectInfo> actualIt) {
    List<ProjectInfo> actual = ImmutableList.copyOf(actualIt);
    for (ProjectInfo info : actual) {
        assertWithMessage("missing project name").that(info.name).isNotNull();
        assertWithMessage("project name does not match id").that(Url.decode(info.id)).isEqualTo(info.name);
    }
    return assertThat(Iterables.transform(actual, p -> new Project.NameKey(p.name)));
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Iterables(com.google.common.collect.Iterables) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ProjectState(com.google.gerrit.server.project.ProjectState) Set(java.util.Set) Truth.assertThat(com.google.common.truth.Truth.assertThat) Strings(com.google.common.base.Strings) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IterableSubject(com.google.common.truth.IterableSubject) Url(com.google.gerrit.extensions.restapi.Url) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo)

Example 95 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ProjectLevelConfigIT method withInheritance.

@Test
public void withInheritance() throws Exception {
    String configName = "test.config";
    Config parentCfg = new Config();
    parentCfg.setString("s1", null, "k1", "parentValue1");
    parentCfg.setString("s1", null, "k2", "parentValue2");
    parentCfg.setString("s2", "ss", "k3", "parentValue3");
    parentCfg.setString("s2", "ss", "k4", "parentValue4");
    pushFactory.create(db, admin.getIdent(), testRepo, "Create Project Level Config", configName, parentCfg.toText()).to(RefNames.REFS_CONFIG).assertOkStatus();
    Project.NameKey childProject = createProject("child", project);
    TestRepository<?> childTestRepo = cloneProject(childProject);
    fetch(childTestRepo, RefNames.REFS_CONFIG + ":refs/heads/config");
    childTestRepo.reset("refs/heads/config");
    Config cfg = new Config();
    cfg.setString("s1", null, "k1", "childValue1");
    cfg.setString("s2", "ss", "k3", "childValue2");
    pushFactory.create(db, admin.getIdent(), childTestRepo, "Create Project Level Config", configName, cfg.toText()).to(RefNames.REFS_CONFIG).assertOkStatus();
    ProjectState state = projectCache.get(childProject);
    Config expectedCfg = new Config();
    expectedCfg.setString("s1", null, "k1", "childValue1");
    expectedCfg.setString("s1", null, "k2", "parentValue2");
    expectedCfg.setString("s2", "ss", "k3", "childValue2");
    expectedCfg.setString("s2", "ss", "k4", "parentValue4");
    assertThat(state.getConfig(configName).getWithInheritance().toText()).isEqualTo(expectedCfg.toText());
    assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Config(org.eclipse.jgit.lib.Config) ProjectState(com.google.gerrit.server.project.ProjectState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Project (com.google.gerrit.reviewdb.client.Project)145 Test (org.junit.Test)73 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)47 Change (com.google.gerrit.reviewdb.client.Change)32 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)29 Branch (com.google.gerrit.reviewdb.client.Branch)25 Account (com.google.gerrit.reviewdb.client.Account)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 Config (org.eclipse.jgit.lib.Config)20 Repository (org.eclipse.jgit.lib.Repository)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)20 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)19 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)17 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)16 IOException (java.io.IOException)16 ObjectId (org.eclipse.jgit.lib.ObjectId)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)15 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)14 SubmoduleSectionParser (com.google.gerrit.server.util.SubmoduleSectionParser)14