use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testActionsCode.
@Test
public void testActionsCode() throws Exception {
String cfg = "" + "def a1(ctx):\n" + " ctx.console.info(\'Hello, this is action1 \' + str(ctx.refs))\n" + " return ctx.success()\n" + "\n" + "def a2(ctx):\n" + " ctx.console.info(\'Hello, this is action2\')\n" + " return ctx.success()\n" + "\n" + "git.mirror(" + " name = 'default'," + " origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + " destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + " actions = [a1, a2]" + ")\n" + "";
Migration migration = loadMigration(cfg, "default");
migration.run(workdir, ImmutableList.of("my_ref"));
console.assertThat().onceInLog(MessageType.INFO, "Hello, this is action1 \\[\"my_ref\"\\]");
console.assertThat().onceInLog(MessageType.INFO, "Hello, this is action2");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testMirrorNoPrune.
@Test
public void testMirrorNoPrune() throws Exception {
GitRepository destRepo1 = bareRepo(Files.createTempDirectory("dest1"));
destRepo1.init();
String cfg = "" + "git.mirror(" + " name = 'default'," + " origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + " destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + ")\n" + "";
String other = originRepo.git(originRepo.getGitDir(), "show-ref", "refs/heads/other", "-s").getStdout();
Migration migration = loadMigration(cfg, "default");
migration.run(workdir, ImmutableList.of());
originRepo.simpleCommand("branch", "-D", "other");
migration.run(workdir, ImmutableList.of());
assertThat(destRepo.git(destRepo.getGitDir(), "show-ref", "refs/heads/other", "-s").getStdout()).isEqualTo(other);
}
use of com.google.copybara.config.Migration in project copybara by google.
the class CopybaraTest method setUp.
@Before
public void setUp() throws Exception {
optionsBuilder = new OptionsBuilder();
console = new TestingConsole();
eventMonitor = new TestingEventMonitor();
optionsBuilder.setConsole(console);
optionsBuilder.general.withEventMonitor(eventMonitor);
migration = mock(Migration.class);
config = new Config(ImmutableMap.of("workflow", migration), "foo/copy.bara.sky");
}
use of com.google.copybara.config.Migration 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.Migration 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>.*");
}
Aggregations