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"));
}
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}");
}
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");
}
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"));
}
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");
}
Aggregations