use of com.google.copybara.Changes in project copybara by google.
the class GitHubPrDestinationTest method emptyChange.
@Test
public void emptyChange() throws Exception {
Writer<GitRevision> writer = getWriterForTestEmptyDiff();
GitRepository remote = gitUtil.mockRemoteRepo("github.com/foo");
addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").buildOrThrow());
String baseline = remote.resolveReference("HEAD").getSha1();
addFiles(remote, "test_feature", "second change", ImmutableMap.<String, String>builder().put("foo.txt", "test").buildOrThrow());
String changeHead = remote.resolveReference("HEAD").getSha1();
gitUtil.mockApi("GET", getPullRequestsUrl("test_feature"), mockResponse("[{" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"closed\",\n" + " \"title\": \"test summary\",\n" + " \"body\": \"test summary\"," + " \"head\": {\"sha\": \"" + changeHead + "\"}," + " \"base\": {\"sha\": \"" + baseline + "\"}" + "}]"));
writeFile(this.workdir, "foo.txt", "test");
RedundantChangeException e = assertThrows(RedundantChangeException.class, () -> writer.write(TransformResults.of(this.workdir, new DummyRevision("one")).withBaseline(baseline).withChanges(new Changes(ImmutableList.of(toChange(new DummyRevision("feature"), new Author("Foo Bar", "foo@bar.com"))), ImmutableList.of())).withLabelFinder(Functions.forMap(ImmutableMap.of("aaa", ImmutableList.of("first a", "second a")))), Glob.ALL_FILES, console));
assertThat(e).hasMessageThat().contains("Skipping push to the existing pr https://github.com/foo/pull/12345 " + "as the change feature is empty.");
}
use of com.google.copybara.Changes 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.Changes in project copybara by google.
the class MetadataModuleTest method testSquashNotesWithMerge.
@Test
public void testSquashNotesWithMerge() throws Exception {
Changes changes = new Changes(ImmutableList.of(new Change<>(new DummyRevision("3"), ORIGINAL_AUTHOR, "merge", fakeDate(), ImmutableListMultimap.of(), /*changeFiles=*/
null, /*merge=*/
true, ImmutableList.of(new DummyRevision("10"), new DummyRevision("20"))), new Change<>(new DummyRevision("2"), ORIGINAL_AUTHOR, "change2", fakeDate(), ImmutableListMultimap.of()), new Change<>(new DummyRevision("1"), ORIGINAL_AUTHOR, "change1", fakeDate(), ImmutableListMultimap.of())), ImmutableList.of());
TransformWork work = TransformWorks.of(workdir, "the message", testingConsole).withChanges(changes);
// The default is to use merges, since git.origin does --first-parent by default
skylark.<MetadataSquashNotes>eval("s", "s = metadata.squash_notes()").transform(work);
assertThat(work.getMessage()).isEqualTo("Copybara import of the project:\n" + "\n" + " - 3 merge by Foo Bar <foo@bar.com>\n" + " - 2 change2 by Foo Bar <foo@bar.com>\n" + " - 1 change1 by Foo Bar <foo@bar.com>\n");
work = TransformWorks.of(workdir, "the message", testingConsole).withChanges(changes);
skylark.<MetadataSquashNotes>eval("s", "s = metadata.squash_notes(use_merge = False)").transform(work);
assertThat(work.getMessage()).isEqualTo("Copybara import of the project:\n" + "\n" + " - 2 change2 by Foo Bar <foo@bar.com>\n" + " - 1 change1 by Foo Bar <foo@bar.com>\n");
}
use of com.google.copybara.Changes in project copybara by google.
the class MetadataModuleTest method testExposeLabelAll.
@Test
public void testExposeLabelAll() throws Exception {
TransformWork tw = TransformWorks.of(workdir, "some message\n\n" + "LABEL=aaa", testingConsole).withChanges(new Changes(ImmutableList.of(toChange(new DummyRevision("1").withLabels(ImmutableListMultimap.of("LABEL", "bbb")), ORIGINAL_AUTHOR), toChange(new DummyRevision("2").withLabels(ImmutableListMultimap.of("LABEL", "bbb")), ORIGINAL_AUTHOR), toChange(new DummyRevision("2").withLabels(ImmutableListMultimap.of("LABEL", "ccc")), ORIGINAL_AUTHOR)), ImmutableList.of())).withResolvedReference(new DummyRevision("123").withLabels(ImmutableListMultimap.of("LABEL", "ddd")));
Transformation t = skylark.eval("t", "t = " + "metadata.expose_label('LABEL', 'NEW_VALUE', all = True)");
t.transform(tw);
assertThat(tw.getMessage()).isEqualTo("some message\n" + "\n" + "LABEL=aaa\n" + "NEW_VALUE=aaa\n" + "NEW_VALUE=bbb\n" + "NEW_VALUE=ccc\n" + "NEW_VALUE=ddd\n");
}
use of com.google.copybara.Changes in project copybara by google.
the class GitDestinationTest method testTag.
@Test
public void testTag() 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(null).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")).withChanges(changes).withSummary("message_tag"), destinationFiles, console);
CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
assertThat(commandOutput.getStdout()).matches(".*test_v1.*message_tag\n" + ".*\n" + ".*DummyOrigin-RevId: ref2\n");
}
Aggregations