use of net.starlark.java.eval.Sequence 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);
}
Aggregations