Search in sources :

Example 6 with TransformResult

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}");
}
Also used : Changes(com.google.copybara.Changes) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change)

Example 7 with TransformResult

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");
}
Also used : Changes(com.google.copybara.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.Change) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 8 with TransformResult

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");
}
Also used : TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 9 with TransformResult

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);
}
Also used : TransformResult(com.google.copybara.TransformResult) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 10 with TransformResult

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);
}
Also used : WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) DummyRevision(com.google.copybara.testing.DummyRevision)

Aggregations

TransformResult (com.google.copybara.TransformResult)16 DummyRevision (com.google.copybara.testing.DummyRevision)11 DestinationEffect (com.google.copybara.DestinationEffect)10 Test (org.junit.Test)8 Author (com.google.copybara.authoring.Author)5 Change (com.google.copybara.Change)4 Changes (com.google.copybara.Changes)4 WriterContext (com.google.copybara.WriterContext)4 ImmutableList (com.google.common.collect.ImmutableList)2 ChangeMessage (com.google.copybara.ChangeMessage)2 WriterImpl (com.google.copybara.git.GitDestination.WriterImpl)2 CreatePullRequest (com.google.copybara.git.github.api.CreatePullRequest)2 PullRequest (com.google.copybara.git.github.api.PullRequest)2 HgLogEntry (com.google.copybara.hg.HgRepository.HgLogEntry)2 Console (com.google.copybara.util.console.Console)2 CheckerException (com.google.copybara.checks.CheckerException)1 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 RepoException (com.google.copybara.exception.RepoException)1 GitHubApi (com.google.copybara.git.github.api.GitHubApi)1 GithubApi (com.google.copybara.git.github.api.GithubApi)1