Search in sources :

Example 6 with Changes

use of com.google.copybara.revision.Changes in project copybara by google.

the class GitHubDestinationTest method testCheckerOnPush.

@Test
public void testCheckerOnPush() throws Exception {
    options.workflowOptions.initHistory = true;
    addFiles(remote, primaryBranch, "first change", ImmutableMap.of("foo.txt", "hello"));
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
    GitDestination d = skylark.eval("r", "r = git.github_destination(" + "    url = '" + url + "', \n" + "    push = '" + primaryBranch + "',\n" + "    checker = testing.dummy_checker(),\n" + ")");
    WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    writeFile(this.workdir, "test.txt", "BAD");
    Writer<GitRevision> writer = d.newWriter(writerContext);
    DummyRevision ref = new DummyRevision("origin_ref1");
    Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
    TransformResult result = TransformResults.of(workdir, ref).withChanges(changes);
    assertThat(assertThrows(CheckerException.class, () -> writer.write(result, destinationFiles, console))).hasMessageThat().contains("Bad word 'bad' found");
}
Also used : Changes(com.google.copybara.revision.Changes) WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.revision.Change) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 7 with Changes

use of com.google.copybara.revision.Changes in project copybara by google.

the class GitHubDestinationTest method process.

private void process(Writer<GitRevision> writer, DummyRevision ref) throws ValidationException, RepoException, IOException {
    TransformResult result = TransformResults.of(workdir, ref);
    Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
    result = result.withChanges(changes);
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
Also used : Changes(com.google.copybara.revision.Changes) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.effect.DestinationEffect) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.revision.Change)

Example 8 with Changes

use of com.google.copybara.revision.Changes in project copybara by google.

the class GitHubPrDestinationTest method emptyChange.

@Test
public void emptyChange() throws Exception {
    Writer<GitRevision> writer = getWriterForTestEmptyDiff();
    GitRepository remote = gitUtil.mockRemoteRepo("github.com/foo");
    addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").buildOrThrow());
    String baseline = remote.resolveReference("HEAD").getSha1();
    addFiles(remote, "test_feature", "second change", ImmutableMap.<String, String>builder().put("foo.txt", "test").buildOrThrow());
    String changeHead = remote.resolveReference("HEAD").getSha1();
    gitUtil.mockApi("GET", getPullRequestsUrl("test_feature"), mockResponse("[{" + "  \"id\": 1,\n" + "  \"number\": 12345,\n" + "  \"state\": \"closed\",\n" + "  \"title\": \"test summary\",\n" + "  \"body\": \"test summary\"," + "  \"head\": {\"sha\": \"" + changeHead + "\"}," + "  \"base\": {\"sha\": \"" + baseline + "\"}" + "}]"));
    writeFile(this.workdir, "foo.txt", "test");
    RedundantChangeException e = assertThrows(RedundantChangeException.class, () -> writer.write(TransformResults.of(this.workdir, new DummyRevision("one")).withBaseline(baseline).withChanges(new Changes(ImmutableList.of(toChange(new DummyRevision("feature"), new Author("Foo Bar", "foo@bar.com"))), ImmutableList.of())).withLabelFinder(Functions.forMap(ImmutableMap.of("aaa", ImmutableList.of("first a", "second a")))), Glob.ALL_FILES, console));
    assertThat(e).hasMessageThat().contains("Skipping push to the existing pr https://github.com/foo/pull/12345 " + "as the change feature is empty.");
}
Also used : Changes(com.google.copybara.revision.Changes) DummyRevision(com.google.copybara.testing.DummyRevision) RedundantChangeException(com.google.copybara.exception.RedundantChangeException) Author(com.google.copybara.authoring.Author) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with Changes

use of com.google.copybara.revision.Changes 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.revision.Changes) Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 10 with Changes

use of com.google.copybara.revision.Changes 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.revision.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.revision.Change) Test(org.junit.Test)

Aggregations

Changes (com.google.copybara.revision.Changes)15 DummyRevision (com.google.copybara.testing.DummyRevision)12 Test (org.junit.Test)11 Author (com.google.copybara.authoring.Author)10 Change (com.google.copybara.revision.Change)9 TransformWork (com.google.copybara.TransformWork)6 WriterContext (com.google.copybara.WriterContext)6 DestinationEffect (com.google.copybara.effect.DestinationEffect)5 TransformResult (com.google.copybara.TransformResult)4 ValidationException (com.google.copybara.exception.ValidationException)3 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)3 Strings (com.google.common.base.Strings)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)2 CheckerException (com.google.copybara.checks.CheckerException)2 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 RedundantChangeException (com.google.copybara.exception.RedundantChangeException)2