org.gitlab4j.api.models.User Java Examples

The following examples show how to use org.gitlab4j.api.models.User. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabApi.java    From choerodon-starters with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up all future calls to the GitLab API to be done as another user specified by provided user ID.
 * To revert back to normal non-sudo operation you must call unsudo(), or pass null as the sudoAsId.
 *
 * @param sudoAsId the ID of the user to sudo as, null will turn off sudo
 * @throws GitLabApiException if any exception occurs
 */
public void setSudoAsId(Integer sudoAsId) throws GitLabApiException {

    if (sudoAsId == null) {
        apiClient.setSudoAsId(null);
        return;
    }

    // Get the User specified by the sudoAsId, if you are not an admin or the username is not found, this will fail
    User user = getUserApi().getUser(sudoAsId);
    if (user == null || !user.getId().equals(sudoAsId)) {
        throw new GitLabApiException("the specified user ID was not found");
    }

    apiClient.setSudoAsId(sudoAsId);
}
 
Example #2
Source File: TestUserApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testGetSshKeys() throws GitLabApiException {

    assumeTrue(TEST_SSH_KEY != null);
    SshKey sshKey = gitLabApi.getUserApi().addSshKey("Test-Key", TEST_SSH_KEY);
    assertNotNull(sshKey);
    assertEquals(TEST_SSH_KEY, sshKey.getKey());
    gitLabApi.getUserApi().deleteSshKey(sshKey.getId());

    User user = gitLabApi.getUserApi().getCurrentUser();
    sshKey = gitLabApi.getUserApi().addSshKey(user.getId(), "Test-Key1", TEST_SSH_KEY);
    assertNotNull(sshKey);
    assertEquals(TEST_SSH_KEY, sshKey.getKey());
    assertEquals(user.getId(), sshKey.getUserId());
    gitLabApi.getUserApi().deleteSshKey(sshKey.getId());
}
 
Example #3
Source File: TestStreams.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testParallelStream() throws Exception {

    // Arrange
    Stream<User> stream = new UserApi(gitLabApi).getUsersStream();

    // Assert
    assertNotNull(stream);
    List<User> users = stream.parallel().sorted(comparing(User::getUsername)).collect(toList());
    assertNotNull(users);

    assertEquals(users.size(), sortedUsers.size());
    for (int i = 0; i < users.size(); i++) {
        assertTrue(compareJson(sortedUsers.get(i), users.get(i)));
    }
}
 
Example #4
Source File: AbstractIntegrationTest.java    From gitlab4j-api with MIT License 6 votes vote down vote up
/**
 * Get the current user (the testing user).
 *
 * @return the user that is being used for testing
 */
protected static User getCurrentUser() {

    Throwable t = new Throwable();
    StackTraceElement directCaller = t.getStackTrace()[1];
    String callingClassName = directCaller.getClassName();
    BaseTestResources baseResources = baseTestResourcesMap.get(callingClassName);
    if (baseResources == null || baseResources.gitLabApi == null) {
        System.err.println("Problems fetching current user: GitLabApi instance is null");
        return (null);
    }

    try {
        return (baseResources.gitLabApi.getUserApi().getCurrentUser());
    } catch (Exception e) {
        System.err.println("Problems fetching current user: " + e.getMessage());
        return (null);
    }
}
 
Example #5
Source File: TestTodosApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testGetTodos() throws GitLabApiException {

    Issue issue = gitLabApi.getIssuesApi().createIssue(testProject, getUniqueTitle(), ISSUE_DESCRIPTION);
    User currentUser = gitLabApi.getUserApi().getCurrentUser();
    gitLabApi.getIssuesApi().assignIssue(testProject, issue.getIid(), currentUser.getId());

    List<Todo> todos = gitLabApi.getTodosApi().getPendingTodos();
    assertTrue(todos.size() > 0);
    boolean found = false;
    for (Todo todo : todos) {
        if (todo.isIssueTodo() && ((Issue)todo.getTarget()).getIid().intValue() == issue.getIid()) {
            found = true;
            break;
        }
    }

    assertTrue(found);
}
 
