use of com.google.copybara.authoring.Author in project copybara by google.
the class MetadataModuleTest method testRestoreAuthor.
@Test
public void testRestoreAuthor() throws Exception {
Workflow<?, ?> wf = createWorkflow(WorkflowMode.ITERATIVE, "metadata.restore_author()");
origin.setAuthor(new Author("remove me", "remove@me.com")).addSimpleChange(0, "A change\n\nORIGINAL_AUTHOR=restore me <restore@me.com>\n");
wf.run(workdir, ImmutableList.of());
ProcessedChange change = Iterables.getLast(destination.processed);
assertThat(change.getChangesSummary()).doesNotContain("restore@me.com");
assertThat(change.getChangesSummary()).doesNotContain("ORIGINAL_AUTHOR");
assertThat(change.getAuthor().toString()).isEqualTo("restore me <restore@me.com>");
}
use of com.google.copybara.authoring.Author in project copybara by google.
the class MetadataModuleTest method testMapAuthor.
@Test
public void testMapAuthor() throws Exception {
options.setLastRevision(origin.resolve("HEAD").asString());
Workflow wf = createWorkflow(WorkflowMode.ITERATIVE, MetadataModule.MAP_AUTHOR_EXAMPLE_SIMPLE);
origin.setAuthor(new Author("john", "john@example.com")).addSimpleChange(0, "change 0");
origin.setAuthor(new Author("Example Example", "madeupexample@google.com")).addSimpleChange(1, "change 1");
origin.setAuthor(new Author("John Example", "john.example@example.com")).addSimpleChange(2, "change 2");
origin.setAuthor(new Author("Other Example", "john.example@example.com")).addSimpleChange(3, "change 3");
origin.setAuthor(new Author("John Example", "other.example@example.com")).addSimpleChange(4, "change 4");
destination.processed.clear();
wf.run(workdir, /*sourceRef=*/
null);
assertThat(destination.processed.get(0).getAuthor().toString()).isEqualTo("Some Person <some@example.com>");
assertThat(destination.processed.get(1).getAuthor().toString()).isEqualTo("Other Person <someone@example.com>");
assertThat(destination.processed.get(2).getAuthor().toString()).isEqualTo("Another Person <some@email.com>");
assertThat(destination.processed.get(3).getAuthor().toString()).isEqualTo(// No match
"Other Example <john.example@example.com>");
assertThat(destination.processed.get(4).getAuthor().toString()).isEqualTo(// No match
"John Example <other.example@example.com>");
}
use of com.google.copybara.authoring.Author in project copybara by google.
the class MapAuthor method getMappedAuthor.
private Author getMappedAuthor(Author originalAuthor) throws ValidationException {
String newAuthor = authorToAuthor.get(originalAuthor.toString());
if (newAuthor != null) {
try {
return AuthorParser.parse(newAuthor);
} catch (InvalidAuthorException e) {
throw new IllegalStateException("Shouldn't happen. We validate before", e);
}
}
Author byMail = mailToAuthor.get(originalAuthor.getEmail());
if (byMail != null) {
return byMail;
}
Author byName = nameToAuthor.get(originalAuthor.getName());
if (byName != null) {
return byName;
}
checkCondition(!failIfNotFound, "Cannot find a mapping for author '%s'", originalAuthor);
return originalAuthor;
}
use of com.google.copybara.authoring.Author in project copybara by google.
the class RestoreOriginalAuthor method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException {
Author author = null;
// last author wins.
for (Change<?> change : work.getChanges().getCurrent()) {
ImmutableCollection<String> labelValue = change.getLabels().get(label);
if (!labelValue.isEmpty()) {
try {
author = Author.parse(Iterables.getLast(labelValue));
} catch (EvalException e) {
// Don't fail the migration because the label is wrong since it is very
// difficult for a user to recover from this.
work.getConsole().warn("Cannot restore original author: " + e.getMessage());
}
}
if (!searchAllChanges) {
break;
}
}
if (author != null) {
work.setAuthor(author);
work.removeLabel(label, /*wholeMessage=*/
true);
}
return TransformationStatus.success();
}
use of com.google.copybara.authoring.Author 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