use of com.google.copybara.Changes in project copybara by google.
the class GerritDestinationTest method setup.
@Before
public void setup() throws Exception {
workdir = Files.createTempDirectory("workdir");
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
gitUtil = new GitTestUtil(options);
Path credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, BASE_URL.getBytes(UTF_8));
GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).init().withCredentialHelper("store --file=" + credentialsFile);
gitUtil.mockRemoteGitRepos(new Validator(), repo);
options.gitDestination = new GitDestinationOptions(options.general, options.git);
options.gitDestination.committerEmail = "commiter@email";
options.gitDestination.committerName = "Bara Kopi";
excludedDestinationPaths = ImmutableList.of();
repoGitDir = gitUtil.mockRemoteRepo("localhost:33333/foo/bar").getGitDir();
url = "https://localhost:33333/foo/bar";
repo().init();
skylark = new SkylarkTestExecutor(options);
when(gitUtil.httpTransport().buildRequest(eq("GET"), startsWith("https://localhost:33333/changes/"))).then((Answer<LowLevelHttpRequest>) invocation -> {
String change = changeIdFromRequest((String) invocation.getArguments()[1]);
return mockResponse("[" + "{" + " change_id : \"" + change + "\"," + " status : \"NEW\"" + "}]");
});
gitUtil.mockApi(eq("GET"), eq("https://localhost:33333/changes/?q=" + "hashtag:%22copybara_id_origin_ref_commiter@email%22%20AND" + "%20project:foo/bar%20AND%20status:NEW"), mockResponse("[]"));
}
use of com.google.copybara.Changes in project copybara by google.
the class GitDestinationTest method testTagWithMsg.
@Test
public void testTagWithMsg() 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);
options.setForce(false);
Changes changes = new Changes(ImmutableList.of(new Change<>(new DummyRevision("ref2"), new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345"))), ImmutableList.of());
Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")).withChanges(changes), destinationFiles, console);
CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
assertThat(commandOutput.getStdout()).matches(".*test_v1.*" + tagMsg + "\n");
}
use of com.google.copybara.Changes in project copybara by google.
the class GitHubDestinationTest method testPrToUpdateIngoredForInitHistory.
@Test
public void testPrToUpdateIngoredForInitHistory() throws Exception {
options.workflowOptions.initHistory = true;
addFiles(remote, primaryBranch, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "foo").buildOrThrow());
WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
writeFile(this.workdir, "test.txt", "some content");
Writer<GitRevision> writer = destinationWithExistingPrBranch("other", "True").newWriter(writerContext);
DummyRevision ref = new DummyRevision("origin_ref1");
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}");
// This is a migration of two changes (use the same ref because mocks)
verifyNoInteractions(gitUtil.httpTransport());
GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
assertThat(remote.simpleCommand("show-ref").getStdout()).doesNotContain("other");
}
use of com.google.copybara.Changes 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.Changes 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");
}
Aggregations