Example #6
Source File: GitLabOwner.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@NonNull
public static GitLabOwner fetchOwner(GitLabApi gitLabApi, String projectOwner) {
    try {
        Group group = gitLabApi.getGroupApi().getGroup(projectOwner);
        return new GitLabGroup(group.getName(), group.getWebUrl(), group.getAvatarUrl(),
            group.getId(), group.getFullName(), group.getDescription());
    } catch (GitLabApiException e) {
        if (e.getHttpStatus() != 404) {
            throw new IllegalStateException("Unable to fetch Group", e);
        }

        try {
            User user = gitLabApi.getUserApi().getUser(projectOwner);
            // If user is not found, null is returned
            if (user == null) {
                throw new IllegalStateException(
                    String.format("Owner '%s' is neither a user/group/subgroup", projectOwner));
            }
            return new GitLabUser(user.getName(), user.getWebUrl(), user.getAvatarUrl(),
                user.getId());
        } catch (GitLabApiException e1) {
            throw new IllegalStateException("Unable to fetch User", e1);
        }
    }
}
 
Example #7
Source File: TestUserApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
@Test
public void testEmails() throws GitLabApiException {

    User currentUser = gitLabApi.getUserApi().getCurrentUser();
    assertNotNull(currentUser);
    List<Email> emails = gitLabApi.getUserApi().getEmails(currentUser);
    assertNotNull(emails);
    int currentSize = emails.size();

    Email email = gitLabApi.getUserApi().addEmail(currentUser, TEST_USER_EMAIL, true);
    emails = gitLabApi.getUserApi().getEmails(currentUser);
    assertTrue(emails.size() == currentSize + 1);
    Email found = emails.stream().filter(e -> e.getEmail().equals(TEST_USER_EMAIL)).findAny().orElse(null);
    assertNotNull(found);
 
    gitLabApi.getUserApi().deleteEmail(currentUser, email.getId());
    emails = gitLabApi.getUserApi().getEmails(currentUser);
    assertEquals(currentSize, emails.size());
    found = emails.stream().filter(e -> e.getEmail().equals(TEST_USER_EMAIL)).findAny().orElse(null);
    assertNull(found);
}
 
Example #8
Source File: GitLabApi.java    From choerodon-starters with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up all future calls to the GitLab API to be done as another user specified by sudoAsUsername.
 * To revert back to normal non-sudo operation you must call unsudo(), or pass null as the username.
 *
 * @param sudoAsUsername the username to sudo as, null will turn off sudo
 * @throws GitLabApiException if any exception occurs
 */
public void sudo(String sudoAsUsername) throws GitLabApiException {

    if (sudoAsUsername == null || sudoAsUsername.trim().length() == 0) {
        apiClient.setSudoAsId(null);
        return;
    }

    // Get the User specified by username, if you are not an admin or the username is not found, this will fail
    User user = getUserApi().getUser(sudoAsUsername);
    if (user == null || user.getId() == null) {
        throw new GitLabApiException("the specified username was not found");
    }

    Integer sudoAsId = user.getId();
    apiClient.setSudoAsId(sudoAsId);
}
 
Example #9
Source File: GitLabApi.java    From gitlab4j-api with MIT License 6 votes vote down vote up
/**
 * Sets up all future calls to the GitLab API to be done as another user specified by provided user ID.
 * To revert back to normal non-sudo operation you must call unsudo(), or pass null as the sudoAsId.
 *
 * @param sudoAsId the ID of the user to sudo as, null will turn off sudo
 * @throws GitLabApiException if any exception occurs
 */
public void setSudoAsId(Integer sudoAsId) throws GitLabApiException {

    if (sudoAsId == null) {
        apiClient.setSudoAsId(null);
        return;
    }

    // Get the User specified by the sudoAsId, if you are not an admin or the username is not found, this will fail
    User user = getUserApi().getUser(sudoAsId);
    if (user == null || !user.getId().equals(sudoAsId)) {
        throw new GitLabApiException("the specified user ID was not found");
    }

    apiClient.setSudoAsId(sudoAsId);
}
 
