use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testReviewerFieldWithNoTopic.
@Test
public void testReviewerFieldWithNoTopic() throws Exception {
pushToRefsFor = "master";
writeFile(workdir, "file", "some content");
fetch = "master";
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") : ImmutableList.of()), glob, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertPushRef("refs/for/master%hashtag=copybara_id_origin_ref_commiter@email," + "r=foo@example.com");
}
use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testLabels.
@Test
public void testLabels() 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", "labels = [\"${SOME_LABELS}\"]");
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_LABELS") ? ImmutableList.of("Foo+1", "Bar-1") : 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," + "label=Foo\\+1,label=Bar-1");
}
use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testCc.
@Test
public void testCc() 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", "cc = [\"${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") : 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," + "cc=foo@example.com");
}
use of com.google.copybara.effect.DestinationEffect in project copybara by google.
the class GerritDestinationTest method runChangeIdPolicy.
private String runChangeIdPolicy(String summary, String... config) throws Exception {
fetch = "master";
writeFile(workdir, "file", "some content");
options.setForce(true);
url = "https://localhost:33333/foo/bar";
GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
mockNoChangesFound();
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
List<DestinationEffect> result = destination(config).newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary(summary).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
return lastCommitChangeIdLine("origin_ref", repo).replace("Change-Id: ", "").trim();
}
use of com.google.copybara.effect.DestinationEffect 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");
}
Aggregations