use of com.google.copybara.util.Glob in project copybara by google.
the class GitDestinationTest method lastRevOnlyForAffectedRoots.
@Test
public void lastRevOnlyForAffectedRoots() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.createDirectories(workdir.resolve("foo"));
Files.createDirectories(workdir.resolve("bar"));
Files.createDirectories(workdir.resolve("baz"));
Files.write(workdir.resolve("foo/one"), "content".getBytes(UTF_8));
Files.write(workdir.resolve("bar/one"), "content".getBytes(UTF_8));
Files.write(workdir.resolve("baz/one"), "content".getBytes(UTF_8));
DummyRevision ref1 = new DummyRevision("first");
Glob firstGlob = Glob.createGlob(ImmutableList.of("foo/**", "bar/**"));
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destinationFirstCommit().newWriter(writerContext);
process(writer, ref1);
Files.write(workdir.resolve("baz/one"), "content2".getBytes(UTF_8));
DummyRevision ref2 = new DummyRevision("second");
process(writer, Glob.createGlob(ImmutableList.of("baz/**")), ref2);
assertThat(destination().newWriter(writerContext).getDestinationStatus(firstGlob, DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo(ref1.asString());
assertThat(writer.getDestinationStatus(Glob.createGlob(ImmutableList.of("baz/**")), DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo(ref2.asString());
}
use of com.google.copybara.util.Glob in project copybara by google.
the class GithubPROrigin method newReader.
@Override
public Reader<GitRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
return new ReaderImpl(url, originFiles, authoring, gitOptions, gitOriginOptions, generalOptions, /*includeBranchCommitLogs=*/
false, submoduleStrategy, firstParent) {
/**
* Disable rebase since this is controlled by useMerge field.
*/
@Override
protected void maybeRebase(GitRepository repo, GitRevision ref, Path workdir) throws RepoException, CannotResolveRevisionException {
}
@Override
public Optional<Baseline<GitRevision>> findBaseline(GitRevision startRevision, String label) throws RepoException, ValidationException {
if (!baselineFromBranch) {
return super.findBaseline(startRevision, label);
}
return findBaselinesWithoutLabel(startRevision, /*limit=*/
1).stream().map(e -> new Baseline<>(e.getSha1(), e)).findFirst();
}
@Override
public ImmutableList<GitRevision> findBaselinesWithoutLabel(GitRevision startRevision, int limit) throws RepoException, ValidationException {
String baseline = startRevision.associatedLabels().get(GITHUB_BASE_BRANCH_SHA1);
Preconditions.checkNotNull(baseline, "%s label should be present in %s", GITHUB_BASE_BRANCH_SHA1, startRevision);
GitRevision baselineRev = getRepository().resolveReference(baseline);
// Don't skip the first change as it is already the baseline
BaselinesWithoutLabelVisitor<GitRevision> visitor = new BaselinesWithoutLabelVisitor<>(originFiles, limit, /*skipFirst=*/
false);
visitChanges(baselineRev, visitor);
return visitor.getResult();
}
@Override
public Endpoint getFeedbackEndPoint() {
return new GitHubEndPoint(githubOptions, url);
}
/**
* Deal with the case of useMerge. We have a new commit (the merge) and first-parent from that
* commit doesn't work for this case.
*/
@Override
public ChangesResponse<GitRevision> changes(@Nullable GitRevision fromRef, GitRevision toRef) throws RepoException {
if (!useMerge) {
return super.changes(fromRef, toRef);
}
GitLogEntry merge = Iterables.getOnlyElement(getRepository().log(toRef.getSha1()).withLimit(1).run());
// Fast-forward merge
if (merge.getParents().size() == 1) {
return super.changes(fromRef, toRef);
}
// HEAD of the Pull Request
GitRevision gitRevision = merge.getParents().get(1);
ChangesResponse<GitRevision> prChanges = super.changes(fromRef, gitRevision);
// origin_files
if (prChanges.isEmpty()) {
return prChanges;
}
try {
return ChangesResponse.forChanges(ImmutableList.<Change<GitRevision>>builder().addAll(prChanges.getChanges()).add(change(merge.getCommit())).build());
} catch (EmptyChangeException e) {
throw new RepoException("Error getting the merge commit information: " + merge, e);
}
}
@Nullable
@Override
public String getGroupIdentity(GitRevision rev) throws RepoException {
return rev.associatedLabels().get(GITHUB_PR_NUMBER_LABEL);
}
};
}
use of com.google.copybara.util.Glob in project copybara by google.
the class WorkflowTest method testOnFinishHook_error.
// Validates that the hook is executed when the workflow throws ValidationException, and that
// the correct effect is populated
@Test
public void testOnFinishHook_error() throws Exception {
options.testingOptions.destination = new RecordsProcessCallDestination() {
@Override
public Writer<Revision> newWriter(WriterContext writerContext) {
return new RecordsProcessCallDestination.WriterImpl(false) {
@Override
public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws ValidationException {
throw new ValidationException("Validation exception!");
}
};
}
};
verifyHookForException(ValidationException.class, Type.ERROR, "Validation exception!");
}
use of com.google.copybara.util.Glob in project copybara by google.
the class WorkflowTest method checkIterativeModeWithError.
@SuppressWarnings("unchecked")
private <T extends Exception> T checkIterativeModeWithError(T exception) throws IOException, ValidationException {
for (int timestamp = 0; timestamp < 10; timestamp++) {
origin.addSimpleChange(timestamp);
}
// Override destination with one that always throws EmptyChangeException.
options.testingOptions.destination = new RecordsProcessCallDestination() {
@Override
public Writer<Revision> newWriter(WriterContext writerContext) {
return new WriterImpl(writerContext.isDryRun()) {
@Override
public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws ValidationException, RepoException {
assert exception != null;
Throwables.propagateIfPossible(exception, ValidationException.class, RepoException.class);
throw new RuntimeException(exception);
}
};
}
};
Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
"1");
try {
workflow.run(workdir, ImmutableList.of("3"));
fail();
} catch (Exception expected) {
assertThat(expected).isInstanceOf(expected.getClass());
return (T) expected;
}
return exception;
}
use of com.google.copybara.util.Glob 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");
}
Aggregations