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");
}
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}");
}
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.");
}
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");
}
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");
}
Aggregations