Skip to content

Add associations count for users #1243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.ws.rs.core.Response;

import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Associations;
import org.gitlab4j.api.models.CustomAttribute;
import org.gitlab4j.api.models.Email;
import org.gitlab4j.api.models.Exists;
Expand Down Expand Up @@ -1502,6 +1503,20 @@ public Pager<Membership> getMemberships(Long userId, int itemsPerPage) throws Gi
return (new Pager<>(this, Membership.class, itemsPerPage, formData.asMap(), "users", userId, "memberships"));
}

/**
* Get a count of a user’s projects, groups, issues, and merge requests
*
* <pre><code>GitLab Endpoint: GET /user/:id/associations_count</code></pre>
*
* @param userId the ID of the user to get the associations for
* @return the count of each type of association
* @throws GitLabApiException if any exception occurs
*/
public Associations getAssociationsCount(Long userId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "users", userId, "associations_count");
return (response.readEntity(Associations.class));
}

/**
* Activates the given user (admin only)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.gitlab4j.api.models;

import java.io.Serializable;

import org.gitlab4j.models.utils.JacksonJson;

public class Associations implements Serializable {
private static final long serialVersionUID = 1L;

private int groupsCount;
private int projectsCount;
private int issuesCount;
private int mergeRequestsCount;

public int getGroupsCount() {
return groupsCount;
}

public void setGroupsCount(int groupsCount) {
this.groupsCount = groupsCount;
}

public int getProjectsCount() {
return projectsCount;
}

public void setProjectsCount(int projectsCount) {
this.projectsCount = projectsCount;
}

public int getIssuesCount() {
return issuesCount;
}

public void setIssuesCount(int issuesCount) {
this.issuesCount = issuesCount;
}

public int getMergeRequestsCount() {
return mergeRequestsCount;
}

public void setMergeRequestsCount(int mergeRequestsCount) {
this.mergeRequestsCount = mergeRequestsCount;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Loading