use of com.google.copybara.git.github.api.GitHubEventType in project copybara by google.
the class GitModule method gitHubTrigger.
@SuppressWarnings("unused")
@StarlarkMethod(name = GITHUB_TRIGGER, doc = "Defines a feedback trigger based on updates on a GitHub PR.", parameters = { @Param(name = "url", doc = "Indicates the GitHub repo URL.", named = true), @Param(name = "checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker for the GitHub API transport provided by this trigger.", named = true), @Param(name = "events", allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class), @ParamType(type = Dict.class, generic1 = Sequence.class) }, named = true, defaultValue = "[]", doc = "Type of events to subscribe. Valid values are: `'ISSUES'`, `'ISSUE_COMMENT'`," + " `'PULL_REQUEST'`, `'PULL_REQUEST_REVIEW_COMMENT'`, `'PUSH'`," + " `'STATUS'`, `'CHECK_RUNS'`") }, useStarlarkThread = true)
@UsesFlags(GitHubOptions.class)
public GitHubTrigger gitHubTrigger(String url, Object checkerObj, Object events, StarlarkThread thread) throws EvalException {
checkNotEmpty(url, "url");
url = fixHttp(url, thread.getCallerLocation());
Checker checker = convertFromNoneable(checkerObj, null);
LinkedHashSet<EventTrigger> eventBuilder = new LinkedHashSet<>();
LinkedHashSet<GitHubEventType> types = new LinkedHashSet<>();
ImmutableSet<EventTrigger> parsedEvents = handleEventTypes(events, eventBuilder, types);
validateEndpointChecker(checker, GITHUB_TRIGGER);
GitHubOptions gitHubOptions = options.get(GitHubOptions.class);
return new GitHubTrigger(gitHubOptions.newGitHubApiSupplier(url, checker, GITHUB_COM), url, parsedEvents, getGeneralConsole(), GITHUB_COM);
}
use of com.google.copybara.git.github.api.GitHubEventType 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