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