use of com.google.copybara.revision.Change 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.revision.Change in project copybara by google.
the class GitOriginTest method testChangesMerge.
@Test
public void testChangesMerge() throws Exception {
// Need to "round" it since git doesn't store the milliseconds
ZonedDateTime beforeTime = ZonedDateTime.now(ZoneId.systemDefault()).minusSeconds(1);
String author = "John Name <john@name.com>";
createBranchMerge(author);
ImmutableList<Change<GitRevision>> changes = newReader().changes(origin.resolve(firstCommitRef), origin.resolve("HEAD")).getChanges();
assertThat(changes).hasSize(3);
assertThat(changes.get(0).getMessage()).isEqualTo("main1\n");
assertThat(changes.get(1).getMessage()).isEqualTo("main2\n");
assertThat(changes.get(2).getMessage()).contains("Merge branch 'feature'");
for (Change<GitRevision> change : changes) {
assertThat(change.getAuthor().getEmail()).isEqualTo("john@name.com");
assertThat(change.getDateTime()).isAtLeast(beforeTime);
assertThat(change.getDateTime()).isAtMost(ZonedDateTime.now(ZoneId.systemDefault()).plusSeconds(1));
}
}
use of com.google.copybara.revision.Change in project copybara by google.
the class GitOriginTest method testChanges.
@Test
public void testChanges() throws Exception {
// Need to "round" it since git doesn't store the milliseconds
ZonedDateTime beforeTime = ZonedDateTime.now(ZoneId.systemDefault()).minusSeconds(1);
String author = "John Name <john@name.com>";
singleFileCommit(author, "change2", "test.txt", "some content2");
git("tag", "-m", "This is a tag", "0.1");
singleFileCommit(author, "change3", "test.txt", "some content3");
singleFileCommit(author, "change4", "test.txt", "some content4");
ImmutableList<Change<GitRevision>> changes = newReader().changes(origin.resolve(firstCommitRef), origin.resolve("HEAD")).getChanges();
assertThat(changes).hasSize(3);
assertThat(changes.stream().map(c -> c.getRevision().getUrl()).allMatch(c -> c.startsWith("file://"))).isTrue();
assertThat(changes.get(0).getMessage()).isEqualTo("change2\n");
assertThat(changes.get(0).getRevision().associatedLabel("GIT_DESCRIBE_CHANGE_VERSION")).contains("0.1");
assertThat(changes.get(1).getMessage()).isEqualTo("change3\n");
assertThat(changes.get(1).getRevision().associatedLabel("GIT_DESCRIBE_CHANGE_VERSION")).contains("0.1-1-g" + changes.get(1).getRevision().asString().substring(0, 7));
assertThat(changes.get(2).getMessage()).isEqualTo("change4\n");
assertThat(changes.get(2).getRevision().associatedLabel("GIT_DESCRIBE_CHANGE_VERSION")).contains("0.1-2-g" + changes.get(2).getRevision().asString().substring(0, 7));
TransformWork work = TransformWorks.of(Paths.get(""), "some msg", console).withChanges(new Changes(changes.reverse(), ImmutableList.of()));
assertThat(work.getLabel("GIT_DESCRIBE_CHANGE_VERSION")).isEqualTo("0.1-2-g" + changes.get(2).getRevision().asString().substring(0, 7));
assertThat(work.getAllLabels("GIT_DESCRIBE_CHANGE_VERSION").getImmutableList()).isEqualTo(ImmutableList.of("0.1-2-g" + changes.get(2).getRevision().asString().substring(0, 7), "0.1-1-g" + changes.get(1).getRevision().asString().substring(0, 7), "0.1"));
for (Change<GitRevision> change : changes) {
assertThat(change.getAuthor().getEmail()).isEqualTo("john@name.com");
assertThat(change.getDateTime()).isAtLeast(beforeTime);
assertThat(change.getDateTime()).isAtMost(ZonedDateTime.now(ZoneId.systemDefault()).plusSeconds(1));
}
}
use of com.google.copybara.revision.Change 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.revision.Change 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