SearchApi.java 18.33 KiB
package org.gitlab4j.api;
import java.util.List;
import java.util.stream.Stream;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.Milestone;
import org.gitlab4j.api.models.Note;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.SearchBlob;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.User;
/**
 * This class provides an entry point to all the GitLab API Search API calls.
 * @see <a href="https://gitlab.com/help/api/search.md">Search API</a>
public class SearchApi extends AbstractApi {
    public SearchApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    /**
     * Search globally across the GitLab instance.
     * <pre><code>GitLab Endpoint: POST /search?scope=:scope&amp;search=:search-query</code></pre>
     * @param scope search the expression within the specified scope. Currently these scopes are supported:
     *              projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs, users
     * @param search the search query
     * @return a List containing the object type specified by the scope
     * @throws GitLabApiException if any exception occurs
     * @since GitLab 10.5
    public List<?> globalSearch(SearchScope scope, String search) throws GitLabApiException {
        return (globalSearch(scope, search, this.getDefaultPerPage()).all());
    /**
     * Search globally across the GitLab instance.
     * <pre><code>GitLab Endpoint: POST /search?scope=:scope&amp;search=:search-query</code></pre>
     * @param scope search the expression within the specified scope. Currently these scopes are supported:
     *              projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs, users
     * @param search the search query
     * @return a Stream containing the object type specified by the scope
     * @throws GitLabApiException if any exception occurs
     * @since GitLab 10.5
    public Stream<?> globalSearchStream(SearchScope scope, String search) throws GitLabApiException {
        return (globalSearch(scope, search, getDefaultPerPage()).stream());
    /**
     * Search globally across the GitLab instance.
     * <pre><code>GitLab Endpoint: POST /search?scope=:scope&amp;search=:search-query</code></pre>
     * @param scope search the expression within the specified scope. Currently these scopes are supported:
     *              projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs, users
     * @param search the search query
     * @param itemsPerPage the number of items that will be fetched per page
     * @return a Pager containing the object type specified by the scope
     * @throws GitLabApiException if any exception occurs
     * @since GitLab 10.5
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
public Pager<?> globalSearch(SearchScope scope, String search, int itemsPerPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("scope", scope, true) .withParam("search", search, true); switch (scope) { case BLOBS: return (new Pager<SearchBlob>(this, SearchBlob.class, itemsPerPage, formData.asMap(), "search")); case COMMITS: return (new Pager<Commit>(this, Commit.class, itemsPerPage, formData.asMap(), "search")); case PROJECTS: return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "search")); case ISSUES: return (new Pager<Issue>(this, Issue.class, itemsPerPage, formData.asMap(), "search")); case MERGE_REQUESTS: return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "search")); case MILESTONES: return (new Pager<Milestone>(this, Milestone.class, itemsPerPage, formData.asMap(), "search")); case SNIPPET_TITLES: return (new Pager<Snippet>(this, Snippet.class, itemsPerPage, formData.asMap(), "search")); case SNIPPET_BLOBS: return (new Pager<Snippet>(this, Snippet.class, itemsPerPage, formData.asMap(), "search")); case USERS: return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(), "search")); case WIKI_BLOBS: return (new Pager<SearchBlob>(this, SearchBlob.class, itemsPerPage, formData.asMap(), "search")); default: throw new GitLabApiException("Invalid SearchScope [" + scope + "]"); } } /** * Search within the specified group. If a user is not a member of a group and the group is private, * a request on that group will result to a 404 status code. * * <pre><code>GitLab Endpoint: POST /groups/:groupId/search?scope=:scope&amp;search=:search-query</code></pre> * * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param scope search the expression within the specified scope. Currently these scopes are supported: * projects, issues, merge_requests, milestones, users * @param search the search query * @return a List containing the object type specified by the scope * @throws GitLabApiException if any exception occurs * @since GitLab 10.5 */ public List<?> groupSearch(Object groupIdOrPath, GroupSearchScope scope, String search) throws GitLabApiException { return (groupSearch(groupIdOrPath, scope, search, this.getDefaultPerPage()).all()); } /** * Search within the specified group. If a user is not a member of a group and the group is private, * a request on that group will result to a 404 status code. * * <pre><code>GitLab Endpoint: POST /groups/:groupId/search?scope=:scope&amp;search=:search-query</code></pre> * * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param scope search the expression within the specified scope. Currently these scopes are supported: * projects, issues, merge_requests, milestones, users * @param search the search query