Search in sources :

Example 41 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class RemoteArchiveOriginTest method testZipFileMultipleDirs.

@Test
public void testZipFileMultipleDirs() throws Exception {
    when(transport.open(any())).thenReturn(new ByteArrayInputStream(BaseEncoding.base64().decode(CAPTURED_MULTIPLE_DIRS_ZIP_FILE)));
    RemoteArchiveOrigin underTest = new RemoteArchiveOrigin("zip", Author.parse("Copybara <noreply@copybara.io>"), "a message", transport, profiler, remoteFileOptions);
    Reader<RemoteArchiveRevision> reader = underTest.newReader(Glob.ALL_FILES, new Authoring(new Author("foo", "default@example.com"), AuthoringMappingMode.PASS_THRU, ImmutableSet.of()));
    RemoteArchiveRevision revision = underTest.resolve("https://dirs.zip");
    reader.checkout(revision, workdir);
    assertThatPath(workdir).containsFile("parent/dir-one/first.txt", "first file\n");
    assertThatPath(workdir).containsFile("parent/dir-two/second.txt", "second file\n");
}
Also used : Authoring(com.google.copybara.authoring.Authoring) ByteArrayInputStream(java.io.ByteArrayInputStream) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 42 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class DummyOriginTest method canSetAuthorOfIndividualChanges.

@Test
public void canSetAuthorOfIndividualChanges() throws Exception {
    DummyOrigin origin = new DummyOrigin().setAuthor(new Author("Dummy Origin", "dummy_origin@google.com")).addSimpleChange(/*timestamp*/
    42).setAuthor(new Author("Wise Origin", "wise_origin@google.com")).addSimpleChange(/*timestamp*/
    999);
    Authoring authoring = new Authoring(new Author("foo", "default.example.com"), AuthoringMappingMode.PASS_THRU, ImmutableSet.of());
    ImmutableList<Change<DummyRevision>> changes = origin.newReader(Glob.ALL_FILES, authoring).changes(/*fromRef*/
    null, /*toRef*/
    origin.resolve("1")).getChanges();
    assertThat(changes).hasSize(2);
    assertThat(changes.get(0).getAuthor()).isEqualTo(new Author("Dummy Origin", "dummy_origin@google.com"));
    assertThat(changes.get(1).getAuthor()).isEqualTo(new Author("Wise Origin", "wise_origin@google.com"));
}
Also used : Authoring(com.google.copybara.authoring.Authoring) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) Test(org.junit.Test)

Example 43 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class RemoteFileModuleTest method testRemoteArchiveOriginZipFile.

@Test
public void testRemoteArchiveOriginZipFile() throws Exception {
    when(transport.open(any())).thenReturn(new ByteArrayInputStream(BaseEncoding.base64().decode(CAPUTRED_HELLO_WORLD_ZIP_FILE)));
    RemoteArchiveOrigin underTest = skylark.eval("o", "o = remotefiles.origin(unpack_method = 'zip', message = 'hello world')");
    Reader<RemoteArchiveRevision> reader = underTest.newReader(Glob.ALL_FILES, new Authoring(new Author("foo", "default@example.com"), AuthoringMappingMode.PASS_THRU, ImmutableSet.of()));
    RemoteArchiveRevision revision = underTest.resolve("https://dirs.zip");
    reader.checkout(revision, workdir);
    assertThatPath(workdir).containsFile("test.txt", "hello world\n");
}
Also used : Authoring(com.google.copybara.authoring.Authoring) ByteArrayInputStream(java.io.ByteArrayInputStream) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 44 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class MetadataModuleTest method testMapAuthor_failIfNotFound.

@Test
public void testMapAuthor_failIfNotFound() throws Exception {
    options.setLastRevision(origin.resolve("HEAD").asString());
    Workflow<?, ?> wf = createWorkflow(WorkflowMode.ITERATIVE, "" + "metadata.map_author({\n" + "    'a' : 'x <x@example.com>',\n" + "    'b@example.com' : 'y <y@example.com>',\n" + "    'c <c@example.com>' : 'z <z@example.com>',\n" + "}, fail_if_not_found = True)");
    origin.setAuthor(new Author("a", "a@example.com")).addSimpleChange(0, "change 0");
    origin.setAuthor(new Author("b", "b@example.com")).addSimpleChange(1, "change 1");
    origin.setAuthor(new Author("c", "c@example.com")).addSimpleChange(2, "change 2");
    origin.setAuthor(new Author("Not found", "d@example.com")).addSimpleChange(3, "change 3");
    destination.processed.clear();
    ValidationException e = assertThrows(ValidationException.class, () -> wf.run(workdir, ImmutableList.of()));
    assertThat(e).hasMessageThat().contains("Cannot find a mapping for author 'Not found <d@example.com>'");
    assertThat(destination.processed.get(0).getAuthor().toString()).isEqualTo("x <x@example.com>");
    assertThat(destination.processed.get(1).getAuthor().toString()).isEqualTo("y <y@example.com>");
    assertThat(destination.processed.get(2).getAuthor().toString()).isEqualTo("z <z@example.com>");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) NonReversibleValidationException(com.google.copybara.exception.NonReversibleValidationException) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 45 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class MetadataModuleTest method testsSaveAuthor.

@Test
public void testsSaveAuthor() throws Exception {
    Workflow<?, ?> wf = createWorkflow(WorkflowMode.ITERATIVE, "metadata.save_author()");
    origin.setAuthor(new Author("keep me", "keep@me.com")).addSimpleChange(0, "A change");
    wf.run(workdir, ImmutableList.of());
    ProcessedChange change = Iterables.getLast(destination.processed);
    assertThat(change.getChangesSummary()).contains("ORIGINAL_AUTHOR=keep me <keep@me.com>");
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Author(com.google.copybara.authoring.Author) 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