use of com.google.copybara.config.Config in project copybara by google.
the class MigrateCmd method run.
/**
* Runs the migration specified by {@code migrationName}.
*/
private void run(Options options, ConfigLoader configLoader, String migrationName, Path workdir, ImmutableList<String> sourceRefs) throws RepoException, ValidationException, IOException {
Config config = loadConfig(options, configLoader, migrationName);
Migration migration = config.getMigration(migrationName);
if (!options.get(WorkflowOptions.class).isReadConfigFromChange()) {
this.migrationRanConsumer.accept(migration);
migration.run(workdir, sourceRefs);
return;
}
checkCondition(configLoader.supportsLoadForRevision(), "%s flag is not supported for the origin/config file path", WorkflowOptions.READ_CONFIG_FROM_CHANGE);
// A safeguard, mirror workflows are not supported in the service anyway
checkCondition(migration instanceof Workflow, "Flag --read-config-from-change is not supported for non-workflow migrations: %s", migrationName);
migrationRanConsumer.accept(migration);
Workflow<? extends Revision, ? extends Revision> workflow = (Workflow<? extends Revision, ? extends Revision>) migration;
new ReadConfigFromChangeWorkflow<>(workflow, options, configLoader, configValidator).run(workdir, sourceRefs);
}
use of com.google.copybara.config.Config in project copybara by google.
the class InfoTest method testInfoAvailableToMigrate.
@Test
public void testInfoAvailableToMigrate() throws Exception {
info = new InfoCmd((configPath, sourceRef) -> new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configInfo), optionsBuilder.general.getStarlarkMode()) {
@Override
public Config load(Console console) {
return config;
}
@Override
public ConfigWithDependencies loadWithDependencies(Console console) {
return configWithDeps;
}
}, getFakeContextProvider());
MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of(newChange("2222", "First change", ZonedDateTime.ofInstant(Instant.ofEpochSecond(1541631979), ZoneId.of("-08:00"))), newChange("3333", "Second change", ZonedDateTime.ofInstant(Instant.ofEpochSecond(1541639979), ZoneId.of("-08:00")))));
Info<?> mockedInfo = Info.create(dummyOriginDescription, dummyDestinationDescription, ImmutableList.of(workflow));
Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
// Copybara copybara = new Copybara(new ConfigValidator() {}, migration -> {});
// copybara.info(optionsBuilder.build(), config, "workflow");
info.run(new CommandEnv(temp, optionsBuilder.build(), ImmutableList.of("copy.bara.sky", "workflow")));
assertThat(eventMonitor.infoFinishedEvent).isNotNull();
assertThat(eventMonitor.infoFinishedEvent.getInfo()).isEqualTo(mockedInfo);
console.assertThat().onceInLog(MessageType.INFO, ".*last_migrated 1111 - last_available 3333.*").onceInLog(MessageType.INFO, ".*Date.*Revision.*Description.*Author.*").onceInLog(MessageType.INFO, ".*2018-11-07 15:06:19.*2222.*First change.*Foo <Bar>.*").onceInLog(MessageType.INFO, ".*2018-11-07 17:19:39.*3333.*Second change.*Foo <Bar>.*");
}
use of com.google.copybara.config.Config in project copybara by google.
the class InfoTest method testInfoUpToDate.
@Test
public void testInfoUpToDate() throws Exception {
info = new InfoCmd((configPath, sourceRef) -> new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configInfo), optionsBuilder.general.getStarlarkMode()) {
@Override
public Config load(Console console) {
return config;
}
@Override
public ConfigWithDependencies loadWithDependencies(Console console) {
return configWithDeps;
}
}, getFakeContextProvider());
MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of());
Info<?> mockedInfo = Info.create(dummyOriginDescription, dummyDestinationDescription, ImmutableList.of(workflow));
Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
info.run(new CommandEnv(temp, optionsBuilder.build(), ImmutableList.of("copy.bara.sky", "workflow")));
assertThat(eventMonitor.infoFinishedEvent).isNotNull();
assertThat(eventMonitor.infoFinishedEvent.getInfo()).isEqualTo(mockedInfo);
console.assertThat().onceInLog(MessageType.INFO, ".*last_migrated 1111 - last_available None.*");
}
use of com.google.copybara.config.Config in project copybara by google.
the class WorkflowTest method customIdentityTest.
@Test
public void customIdentityTest() throws Exception {
options.workflowOptions.initHistory = true;
Config config = loadConfig("" + "core.workflow(\n" + " name = 'one',\n" + " authoring = " + authoring + "\n," + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " transformations = [metadata.expose_label('some_label', 'new_label')],\n" + " change_identity = '${copybara_config_path}foo${label:new_label}',\n" + " mode = 'ITERATIVE',\n" + ")\n\n" + "core.workflow(\n" + " name = 'two',\n" + " authoring = " + authoring + "\n," + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " change_identity = '${copybara_config_path}foo${label:some_label}',\n" + " mode = 'ITERATIVE',\n" + ")\n\n" + "core.workflow(\n" + " name = 'three',\n" + " authoring = " + authoring + "\n," + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " change_identity = '${copybara_config_path}foo${label:not_found}',\n" + " mode = 'ITERATIVE',\n" + ")\n\n" + "");
origin.addSimpleChange(1, "change\n\nsome_label=a");
origin.addSimpleChange(2, "change\n\nsome_label=b");
origin.addSimpleChange(3, "change\n\nsome_label=c");
config.getMigration("one").run(workdir, ImmutableList.of());
assertThat(destination.processed).hasSize(3);
ImmutableList<String> oneResult = destination.processed.stream().map(ProcessedChange::getChangeIdentity).collect(ImmutableList.toImmutableList());
// Different identities
assertThat(ImmutableSet.copyOf(oneResult)).hasSize(3);
destination.processed.clear();
config.getMigration("two").run(workdir, ImmutableList.of());
ImmutableList<String> twoResult = destination.processed.stream().map(ProcessedChange::getChangeIdentity).collect(ImmutableList.toImmutableList());
assertThat(oneResult).isEqualTo(twoResult);
destination.processed.clear();
config.getMigration("three").run(workdir, ImmutableList.of());
ImmutableList<String> threeResult = destination.processed.stream().map(ProcessedChange::getChangeIdentity).collect(ImmutableList.toImmutableList());
assertThat(oneResult).isNotEqualTo(threeResult);
}
use of com.google.copybara.config.Config in project copybara by google.
the class WorkflowTest method runWorkflowForMessageTransform.
private void runWorkflowForMessageTransform(WorkflowMode mode, @Nullable String thirdTransform) throws IOException, RepoException, ValidationException {
origin.addSimpleChange(0, "first commit").setAuthor(new Author("Foo Bar", "foo@bar.com")).addSimpleChange(1, "second commit").setAuthor(new Author("Foo Baz", "foo@baz.com")).addSimpleChange(2000000000, "third commit");
options.workflowOptions.lastRevision = "0";
passThruAuthoring();
Config config = loadConfig("" + "def first(ctx):\n" + " msg =''\n" + " for c in ctx.changes.current:\n" + " msg+='CHANGE: %s (%s) by %s\\n' % (c.message, c.ref, c.author.name)\n" + " ctx.set_message(msg)\n" + "def second(ctx):\n" + " ctx.set_message(ctx.message +'\\nBAR = foo\\n')\n" + " ctx.set_author(new_author('Someone <someone@somewhere.com>'))\n" + "\n" + (thirdTransform == null ? "" : thirdTransform) + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " authoring = " + authoring + "\n," + " destination = testing.destination(),\n" + " mode = '" + mode + "',\n" + " transformations = [\n" + " first, second" + (thirdTransform == null ? "" : ", third") + "]\n" + ")\n");
config.getMigration("default").run(workdir, ImmutableList.of("2"));
}
Aggregations