use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class MetadataModuleTest method testCurrentRevForSquashEmptyChanges.
@Test
public void testCurrentRevForSquashEmptyChanges() throws Exception {
options.setForce(true);
passThruAuthoring();
options.setLastRevision(origin.resolve("HEAD").asString());
origin.singleFileChange(42, "test", "excluded", "");
DummyRevision expectedRev = origin.resolve("HEAD");
Config config = loadConfig("" + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " origin_files = glob(['**'], exclude = ['excluded']),\n" + " authoring = " + authoring + "\n," + " destination = testing.destination(),\n" + " mode = '" + WorkflowMode.SQUASH + "',\n" + " transformations = [" + " metadata.replace_message('${COPYBARA_CURRENT_REV}')," + " ]\n" + ")\n");
config.getMigration("default").run(workdir, ImmutableList.of());
assertThat(Iterables.getLast(destination.processed).getChangesSummary()).isEqualTo(expectedRev.asString());
}
use of com.google.copybara.testing.DummyRevision 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");
}
use of com.google.copybara.testing.DummyRevision 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.testing.DummyRevision in project copybara by google.
the class MetadataModuleTest method checkExposeLabel.
private void checkExposeLabel(String msg, String transform, String expectedOutput) throws ValidationException, IOException {
TransformWork tw = TransformWorks.of(workdir, msg, testingConsole).withChanges(EMPTY_CHANGES).withResolvedReference(new DummyRevision("123").withLabels(ImmutableMap.of("SOME", "value")));
Transformation t = skylarkExecutor.eval("t", "t = " + transform);
t.transform(tw);
assertThat(tw.getMessage()).isEqualTo(expectedOutput);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GithubPrDestinationTest method checkWrite.
private void checkWrite(String groupId) throws ValidationException, RepoException, IOException {
gitApiMockHttpTransport = new GitApiMockHttpTransport() {
@Override
protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request) throws IOException {
boolean isPulls = "https://api.github.com/repos/foo/pulls".equals(url);
if ("GET".equals(method) && isPulls) {
return "[]".getBytes(UTF_8);
} else if ("POST".equals(method) && isPulls) {
assertThat(request.getContentAsString()).isEqualTo("{\"base\":\"master\",\"body\":\"test summary\",\"head\":\"feature\",\"title\":\"test summary\"}");
return ("{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"test summary\",\n" + " \"body\": \"test summary\"" + "}").getBytes();
}
fail(method + " " + url);
throw new IllegalStateException();
}
};
GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'" + ")");
Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, groupId, /*oldWriter=*/
null);
GitRepository remote = localHubRepo("foo");
addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
Files.write(this.workdir.resolve("test.txt"), "other content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("two")), console);
// Use a new writer that shares the old state
writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, groupId, /*oldWriter=*/
writer);
Files.write(this.workdir.resolve("test.txt"), "and content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("three")), console);
console.assertThat().timesInLog(1, MessageType.INFO, "Pull Request https://github.com/foo/pull/12345 created using branch 'feature'.");
assertThat(remote.refExists("feature")).isTrue();
assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: one\n", "test summary\n" + "\n" + "DummyOrigin-RevId: two\n", "test summary\n" + "\n" + "DummyOrigin-RevId: three\n");
// If we don't keep writer state (same as a new migration). We do a rebase of
// all the changes.
writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, groupId, /*oldWriter=*/
null);
Files.write(this.workdir.resolve("test.txt"), "and content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("four")), console);
assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: four\n");
}
Aggregations