Search in sources :

Example 26 with Author

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>");
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 27 with Author

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>");
}
Also used : Workflow(com.google.copybara.Workflow) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 28 with Author

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;
}
Also used : Author(com.google.copybara.authoring.Author) InvalidAuthorException(com.google.copybara.authoring.InvalidAuthorException)

Example 29 with Author

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();
}
Also used : Author(com.google.copybara.authoring.Author) EvalException(net.starlark.java.eval.EvalException)

Example 30 with Author

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>.*");
}
Also used : MigrationReference(com.google.copybara.Info.MigrationReference) DummyRevision(com.google.copybara.testing.DummyRevision) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) ImmutableList(com.google.common.collect.ImmutableList) Author(com.google.copybara.authoring.Author) ExitCode(com.google.copybara.util.ExitCode) Config(com.google.copybara.config.Config) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) Before(org.junit.Before) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) Migration(com.google.copybara.config.Migration) ValidationException(com.google.copybara.exception.ValidationException) ConfigWithDependencies(com.google.copybara.config.SkylarkParser.ConfigWithDependencies) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) ZoneId(java.time.ZoneId) Mockito(org.mockito.Mockito) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) StarlarkMode(com.google.copybara.util.console.StarlarkMode) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SUCCESS(com.google.copybara.util.ExitCode.SUCCESS) Mockito.mock(org.mockito.Mockito.mock) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

Author (com.google.copybara.authoring.Author)47 Test (org.junit.Test)36 DummyRevision (com.google.copybara.testing.DummyRevision)12 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)12 Change (com.google.copybara.Change)10 Changes (com.google.copybara.Changes)9 Authoring (com.google.copybara.authoring.Authoring)8 DestinationEffect (com.google.copybara.DestinationEffect)7 WriterContext (com.google.copybara.WriterContext)6 ZonedDateTime (java.time.ZonedDateTime)6 TransformResult (com.google.copybara.TransformResult)5 TransformWork (com.google.copybara.TransformWork)5 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ImmutableList (com.google.common.collect.ImmutableList)3 Transformation (com.google.copybara.Transformation)3 InvalidAuthorException (com.google.copybara.authoring.InvalidAuthorException)3 ValidationException (com.google.copybara.exception.ValidationException)3 DummyChecker (com.google.copybara.testing.DummyChecker)3 ImmutableMap (com.google.common.collect.ImmutableMap)2