Search in sources :

Example 1 with GitHubEventType

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Checker(com.google.copybara.checks.Checker) GitHubEventType(com.google.copybara.git.github.api.GitHubEventType) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags)

Example 2 with GitHubEventType

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);
}
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)2 Checker (com.google.copybara.checks.Checker)1 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)1 LinkedHashSet (java.util.LinkedHashSet)1 Entry (java.util.Map.Entry)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1 Dict (net.starlark.java.eval.Dict)1 Sequence (net.starlark.java.eval.Sequence)1