Search in sources :

Example 6 with Workflow

use of com.google.copybara.Workflow in project copybara by google.

the class GitOriginTest method autoDetectBranchAtGitOrigin.

@Test
public void autoDetectBranchAtGitOrigin() throws Exception {
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
    git("add", "include/fileA.txt");
    git("commit", "-m", "not include");
    defaultBranch = repo.getPrimaryBranch(url);
    git("checkout", defaultBranch);
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
    git("add", "include/mainline-file.txt");
    git("commit", "-m", "message_a!");
    options.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + // Intentionally pick the "wrong" ref.
    "         ref = '" + (defaultBranch.equals("master") ? "main" : "master") + "',\n" + "         url = '" + url + "',\n" + "         primary_branch_migration = True,\n" + "    ),\n" + "    origin_files = glob(['include/mainline-file.txt']),\n" + "    destination = testing.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
    List<ProcessedChange> changes = destination.processed;
    assertThat(changes).hasSize(1);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 7 with Workflow

use of com.google.copybara.Workflow in project copybara by google.

the class GitOriginTest method branchCommitLogsOnlyCoverIncludedOriginFileRoots.

@SuppressWarnings("unchecked")
@Test
public void branchCommitLogsOnlyCoverIncludedOriginFileRoots() throws Exception {
    String excludedMessage = "i hope this IS NOT included in the migrated message!";
    // Make two commits on 'the-branch' branch, one being in an excluded directory, the other
    // included.
    git("checkout", "-b", "the-branch");
    Files.write(remote.resolve("branch-file.txt"), new byte[0]);
    git("add", "branch-file.txt");
    git("commit", "-m", excludedMessage);
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/branch-file.txt"), new byte[0]);
    git("add", "include/branch-file.txt");
    git("commit", "-m", "i hope this is included@@@");
    git("checkout", defaultBranch);
    // Make a commit on mainline so that Git doesn't turn this into a fast-forward.
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
    git("add", "include/mainline-file.txt");
    git("commit", "-m", "mainline message!");
    git("merge", "the-branch");
    options.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "    ),\n" + "    origin_files = glob(['include/**']),\n" + "    destination = testing.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
    List<ProcessedChange> changes = destination.processed;
    assertThat(changes).hasSize(2);
    assertThat(changes.get(0).getChangesSummary()).contains("mainline message!");
    assertThat(changes.get(1).getChangesSummary()).doesNotContain(excludedMessage);
    assertThat(changes.get(1).getChangesSummary()).contains("i hope this is included@@@");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 8 with Workflow

use of com.google.copybara.Workflow in project copybara by google.

the class MetadataModuleTest method createWorkflow.

private Workflow<?, ?> createWorkflow(WorkflowMode mode, String... transforms) throws IOException, ValidationException {
    passThruAuthoring();
    Config config = loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin =  testing.origin(),\n" + "    authoring = " + authoring + "\n," + "    destination = testing.destination(),\n" + "    mode = '" + mode + "',\n" + "    transformations = [" + Joiner.on(", ").join(transforms) + "]\n" + ")\n");
    return (Workflow) config.getMigration("default");
}
Also used : Config(com.google.copybara.config.Config) Workflow(com.google.copybara.Workflow)

Aggregations

Workflow (com.google.copybara.Workflow)8 Revision (com.google.copybara.Revision)6 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)6 Test (org.junit.Test)6 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)4 Author (com.google.copybara.authoring.Author)1 Config (com.google.copybara.config.Config)1 ValidationException (com.google.copybara.exception.ValidationException)1