Search in sources :

Example 31 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class WorkflowTest method runWorkflowForMessageTransform.

private void runWorkflowForMessageTransform(WorkflowMode mode, @Nullable String thirdTransform) throws IOException, RepoException, ValidationException {
    origin.addSimpleChange(0, "first commit").setAuthor(new Author("Foo Bar", "foo@bar.com")).addSimpleChange(1, "second commit").setAuthor(new Author("Foo Baz", "foo@baz.com")).addSimpleChange(2000000000, "third commit");
    options.workflowOptions.lastRevision = "0";
    passThruAuthoring();
    Config config = loadConfig("" + "def first(ctx):\n" + "  msg =''\n" + "  for c in ctx.changes.current:\n" + "    msg+='CHANGE: %s (%s) by %s\\n' %  (c.message, c.ref, c.author.name)\n" + "  ctx.set_message(msg)\n" + "def second(ctx):\n" + "  ctx.set_message(ctx.message +'\\nBAR = foo\\n')\n" + "  ctx.set_author(new_author('Someone <someone@somewhere.com>'))\n" + "\n" + (thirdTransform == null ? "" : thirdTransform) + "core.workflow(\n" + "    name = 'default',\n" + "    origin =  testing.origin(),\n" + "    authoring = " + authoring + "\n," + "    destination = testing.destination(),\n" + "    mode = '" + mode + "',\n" + "    transformations = [\n" + "      first, second" + (thirdTransform == null ? "" : ", third") + "]\n" + ")\n");
    config.getMigration("default").run(workdir, ImmutableList.of("2"));
}
Also used : Config(com.google.copybara.config.Config) Author(com.google.copybara.authoring.Author)

Example 32 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class GerritDestinationTest method process.

private void process(DummyRevision originRef, GerritDestination destination) throws ValidationException, RepoException, IOException {
    WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    Writer<GitRevision> gitRevisionWriter = destination.newWriter(writerContext);
    // This is largely unused, except for the label finder.
    TransformWork work = new TransformWork(workdir, new Metadata("Desc", new Author("foo", "foo@foo.com"), ImmutableSetMultimap.of()), Changes.EMPTY, console, new MigrationInfo(DummyOrigin.LABEL_NAME, null), originRef, console -> new DummyEndpoint(), console -> gitRevisionWriter.getFeedbackEndPoint(console), () -> gitRevisionWriter.getDestinationReader(console, null, workdir));
    ImmutableList<DestinationEffect> result = gitRevisionWriter.write(TransformResults.of(workdir, originRef).withLabelFinder(work::getAllLabels).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
Also used : DummyEndpoint(com.google.copybara.testing.DummyEndpoint) WriterContext(com.google.copybara.WriterContext) MigrationInfo(com.google.copybara.MigrationInfo) DestinationEffect(com.google.copybara.DestinationEffect) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) Metadata(com.google.copybara.Metadata) Author(com.google.copybara.authoring.Author)

Example 33 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class GerritDestinationTest method testProcesPushOutput.

private void testProcesPushOutput(boolean newReview, Type created, String gerritResponse, String expectedConsoleMessage) throws IOException, RepoException, ValidationException {
    GerritWriteHook process = new GerritWriteHook(options.general, options.gerrit, "http://example.com/foo", new Author("foo", "foo@example.com"), ImmutableList.of(), ImmutableList.of(), ChangeIdPolicy.REPLACE, /*allowEmptyDiffPatchSet=*/
    true, /*labels*/
    ImmutableList.of(), /*endpointChecker=*/
    null, /*notifyOption*/
    null, /*topicTemplate*/
    null, /*partialFetch*/
    false, /*gerritSubmit*/
    false, /*primaryBranchMigrationMode*/
    false);
    fakeOneCommitInDestination();
    ImmutableList<DestinationEffect> result = process.afterPush(gerritResponse, new GerritMessageInfo(ImmutableList.of(), newReview, CONSTANT_CHANGE_ID), repo().resolveReference("HEAD"), Changes.EMPTY.getCurrent());
    console.assertThat().onceInLog(MessageType.INFO, expectedConsoleMessage);
    assertThat(result).hasSize(2);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
    assertThat(result.get(1).getSummary()).contains(expectedConsoleMessage);
    assertThat(result.get(1).getType()).isEqualTo(created);
    assertThat(result.get(1).getDestinationRef().getId()).isEqualTo("1234");
    assertThat(result.get(1).getDestinationRef().getType()).isEqualTo("gerrit_review");
    assertThat(result.get(1).getDestinationRef().getUrl()).isEqualTo("https://some.url.google.com/1234");
}
Also used : GerritWriteHook(com.google.copybara.git.GerritDestination.GerritWriteHook) GerritMessageInfo(com.google.copybara.git.GerritDestination.GerritMessageInfo) DestinationEffect(com.google.copybara.DestinationEffect) Author(com.google.copybara.authoring.Author)

Example 34 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class GitDestinationTest method authorPropagated.

@Test
public void authorPropagated() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    DummyRevision firstCommit = new DummyRevision("first_commit").withAuthor(new Author("Foo Bar", "foo@bar.com")).withTimestamp(timeFromEpoch(1414141414));
    process(firstCommitWriter(), firstCommit);
    assertCommitHasAuthor(primaryBranch, new Author("Foo Bar", "foo@bar.com"));
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 35 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class GitDestinationTest method authorDateWithSubsecondsCorrectlyPopulated.

/**
 * This test reproduces an issue where the author timestamp has subseconds and, as a result,
 * before the fix the change was committed with the (incorrect) date '2017-04-12T12:19:00-07:00',
 * instead of '2017-06-01T12:19:00-04:00'.
 */
@Test
public void authorDateWithSubsecondsCorrectlyPopulated() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1496333940012L), ZoneId.of("-04:00"));
    DummyRevision firstCommit = new DummyRevision("first_commit").withAuthor(new Author("Foo Bar", "foo@bar.com")).withTimestamp(zonedDateTime);
    process(firstCommitWriter(), firstCommit);
    String authorDate = git("log", "-1", "--pretty=%aI");
    assertThat(authorDate).isEqualTo("2017-06-01T12:19:00-04:00\n");
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) 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