Example #10
Source File: JacksonJson.java    From choerodon-starters with Apache License 2.0 6 votes vote down vote up
@Override
public List<User> deserialize(JsonParser jsonParser, DeserializationContext context)
        throws IOException, JsonProcessingException {

    JsonNode tree = jsonParser.readValueAsTree();
    int numUsers = tree.size();
    List<User> users = new ArrayList<>(numUsers);
    for (int i = 0; i < numUsers; i++) {
        JsonNode node = tree.get(i);
        JsonNode userNode = node.get("user");
        User user = mapper.treeToValue(userNode, User.class);
        users.add(user);
    }

    return (users);
}
 
Example #11
Source File: SearchApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
/**
 * 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
 * @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
 */
public Pager<?> groupSearch(Object groupIdOrPath, GroupSearchScope scope, String search, int itemsPerPage) throws GitLabApiException {

    GitLabApiForm formData = new GitLabApiForm()
            .withParam("scope", scope, true)
            .withParam("search", search, true);

    switch (scope) {
        case PROJECTS:
            return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(),
                    "groups", getGroupIdOrPath(groupIdOrPath), "search"));

        case ISSUES:
            return (new Pager<Issue>(this, Issue.class, itemsPerPage, formData.asMap(),
                    "groups", getGroupIdOrPath(groupIdOrPath), "search"));

        case MERGE_REQUESTS:
            return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(),
                    "groups", getGroupIdOrPath(groupIdOrPath), "search"));

        case MILESTONES:
            return (new Pager<Milestone>(this, Milestone.class, itemsPerPage, formData.asMap(),
                    "groups", getGroupIdOrPath(groupIdOrPath), "search"));

        case USERS:
            return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(),
                    "groups", getGroupIdOrPath(groupIdOrPath), "search"));

        default:
            throw new GitLabApiException("Invalid GroupSearchScope [" + scope + "]");
    }
}
 
Example #12
Source File: TestSearchApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testProjectlUsersSearch() throws GitLabApiException {
    List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
            testProject, ProjectSearchScope.USERS, TEST_LOGIN_USERNAME);
    assertNotNull(results);
    assertTrue(results.get(0).getClass() == User.class);
}
 
Example #13
Source File: TestStreams.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
    initMocks(this);
    response = new MockResponse(User.class, null, "user-list.json");
    when(gitLabApi.getApiClient()).thenReturn(gitLabApiClient);
    when(gitLabApiClient.validateSecretToken(any())).thenReturn(true);
    when(gitLabApiClient.get(attributeCaptor.capture(), Mockito.<Object>any())).thenReturn(response);
}
 
Example #14
Source File: TestUserApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testGetOptionalImpersonationToken() throws GitLabApiException, ParseException {

    User user = gitLabApi.getUserApi().getCurrentUser();
    Scope[] scopes = {Scope.API, Scope.READ_USER};
    Date expiresAt = ISO8601.toDate("2018-01-01T00:00:00Z");

    ImpersonationToken token = null;
    try {

        token = gitLabApi.getUserApi().createImpersonationToken(user.getId(), TEST_IMPERSONATION_TOKEN_NAME, expiresAt, scopes);
        assertNotNull(token);

        Optional<ImpersonationToken> optional = gitLabApi.getUserApi().getOptionalImpersonationToken(user.getId(), token.getId());
        assertTrue(optional.isPresent());
        assertEquals(token.getId(), optional.get().getId());
        gitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());

        optional = gitLabApi.getUserApi().getOptionalImpersonationToken(user.getId(), 123456);
        assertNotNull(optional);
        assertFalse(optional.isPresent());

    } finally {
        if (user != null && token != null) {
            gitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());
        }
    }
}
 
