Search in sources :

Example 6 with Author

use of com.google.copybara.authoring.Author 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");
}
Also used : Changes(com.google.copybara.Changes) WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) Test(org.junit.Test)

Example 7 with Author

use of com.google.copybara.authoring.Author 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}");
}
Also used : Changes(com.google.copybara.Changes) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change)

Example 8 with Author

use of com.google.copybara.authoring.Author 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");
}
Also used : Changes(com.google.copybara.Changes) WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 9 with Author

use of com.google.copybara.authoring.Author 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.");
}
Also used : Changes(com.google.copybara.Changes) DummyRevision(com.google.copybara.testing.DummyRevision) RedundantChangeException(com.google.copybara.exception.RedundantChangeException) Author(com.google.copybara.authoring.Author) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with Author

use of com.google.copybara.authoring.Author 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));
    }
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) AuthoringMappingMode(com.google.copybara.authoring.Authoring.AuthoringMappingMode) ZonedDateTime(java.time.ZonedDateTime) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) TransformWork(com.google.copybara.TransformWork) LabelsAwareModule(com.google.copybara.config.LabelsAwareModule) VisitResult(com.google.copybara.ChangeVisitable.VisitResult) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) Workflow(com.google.copybara.Workflow) Path(java.nio.file.Path) Reader(com.google.copybara.Origin.Reader) ImmutableSet(com.google.common.collect.ImmutableSet) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) Revision(com.google.copybara.Revision) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) List(java.util.List) Iterables(com.google.common.collect.Iterables) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) Changes(com.google.copybara.Changes) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ChangesResponse(com.google.copybara.Origin.Reader.ChangesResponse) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ModuleSet(com.google.copybara.ModuleSet) Before(org.junit.Before) Glob.createGlob(com.google.copybara.util.Glob.createGlob) EmptyReason(com.google.copybara.Origin.Reader.ChangesResponse.EmptyReason) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) ValidationException(com.google.copybara.exception.ValidationException) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Authoring(com.google.copybara.authoring.Authoring) Glob(com.google.copybara.util.Glob) Paths(java.nio.file.Paths) TransformWorks(com.google.copybara.testing.TransformWorks) GitTestUtil.writeFile(com.google.copybara.testing.git.GitTestUtil.writeFile) Changes(com.google.copybara.Changes) ZonedDateTime(java.time.ZonedDateTime) TransformWork(com.google.copybara.TransformWork) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Change(com.google.copybara.Change) Test(org.junit.Test)

Aggregations

Author (com.google.copybara.authoring.Author)47 Test (org.junit.Test)36 DummyRevision (com.google.copybara.testing.DummyRevision)12 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)12 Change (com.google.copybara.Change)10 Changes (com.google.copybara.Changes)9 Authoring (com.google.copybara.authoring.Authoring)8 DestinationEffect (com.google.copybara.DestinationEffect)7 WriterContext (com.google.copybara.WriterContext)6 ZonedDateTime (java.time.ZonedDateTime)6 TransformResult (com.google.copybara.TransformResult)5 TransformWork (com.google.copybara.TransformWork)5 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ImmutableList (com.google.common.collect.ImmutableList)3 Transformation (com.google.copybara.Transformation)3 InvalidAuthorException (com.google.copybara.authoring.InvalidAuthorException)3 ValidationException (com.google.copybara.exception.ValidationException)3 DummyChecker (com.google.copybara.testing.DummyChecker)3 ImmutableMap (com.google.common.collect.ImmutableMap)2