use of net.starlark.java.eval.EvalException in project copybara by google.
the class RestoreOriginalAuthor method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException {
Author author = null;
// last author wins.
for (Change<?> change : work.getChanges().getCurrent()) {
ImmutableCollection<String> labelValue = change.getLabels().get(label);
if (!labelValue.isEmpty()) {
try {
author = Author.parse(Iterables.getLast(labelValue));
} catch (EvalException e) {
// Don't fail the migration because the label is wrong since it is very
// difficult for a user to recover from this.
work.getConsole().warn("Cannot restore original author: " + e.getMessage());
}
}
if (!searchAllChanges) {
break;
}
}
if (author != null) {
work.setAuthor(author);
work.removeLabel(label, /*wholeMessage=*/
true);
}
return TransformationStatus.success();
}
use of net.starlark.java.eval.EvalException in project copybara by google.
the class AuthorTest method testWrongEmailFormat.
@Test
public void testWrongEmailFormat() throws Exception {
EvalException thrown = assertThrows(EvalException.class, () -> Author.parse("foo-bar"));
assertThat(thrown).hasMessageThat().contains("Author 'foo-bar' doesn't match the expected format 'name <mail@example.com>");
}
use of net.starlark.java.eval.EvalException in project copybara by google.
the class SkylarkUtilTest method testCheckNotEmpty_empty.
@Test
public void testCheckNotEmpty_empty() throws Exception {
EvalException thrown = assertThrows(EvalException.class, () -> SkylarkUtil.checkNotEmpty("", "foo"));
assertThat(thrown).hasMessageThat().contains("Invalid empty field 'foo'");
}
use of net.starlark.java.eval.EvalException in project copybara by google.
the class GitHubDestinationTest method testChecker.
@Test
public void testChecker() throws Exception {
GitDestination d = skylark.eval("r", "r = git.github_destination(" + " url = 'http://github.com/example/example', \n" + " api_checker = testing.dummy_checker(),\n" + ")");
WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = d.newWriter(writerContext);
GitHubEndPoint endpoint = (GitHubEndPoint) writer.getFeedbackEndPoint(console);
EvalException e = assertThrows(EvalException.class, () -> endpoint.getCombinedStatus("bad_word"));
assertThat(e).hasMessageThat().contains("Bad word 'bad_word' found: field 'path'");
}
Aggregations