Search in sources :

Example 1 with Dict

use of net.starlark.java.eval.Dict in project copybara by google.

the class GitModule method handleEventTypes.

private ImmutableSet<EventTrigger> handleEventTypes(Object events, LinkedHashSet<EventTrigger> eventBuilder, LinkedHashSet<GitHubEventType> types) throws EvalException {
    if (events instanceof Sequence) {
        for (String e : Sequence.cast(events, String.class, "events")) {
            GitHubEventType event = stringToEnum("events", e, GitHubEventType.class);
            check(eventBuilder.add(EventTrigger.create(event, ImmutableSet.of())), "Repeated element %s", e);
        }
    } else if (events instanceof Dict) {
        Dict<String, StarlarkList<String>> dict = SkylarkUtil.castOfSequence(events, String.class, String.class, "events");
        for (Entry<String, StarlarkList<String>> trigger : dict.entrySet()) {
            check(types.add(stringToEnum("events", trigger.getKey(), GitHubEventType.class)), "Repeated element %s", trigger);
            eventBuilder.add(EventTrigger.create(stringToEnum("events", trigger.getKey(), GitHubEventType.class), ImmutableSet.copyOf(trigger.getValue())));
        }
    }
    for (EventTrigger trigger : eventBuilder) {
        check(WATCHABLE_EVENTS.contains(trigger.type()), "%s is not a valid value. Values: %s", trigger.type(), WATCHABLE_EVENTS);
    }
    check(!eventBuilder.isEmpty(), "events cannot be empty");
    return ImmutableSet.copyOf(eventBuilder);
}
Also used : Entry(java.util.Map.Entry) Dict(net.starlark.java.eval.Dict) Sequence(net.starlark.java.eval.Sequence) GitHubEventType(com.google.copybara.git.github.api.GitHubEventType)

Aggregations

GitHubEventType (com.google.copybara.git.github.api.GitHubEventType)1 Entry (java.util.Map.Entry)1 Dict (net.starlark.java.eval.Dict)1 Sequence (net.starlark.java.eval.Sequence)1