Search in sources :

Example 16 with TransformWork

use of com.google.copybara.TransformWork in project copybara by google.

the class MetadataModuleTest method testMapAuthor_reversible.

@Test
public void testMapAuthor_reversible() throws Exception {
    Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + "    'a <a@example.com>' : 'b <b@example.com>',\n" + "}," + "reversible = True)");
    TransformWork work = TransformWorks.of(workdir, "test", testingConsole);
    work.setAuthor(new Author("a", "a@example.com"));
    m.transform(work);
    assertThat(work.getAuthor().toString()).isEqualTo("b <b@example.com>");
    m.reverse().transform(work);
    assertThat(work.getAuthor().toString()).isEqualTo("a <a@example.com>");
}
Also used : Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 17 with TransformWork

use of com.google.copybara.TransformWork in project copybara by google.

the class MetadataModuleTest method testSquashNotesWithMerge.

@Test
public void testSquashNotesWithMerge() throws Exception {
    Changes changes = new Changes(ImmutableList.of(new Change<>(new DummyRevision("3"), ORIGINAL_AUTHOR, "merge", fakeDate(), ImmutableListMultimap.of(), /*changeFiles=*/
    null, /*merge=*/
    true, ImmutableList.of(new DummyRevision("10"), new DummyRevision("20"))), new Change<>(new DummyRevision("2"), ORIGINAL_AUTHOR, "change2", fakeDate(), ImmutableListMultimap.of()), new Change<>(new DummyRevision("1"), ORIGINAL_AUTHOR, "change1", fakeDate(), ImmutableListMultimap.of())), ImmutableList.of());
    TransformWork work = TransformWorks.of(workdir, "the message", testingConsole).withChanges(changes);
    // The default is to use merges, since git.origin does --first-parent by default
    skylark.<MetadataSquashNotes>eval("s", "s = metadata.squash_notes()").transform(work);
    assertThat(work.getMessage()).isEqualTo("Copybara import of the project:\n" + "\n" + "  - 3 merge by Foo Bar <foo@bar.com>\n" + "  - 2 change2 by Foo Bar <foo@bar.com>\n" + "  - 1 change1 by Foo Bar <foo@bar.com>\n");
    work = TransformWorks.of(workdir, "the message", testingConsole).withChanges(changes);
    skylark.<MetadataSquashNotes>eval("s", "s = metadata.squash_notes(use_merge = False)").transform(work);
    assertThat(work.getMessage()).isEqualTo("Copybara import of the project:\n" + "\n" + "  - 2 change2 by Foo Bar <foo@bar.com>\n" + "  - 1 change1 by Foo Bar <foo@bar.com>\n");
}
Also used : Changes(com.google.copybara.Changes) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) TransformWorks.toChange(com.google.copybara.testing.TransformWorks.toChange) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Change(com.google.copybara.Change) Test(org.junit.Test)

Example 18 with TransformWork

use of com.google.copybara.TransformWork in project copybara by google.

the class MetadataModuleTest method testExposeLabelAll.

@Test
public void testExposeLabelAll() throws Exception {
    TransformWork tw = TransformWorks.of(workdir, "some message\n\n" + "LABEL=aaa", testingConsole).withChanges(new Changes(ImmutableList.of(toChange(new DummyRevision("1").withLabels(ImmutableListMultimap.of("LABEL", "bbb")), ORIGINAL_AUTHOR), toChange(new DummyRevision("2").withLabels(ImmutableListMultimap.of("LABEL", "bbb")), ORIGINAL_AUTHOR), toChange(new DummyRevision("2").withLabels(ImmutableListMultimap.of("LABEL", "ccc")), ORIGINAL_AUTHOR)), ImmutableList.of())).withResolvedReference(new DummyRevision("123").withLabels(ImmutableListMultimap.of("LABEL", "ddd")));
    Transformation t = skylark.eval("t", "t = " + "metadata.expose_label('LABEL', 'NEW_VALUE', all = True)");
    t.transform(tw);
    assertThat(tw.getMessage()).isEqualTo("some message\n" + "\n" + "LABEL=aaa\n" + "NEW_VALUE=aaa\n" + "NEW_VALUE=bbb\n" + "NEW_VALUE=ccc\n" + "NEW_VALUE=ddd\n");
}
Also used : Changes(com.google.copybara.Changes) Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 19 with TransformWork

use of com.google.copybara.TransformWork in project copybara by google.

the class RevisionMigratorTest method testUndefinedReferenceGetsNotUpdated.

@Test
public void testUndefinedReferenceGetsNotUpdated() throws Exception {
    String desc = "This is an awesome change, building on http://internalReviews.com/5";
    TransformWork work = getTransformWork(desc);
    referenceMigrator.transform(work);
    assertThat(work.getMessage()).isEqualTo("This is an awesome change, building on http://internalReviews.com/5");
}
Also used : TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Example 20 with TransformWork

use of com.google.copybara.TransformWork in project copybara by google.

the class RevisionMigratorTest method testMultipleGetUpdated.

@Test
public void testMultipleGetUpdated() throws Exception {
    String desc = "This is an awesome change, building on http://internalReviews.com/5005, " + "http://internalReviews.com/53, http://internalReviews.com/5, " + "http://internalReviews.com/14 and stuff.";
    TransformWork work = getTransformWork(desc);
    referenceMigrator.transform(work);
    assertThat(work.getMessage()).isEqualTo("This is an awesome change, building on http://internalReviews.com/5005, " + "http://externalreviews.com/view?35, http://internalReviews.com/5, " + "http://externalreviews.com/view?e and stuff.");
}
Also used : TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Aggregations

TransformWork (com.google.copybara.TransformWork)41 Test (org.junit.Test)33 Transformation (com.google.copybara.Transformation)23 TransformationStatus (com.google.copybara.TransformationStatus)9 DummyRevision (com.google.copybara.testing.DummyRevision)6 Changes (com.google.copybara.Changes)5 Author (com.google.copybara.authoring.Author)5 ValidationException (com.google.copybara.exception.ValidationException)4 Change (com.google.copybara.Change)3 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)3 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)2 RepoException (com.google.copybara.exception.RepoException)2 TransformWorks.toChange (com.google.copybara.testing.TransformWorks.toChange)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1