use of com.google.copybara.TransformResult 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.TransformResult 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.TransformResult in project copybara by google.
the class HgDestinationTest method testWrite.
@Test
public void testWrite() throws Exception {
Files.write(workdir.resolve("file.txt"), "first write".getBytes(UTF_8));
Files.write(workdir.resolve("test.txt"), "test".getBytes(UTF_8));
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1496333940000L), ZoneId.of("-04:00"));
DummyRevision originRef = new DummyRevision("origin_ref").withAuthor(new Author("Copy Bara", "copy@bara.com")).withTimestamp(zonedDateTime);
TransformResult result = TransformResults.of(workdir, originRef);
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}");
ImmutableList<HgLogEntry> commits = remoteRepo.log().run();
assertThat(commits).hasSize(2);
assertThat(commits.get(0).getDescription()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref");
assertThat(commits).hasSize(2);
assertThat(commits.get(0).getZonedDate()).isEqualTo(zonedDateTime);
assertThat(commits.get(0).getFiles()).hasSize(1);
assertThat(commits.get(0).getFiles().get(0)).isEqualTo("test.txt");
assertThat(commits.get(1).getFiles()).hasSize(1);
assertThat(commits.get(1).getFiles().get(0)).isEqualTo("file.txt");
}
use of com.google.copybara.TransformResult in project copybara by google.
the class HgDestinationTest method createRevisionAndWrite.
private void createRevisionAndWrite(String referenceName) throws RepoException, ValidationException, IOException {
DummyRevision originRef = new DummyRevision(referenceName);
TransformResult result = TransformResults.of(workdir, originRef);
writer.write(result, destinationFiles, console);
}
use of com.google.copybara.TransformResult in project copybara by google.
the class GitDestinationIntegrateTest method migrateOriginChange.
private void migrateOriginChange(GitDestination destination, String summary, String file, String content, String originRef) throws IOException, RepoException, ValidationException {
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destination.newWriter(writerContext);
Files.createDirectories(workdir.resolve(file).getParent());
Files.write(workdir.resolve(file), content.getBytes(UTF_8));
TransformResult result = TransformResults.of(workdir, new DummyRevision(originRef)).withSummary(summary);
writer.write(result, destinationFiles, console);
}
Aggregations