Example #15
Source File: TestGroupApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testDenyRequestAccess() throws GitLabApiException {

    assumeTrue(TEST_REQUEST_ACCESS_USERNAME != null && TEST_REQUEST_ACCESS_USERNAME.length() > 0);

    gitLabApi.sudo(TEST_REQUEST_ACCESS_USERNAME);
    User user = gitLabApi.getUserApi().getCurrentUser();
    assertNotNull(user);
    final Integer userId = user.getId();

    try {
        try {

            AccessRequest accessRequest = gitLabApi.getGroupApi().requestAccess(testGroup);
            assertNotNull(accessRequest);
            assertEquals(userId, accessRequest.getId());

        } finally {
            gitLabApi.unsudo();
        }

        List<AccessRequest> requests = gitLabApi.getGroupApi().getAccessRequests(testGroup);
        assertTrue(requests.stream().anyMatch(r -> r.getId() == userId));

        gitLabApi.getGroupApi().denyAccessRequest(testGroup, userId);

        requests = gitLabApi.getGroupApi().getAccessRequests(testGroup);
        assertFalse(requests.stream().anyMatch(r -> r.getId() == userId));

        user = null;

    } finally {
        try {
            if (user != null) {
                gitLabApi.getGroupApi().denyAccessRequest(testGroup, userId);
            }
        } catch (Exception ignore) {
        }
    }
}
 
Example #16
Source File: TestTodosApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testMarkAllAsDone() throws GitLabApiException {

    Issue issue = gitLabApi.getIssuesApi().createIssue(testProject, getUniqueTitle(), ISSUE_DESCRIPTION);
    User currentUser = gitLabApi.getUserApi().getCurrentUser();
    gitLabApi.getIssuesApi().assignIssue(testProject, issue.getIid(), currentUser.getId());

    List<Todo> todos = gitLabApi.getTodosApi().getPendingTodos();
    assertTrue(todos.size() > 0);

    gitLabApi.getTodosApi().markAllAsDone();
    todos = gitLabApi.getTodosApi().getPendingTodos();
    assertNotNull(todos);
    assertEquals(0, todos.size());
}
 
Example #17
Source File: TestUserApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testSudoAsUser() throws GitLabApiException {

    assumeTrue(TEST_SUDO_AS_USERNAME != null && TEST_SUDO_AS_USERNAME.length() > 0);

    try {

        gitLabApi.sudo(TEST_SUDO_AS_USERNAME);
        User user = gitLabApi.getUserApi().getCurrentUser();
        assertNotNull(user);
        assertEquals(TEST_SUDO_AS_USERNAME, user.getUsername());
        Integer sudoAsId = user.getId();

        gitLabApi.sudo(null);
        user = gitLabApi.getUserApi().getCurrentUser();
        assertNotNull(user);
        assertEquals(TEST_USERNAME, user.getUsername());

        gitLabApi.unsudo();
        assertNull(gitLabApi.getSudoAsId());

        gitLabApi.setSudoAsId(sudoAsId);
        user = gitLabApi.getUserApi().getCurrentUser();
        assertNotNull(user);
        assertEquals(sudoAsId, user.getId());
        assertEquals(TEST_SUDO_AS_USERNAME, user.getUsername());

    } finally {
        gitLabApi.unsudo();
    }
}
 
Example #18
Source File: TestProjectApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testDenyRequestAccess() throws GitLabApiException {

    assumeTrue(TEST_REQUEST_ACCESS_USERNAME != null && TEST_REQUEST_ACCESS_USERNAME.length() > 0);

    gitLabApi.sudo(TEST_REQUEST_ACCESS_USERNAME);
    User user = gitLabApi.getUserApi().getCurrentUser();
    assertNotNull(user);
    final Integer userId = user.getId();

    try {
        try {

            AccessRequest accessRequest = gitLabApi.getProjectApi().requestAccess(testProject);
            assertNotNull(accessRequest);
            assertEquals(userId, accessRequest.getId());

        } finally {
            gitLabApi.unsudo();
        }

        List<AccessRequest> requests = gitLabApi.getProjectApi().getAccessRequests(testProject);
        assertTrue(requests.stream().anyMatch(r -> r.getId() == userId));

        gitLabApi.getProjectApi().denyAccessRequest(testProject, userId);

        requests = gitLabApi.getProjectApi().getAccessRequests(testProject);
        assertFalse(requests.stream().anyMatch(r -> r.getId() == userId));

        user = null;

    } finally {
        try {
            if (user != null) {
                gitLabApi.getProjectApi().denyAccessRequest(testProject, userId);
            }
        } catch (Exception ignore) {
        }
    }
}
 
