use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testReviewersFieldWithTopic.
@Test
public void testReviewersFieldWithTopic() throws Exception {
pushToRefsFor = "master";
writeFile(workdir, "file", "some content");
fetch = "master";
options.gerrit.gerritTopic = "testTopic";
options.setForce(true);
url = "https://localhost:33333/foo/bar";
mockNoChangesFound();
DummyRevision originRef = new DummyRevision("origin_ref");
GerritDestination destination = destination("submit = False", "reviewers = [\"${SOME_REVIEWER}\"]");
Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()).withLabelFinder(e -> e.equals("SOME_REVIEWER") ? ImmutableList.of("foo@example.com", "bar@example.com") : ImmutableList.of()), glob, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertPushRef("refs/for/master%topic=testTopic,hashtag=copybara_id_origin_ref_commiter@email," + "r=foo@example.com,r=bar@example.com");
}
use of com.google.copybara.effect.DestinationEffect 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.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testEmptyReviewersField.
@Test
public void testEmptyReviewersField() throws Exception {
pushToRefsFor = "master";
writeFile(workdir, "file", "some content");
fetch = "master";
options.gerrit.gerritTopic = "testTopic";
options.setForce(true);
url = "https://localhost:33333/foo/bar";
mockNoChangesFound();
DummyRevision originRef = new DummyRevision("origin_ref");
GerritDestination destination = destination("submit = False", "reviewers = [\"${SOME_REVIEWER}\"]");
Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertPushRef("refs/for/master%topic=testTopic");
}
use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method runAllowEmptyPatchSetFalse.
private void runAllowEmptyPatchSetFalse(String baseline) throws ValidationException, RepoException, IOException {
fetch = repo().getPrimaryBranch();
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
ImmutableList<DestinationEffect> result = destination("allow_empty_diff_patchset = False").newWriter(writerContext).write(TransformResults.of(workdir, originRef).withIdentity(originRef.asString()).withBaseline(baseline), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
assertThat(result).hasSize(1);
}
use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class WorkflowTest method testOnFinishHookCreatesEffects.
@Test
public void testOnFinishHookCreatesEffects() throws Exception {
origin.singleFileChange(0, "one commit", "foo.txt", "1");
String config = "" + "def test(ctx):\n" + " origin_refs = [ctx.origin.new_origin_ref('1111')]\n" + " dest_ref = ctx.destination.new_destination_ref(ref = '9999', type = 'some_type')\n" + " ctx.record_effect('New effect', origin_refs, dest_ref)\n" + "\n" + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " transformations = [],\n" + " authoring = " + authoring + ",\n" + " after_migration = [test]" + ")\n";
loadConfig(config).getMigration("default").run(workdir, ImmutableList.of());
assertThat(eventMonitor.changeMigrationFinishedEventCount()).isEqualTo(1);
ChangeMigrationFinishedEvent event = Iterables.getOnlyElement(eventMonitor.changeMigrationFinishedEvents);
assertThat(event.getDestinationEffects()).hasSize(2);
DestinationEffect firstEffect = event.getDestinationEffects().get(0);
assertThat(firstEffect.getSummary()).isEqualTo("Change created");
assertThat(firstEffect.getOriginRefs().get(0).getRef()).isEqualTo("0");
assertThat(firstEffect.getDestinationRef().getId()).isEqualTo("destination/1");
DestinationEffect secondEffect = event.getDestinationEffects().get(1);
assertThat(secondEffect.getSummary()).isEqualTo("New effect");
assertThat(secondEffect.getType()).isEqualTo(Type.UPDATED);
assertThat(secondEffect.getOriginRefs().get(0).getRef()).isEqualTo("1111");
assertThat(secondEffect.getDestinationRef().getId()).isEqualTo("9999");
}
Aggregations