Search in sources :

Example 6 with EvalException

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();
}
Also used : Author(com.google.copybara.authoring.Author) EvalException(net.starlark.java.eval.EvalException)

Example 7 with EvalException

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>");
}
Also used : EvalException(net.starlark.java.eval.EvalException) Test(org.junit.Test)

Example 8 with EvalException

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'");
}
Also used : EvalException(net.starlark.java.eval.EvalException) Test(org.junit.Test)

Example 9 with EvalException

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'");
}
Also used : WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) EvalException(net.starlark.java.eval.EvalException) Test(org.junit.Test)

Aggregations

EvalException (net.starlark.java.eval.EvalException)9 RepoException (com.google.copybara.exception.RepoException)4 ValidationException (com.google.copybara.exception.ValidationException)4 Test (org.junit.Test)4 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)2 Mutability (net.starlark.java.eval.Mutability)2 StarlarkThread (net.starlark.java.eval.StarlarkThread)2 TransformWork (com.google.copybara.TransformWork)1 TransformationStatus (com.google.copybara.TransformationStatus)1 WriterContext (com.google.copybara.WriterContext)1 Author (com.google.copybara.authoring.Author)1 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1 ChangeInfo (com.google.copybara.git.gerritapi.ChangeInfo)1 DeleteVoteInput (com.google.copybara.git.gerritapi.DeleteVoteInput)1 GerritApi (com.google.copybara.git.gerritapi.GerritApi)1 DummyRevision (com.google.copybara.testing.DummyRevision)1