Example #19
Source File: JacksonJson.java    From choerodon-starters with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(List<User> value, JsonGenerator jgen,
                      SerializerProvider provider) throws IOException,
        JsonProcessingException {

    jgen.writeStartArray();
    for (User user : value) {
        jgen.writeStartObject();
        jgen.writeObjectField("user", user);
        jgen.writeEndObject();
    }
    jgen.writeEndArray();
}
 
Example #20
Source File: TestUserApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testGetOptionalUser() throws GitLabApiException {

    Optional<User> optional = gitLabApi.getUserApi().getOptionalUser(TEST_USERNAME);
    assertNotNull(optional);
    assertTrue(optional.isPresent());
    assertEquals(TEST_USERNAME, optional.get().getUsername());

    optional = gitLabApi.getUserApi().getOptionalUser("this-username-does-not-exist");
    assertNotNull(optional);
    assertFalse(optional.isPresent());
}
 
Example #21
Source File: TestUserApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testExternalUid() throws GitLabApiException {

    assumeNotNull(TEST_EXTERNAL_USERNAME);
    assumeNotNull(TEST_EXTERNAL_PROVIDER);
    assumeNotNull(TEST_EXTERNAL_UID);

    User externalUser = null;
    try {

        User userSettings = new User()
                .withUsername(TEST_EXTERNAL_USERNAME)
                .withEmail(TEST_EXTERNAL_USERNAME + "@gitlab4j.org")
                .withName("GitLab4J External User")
                .withSkipConfirmation(true)
                .withIsAdmin(false)
                .withExternUid(TEST_EXTERNAL_UID)
                .withProvider(TEST_EXTERNAL_PROVIDER);
        externalUser = gitLabApi.getUserApi().createUser(userSettings, TEST_LOGIN_PASSWORD, false);
        assertNotNull(externalUser);

        Optional<User> optionalUser = gitLabApi.getUserApi().getOptionalUserByExternalUid(TEST_EXTERNAL_PROVIDER, TEST_EXTERNAL_UID);
        assertNotNull(optionalUser);
        assertTrue(optionalUser.isPresent());
        assertEquals(externalUser.getId(), optionalUser.get().getId());

        optionalUser = gitLabApi.getUserApi().getOptionalUserByExternalUid("unknown-provider", "unknown-uid");
        assertNotNull(optionalUser);
        assertFalse(optionalUser.isPresent());

    } finally {
        if (externalUser != null) {
            try {
                gitLabApi.getUserApi().deleteUser(externalUser);
            } catch (Exception ignore) {}
        }
    }
}
 
Example #22
Source File: JacksonJson.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Override
public void serialize(List<User> value, JsonGenerator jgen,
        SerializerProvider provider) throws IOException,
        JsonProcessingException {

    jgen.writeStartArray();
    for (User user : value) {
        jgen.writeStartObject();
        jgen.writeObjectField("user", user);
        jgen.writeEndObject();
    }
    jgen.writeEndArray();
}
 
Example #23
Source File: TestUserApi.java    From gitlab4j-api with MIT License 5 votes vote down vote up
@Test
public void testCreateImpersonationToken() throws GitLabApiException, ParseException {

    User user = gitLabApi.getUserApi().getCurrentUser();

    // NOTE: READ_REGISTRY scope is left out because the GitLab server docker instance does not have the 
    // registry configured and the test would thus fail.
    Scope[] scopes = {Scope.API, Scope.READ_USER, Scope.READ_REPOSITORY, Scope.WRITE_REPOSITORY, Scope.SUDO};
    Date expiresAt = ISO8601.toDate("2018-01-01T00:00:00Z");

    ImpersonationToken token = null;
    try {

        token = gitLabApi.getUserApi().createImpersonationToken(user, TEST_IMPERSONATION_TOKEN_NAME, expiresAt, scopes);

        assertNotNull(token);
        assertNotNull(token.getId());
        assertEquals(TEST_IMPERSONATION_TOKEN_NAME, token.getName());
        assertEquals(expiresAt.getTime(), token.getExpiresAt().getTime());
        assertEquals(scopes.length, token.getScopes().size());
        assertThat(token.getScopes(), contains(scopes));

    } finally {
        if (user != null && token != null) {
            gitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());
        }
    }
}
 
