Search in sources :

Example 41 with WriterContext

use of com.google.copybara.WriterContext in project copybara by google.

the class GerritDestinationTest method runChangeIdPolicy.

private String runChangeIdPolicy(String summary, String... config) throws Exception {
    fetch = "master";
    writeFile(workdir, "file", "some content");
    options.setForce(true);
    url = "https://localhost:33333/foo/bar";
    GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
    mockNoChangesFound();
    DummyRevision originRef = new DummyRevision("origin_ref");
    WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
    List<DestinationEffect> result = destination(config).newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary(summary).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    return lastCommitChangeIdLine("origin_ref", repo).replace("Change-Id: ", "").trim();
}
Also used : WriterContext(com.google.copybara.WriterContext) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 42 with WriterContext

use of com.google.copybara.WriterContext in project copybara by google.

the class GerritDestinationTest method testChecker.

@Test
public void testChecker() throws Exception {
    options.gerrit.gerritChangeId = null;
    fetch = "master";
    pushToRefsFor = "master";
    writeFile(workdir, "file", "BAD");
    options.setForce(true);
    url = "https://localhost:33333/foo/bar";
    GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
    mockNoChangesFound();
    DummyRevision originRef = new DummyRevision("origin_ref");
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
    GerritDestination destination = destination("submit = True, checker = testing.dummy_checker()");
    Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
    WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
    assertThat(assertThrows(CheckerException.class, () -> destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console))).hasMessageThat().contains("Bad word 'bad' found");
}
Also used : WriterContext(com.google.copybara.WriterContext) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 43 with WriterContext

use of com.google.copybara.WriterContext 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)

Example 44 with WriterContext

use of com.google.copybara.WriterContext in project copybara by google.

the class GitDestinationTest method testTagWithExisting.

@Test
public void testTagWithExisting() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    options.setForce(true);
    WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    evalDestination().newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
    Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
    // push tag
    evalDestinationWithTag(null).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
    options.setForce(false);
    Files.write(workdir.resolve("test.txt"), "some content 3".getBytes(UTF_8));
    // push existing tag
    evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
    CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
    assertThat(commandOutput.getStdout()).matches(".*" + tagName + ".*test summary\n" + ".*\n" + ".*DummyOrigin-RevId: ref2\n");
}
Also used : WriterContext(com.google.copybara.WriterContext) CommandOutput(com.google.copybara.util.CommandOutput) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 45 with WriterContext

use of com.google.copybara.WriterContext in project copybara by google.

the class GitDestinationTest method testTagWithExistingAndForce.

@Test
public void testTagWithExistingAndForce() throws Exception {
    WriterContext writerContext = setUpForTestingTag();
    // push existing tag with tagMsg
    options.git.gitTagOverwrite = true;
    evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
    CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
    assertThat(commandOutput.getStdout()).matches(".*" + tagName + ".*" + tagMsg + "\n");
}
Also used : WriterContext(com.google.copybara.WriterContext) CommandOutput(com.google.copybara.util.CommandOutput) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

WriterContext (com.google.copybara.WriterContext)58 DummyRevision (com.google.copybara.testing.DummyRevision)58 Test (org.junit.Test)46 DestinationEffect (com.google.copybara.DestinationEffect)21 Glob (com.google.copybara.util.Glob)17 Path (java.nio.file.Path)15 Author (com.google.copybara.authoring.Author)14 Changes (com.google.copybara.Changes)13 ValidationException (com.google.copybara.exception.ValidationException)12 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)11 CheckerException (com.google.copybara.checks.CheckerException)10 DummyChecker (com.google.copybara.testing.DummyChecker)10 MockRequestAssertion (com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion)10 CommandOutput (com.google.copybara.util.CommandOutput)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 Truth.assertThat (com.google.common.truth.Truth.assertThat)8 ChangeMessage (com.google.copybara.ChangeMessage)8 Writer (com.google.copybara.Destination.Writer)8