Search in sources :

Example 1 with PullRequestListParams

use of com.google.copybara.git.github.api.GitHubApi.PullRequestListParams in project copybara by google.

the class GitHubEndPoint method getPullRequests.

@StarlarkMethod(name = "get_pull_requests", doc = "Get Pull Requests for a repo", parameters = { @Param(name = "head_prefix", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "Only return PRs wher the branch name has head_prefix", defaultValue = "None"), @Param(name = "base_prefix", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "Only return PRs where the destination branch name has base_prefix", defaultValue = "None"), @Param(name = "state", doc = "State of the Pull Request. Can be `\"OPEN\"`, `\"CLOSED\"` or `\"ALL\"`", defaultValue = "\"OPEN\"", named = true), @Param(name = "sort", doc = "Sort filter for retrieving the Pull Requests. Can be `\"CREATED\"`," + " `\"UPDATED\"` or `\"POPULARITY\"`", named = true, defaultValue = "\"CREATED\""), @Param(name = "direction", doc = "Direction of the filter. Can be `\"ASC\"` or `\"DESC\"`", defaultValue = "\"ASC\"", named = true) }, allowReturnNones = true)
@Nullable
public ImmutableList<PullRequest> getPullRequests(Object headPrefixParam, Object basePrefixParam, String state, String sort, String direction) throws EvalException, RepoException {
    try {
        String project = ghHost.getProjectNameFromUrl(url);
        PullRequestListParams request = PullRequestListParams.DEFAULT;
        String headPrefix = convertFromNoneable(headPrefixParam, null);
        String basePrefix = convertFromNoneable(basePrefixParam, null);
        if (!Strings.isNullOrEmpty(headPrefix)) {
            checkCondition(SAFE_BRANCH_NAME_PREFIX.matches(headPrefix), "'%s' is not a valid head_prefix (%s is used for validation)", headPrefix, SAFE_BRANCH_NAME_PREFIX.pattern());
            request = request.withHead(headPrefix);
        }
        if (!Strings.isNullOrEmpty(basePrefix)) {
            checkCondition(SAFE_BRANCH_NAME_PREFIX.matches(basePrefix), "'%s' is not a valid base_prefix (%s is used for validation)", basePrefix, SAFE_BRANCH_NAME_PREFIX.pattern());
            request = request.withHead(basePrefix);
        }
        return apiSupplier.load(console).getPullRequests(project, request.withState(stringToEnum("state", state, StateFilter.class)).withDirection(stringToEnum("direction", direction, DirectionFilter.class)).withSort(stringToEnum("sort", sort, SortFilter.class)));
    } catch (GitHubApiException e) {
        return returnNullOnNotFound(e);
    } catch (ValidationException | RuntimeException e) {
        throw Starlark.errorf("Error calling get_pull_requests: %s", e.getMessage());
    }
}
Also used : DirectionFilter(com.google.copybara.git.github.api.GitHubApi.PullRequestListParams.DirectionFilter) ValidationException(com.google.copybara.exception.ValidationException) GitHubApiException(com.google.copybara.git.github.api.GitHubApiException) PullRequestListParams(com.google.copybara.git.github.api.GitHubApi.PullRequestListParams) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) Nullable(javax.annotation.Nullable)

Aggregations

ValidationException (com.google.copybara.exception.ValidationException)1 PullRequestListParams (com.google.copybara.git.github.api.GitHubApi.PullRequestListParams)1 DirectionFilter (com.google.copybara.git.github.api.GitHubApi.PullRequestListParams.DirectionFilter)1 GitHubApiException (com.google.copybara.git.github.api.GitHubApiException)1 Nullable (javax.annotation.Nullable)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1