Example #24
Source File: SearchApi.java    From gitlab4j-api with MIT License 4 votes vote down vote up
/**
 * Search within the specified project.  If a user is not a member of a project and the project is private,
 * a request on that project will result to a 404 status code.
 *
 * <pre><code>GitLab Endpoint: POST /project/:projectId/search?scope=:scope&amp;search=:search-query&amp;ref=ref</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
 * @param scope search the expression within the specified scope. Currently these scopes are supported:
 *               issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs, users
 * @param search the search query
 * @param ref the name of a repository branch or tag to search on. The project’s default branch is used by 
 *             default. This is only applicable for scopes: commits, blobs, and wiki_blobs.
 * @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
 */
public Pager<?> projectSearch(Object projectIdOrPath, ProjectSearchScope scope, String search, String ref, int itemsPerPage) throws GitLabApiException {

    GitLabApiForm formData = new GitLabApiForm()
            .withParam("scope", scope, true)
            .withParam("search", search, true)
            .withParam("ref", ref, false);
    
    if (ref != null) {
        if (!scope.equals(ProjectSearchScope.BLOBS) && !scope.equals(ProjectSearchScope.WIKI_BLOBS) && !scope.equals(ProjectSearchScope.COMMITS)) {
            throw new GitLabApiException("Ref parameter is only applicable for scopes: commits, blobs, and wiki_blobs");
        }
    }

    switch (scope) {
        case BLOBS:
            return (new Pager<SearchBlob>(this, SearchBlob.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case COMMITS:
            return (new Pager<Commit>(this, Commit.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case ISSUES:
            return (new Pager<Issue>(this, Issue.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case MERGE_REQUESTS:
            return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case MILESTONES:
            return (new Pager<Milestone>(this, Milestone.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case NOTES:
            return (new Pager<Note>(this, Note.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case WIKI_BLOBS:
            return (new Pager<SearchBlob>(this, SearchBlob.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        case USERS:
            return (new Pager<User>(this, User.class, itemsPerPage, formData.asMap(),
                    "projects", getProjectIdOrPath(projectIdOrPath), "search"));

        default:
            throw new GitLabApiException("Invalid ProjectSearchScope [" + scope + "]");
    }
}
 
Example #25
Source File: IssueEvent.java    From gitlab4j-api with MIT License 4 votes vote down vote up
public void setUser(User user) {
    this.user = user;
}
 
Example #26
Source File: SearchApi.java    From gitlab4j-api with MIT License 4 votes vote down vote up
/**
 * 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
 */
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 + "]");
    }
}
 
Example #27
Source File: TestSearchApi.java    From gitlab4j-api with MIT License 4 votes vote down vote up
@Test
public void testGrouplUsersSearch() throws GitLabApiException {
    List<?> results = (List<?>) gitLabApi.getSearchApi().groupSearch(testGroup, GroupSearchScope.USERS, TEST_LOGIN_USERNAME);
    assertNotNull(results);
    assertTrue(results.get(0).getClass() == User.class);
}
 
Example #28
Source File: IssueEvent.java    From gitlab4j-api with MIT License 4 votes vote down vote up
public User getUser() {
    return user;
}
 
Example #29
Source File: WikiPageEvent.java    From gitlab4j-api with MIT License 4 votes vote down vote up
public User getUser() {
    return user;
}
 
Example #30
Source File: BuildEvent.java    From gitlab4j-api with MIT License 4 votes vote down vote up
public void setUser(User user) {
    this.user = user;
}