Skip to content

Add getProjectGroups() methods in the projects api #909

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

Merged
merged 1 commit into from
Mar 30, 2023
Merged
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
88 changes: 87 additions & 1 deletion src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.gitlab4j.api.models.ProjectApprovalsConfig;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectFilter;
import org.gitlab4j.api.models.ProjectGroupsFilter;
import org.gitlab4j.api.models.ProjectGroup;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.PushRules;
Expand Down Expand Up @@ -1624,7 +1626,7 @@ public Stream<Member> getAllMembersStream(Object projectIdOrPath, String query,
* @throws GitLabApiException if any exception occurs
*/
public Member getMember(Object projectIdOrPath, Long userId) throws GitLabApiException {
return (getMember(projectIdOrPath, userId, false));
return (getMember(projectIdOrPath, userId, false));
}

/**
Expand Down Expand Up @@ -1926,6 +1928,90 @@ public Stream<ProjectUser> getProjectUsersStream(Object projectIdOrPath, String
return (getProjectUsers(projectIdOrPath, search, getDefaultPerPage()).stream());
}

/**
* Get a list of the ancestor groups for a given project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @return the ancestor groups for a given project
* @throws GitLabApiException if any exception occurs
*/
public List<ProjectGroup> getProjectGroups(Object projectIdOrPath) throws GitLabApiException {
return (getProjectGroups(projectIdOrPath, new ProjectGroupsFilter(), getDefaultPerPage()).all());
}

/**
* Get a Pager of the ancestor groups for a given project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of the ancestor groups for a given project
* @throws GitLabApiException if any exception occurs
*/
public Pager<ProjectGroup> getProjectGroups(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (getProjectGroups(projectIdOrPath, new ProjectGroupsFilter(), itemsPerPage));
}

/**
* Get a Stream of the ancestor groups for a given project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @return a Stream of the ancestor groups for a given project
* @throws GitLabApiException if any exception occurs
*/
public Stream<ProjectGroup> getProjectGroupsStream(Object projectIdOrPath) throws GitLabApiException {
return (getProjectGroups(projectIdOrPath, new ProjectGroupsFilter(), getDefaultPerPage()).stream());
}

/**
* Get a list of the ancestor groups for a given project matching the specified filter.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @param filter the ProjectGroupsFilter to match against
* @return the ancestor groups for a given project
* @throws GitLabApiException if any exception occurs
*/
public List<ProjectGroup> getProjectGroups(Object projectIdOrPath, ProjectGroupsFilter filter) throws GitLabApiException {
return (getProjectGroups(projectIdOrPath, filter, getDefaultPerPage()).all());
}

/**
* Get a Pager of the ancestor groups for a given project matching the specified filter.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param filter the ProjectGroupsFilter to match against
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of the ancestor groups for a given project
* @throws GitLabApiException if any exception occurs
*/
public Pager<ProjectGroup> getProjectGroups(Object projectIdOrPath, ProjectGroupsFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<ProjectGroup>(this, ProjectGroup.class, itemsPerPage, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "groups"));
}

/**
* Get a Stream of the ancestor groups for a given project matching the specified filter.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @param filter the ProjectGroupsFilter to match against
* @return a Stream of the ancestor groups for a given project
* @throws GitLabApiException if any exception occurs
*/
public Stream<ProjectGroup> getProjectGroupsStream(Object projectIdOrPath, ProjectGroupsFilter filter) throws GitLabApiException {
return (getProjectGroups(projectIdOrPath, filter, getDefaultPerPage()).stream());
}

/**
* Get the project events for specific project. Sorted from newest to latest.
*
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/org/gitlab4j/api/models/AbstractGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

package org.gitlab4j.api.models;

import org.gitlab4j.api.utils.JacksonJson;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class AbstractGroup<G extends AbstractGroup<G>> {

private Long id;
private String name;
private String avatarUrl;
private String webUrl;
private String fullName;
private String fullPath;

public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getAvatarUrl() {
return avatarUrl;
}

public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}

public String getWebUrl() {
return webUrl;
}

public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public String getFullPath() {
return fullPath;
}

public void setFullPath(String fullPath) {
this.fullPath = fullPath;
}

@SuppressWarnings("unchecked")
public G withId(Long id) {
this.id = id;
return (G)this;
}

@SuppressWarnings("unchecked")
public G withName(String name) {
this.name = name;
return (G)this;
}

@SuppressWarnings("unchecked")
public G withAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
return (G)this;
}

@SuppressWarnings("unchecked")
public G withWebUrl(String url) {
this.webUrl = url;
return (G)this;
}

@SuppressWarnings("unchecked")
public G withFullName(String fullName) {
this.fullName = fullName;
return (G)this;
}

@SuppressWarnings("unchecked")
public G withFullPath(String fullPath) {
this.fullPath = fullPath;
return (G)this;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
86 changes: 1 addition & 85 deletions src/main/java/org/gitlab4j/api/models/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Date;
import java.util.List;

public class Group {
public class Group extends AbstractGroup<Group> {

public class Statistics {
private Long storageSize;
Expand Down Expand Up @@ -49,17 +49,11 @@ public void setJobArtifactsSize(Long jobArtifactsSize) {
}


private Long id;
private String name;
private String path;
private String description;
private Visibility visibility;
private Boolean lfsEnabled;
private String avatarUrl;
private String webUrl;
private Boolean requestAccessEnabled;
private String fullName;
private String fullPath;
private Long parentId;
private Integer sharedRunnersMinutesLimit;
private Statistics statistics;
Expand All @@ -71,22 +65,6 @@ public void setJobArtifactsSize(Long jobArtifactsSize) {
@JsonSerialize(using = JacksonJson.DateOnlySerializer.class)
private Date markedForDeletionOn;

public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getPath() {
return this.path;
}
Expand Down Expand Up @@ -119,22 +97,6 @@ public void setLfsEnabled(Boolean lfsEnabled) {
this.lfsEnabled = lfsEnabled;
}

public String getAvatarUrl() {
return avatarUrl;
}

public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}

public String getWebUrl() {
return webUrl;
}

public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}

public Boolean getRequestAccessEnabled() {
return requestAccessEnabled;
}
Expand All @@ -143,22 +105,6 @@ public void setRequestAccessEnabled(Boolean requestAccessEnabled) {
this.requestAccessEnabled = requestAccessEnabled;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public String getFullPath() {
return fullPath;
}

public void setFullPath(String fullPath) {
this.fullPath = fullPath;
}

public Long getParentId() {
return parentId;
}
Expand Down Expand Up @@ -223,16 +169,6 @@ public void setRunnersToken(String runnersToken) {
this.runnersToken = runnersToken;
}

public Group withId(Long id) {
this.id = id;
return this;
}

public Group withName(String name) {
this.name = name;
return this;
}

public Group withPath(String path) {
this.path = path;
return this;
Expand All @@ -253,31 +189,11 @@ public Group withlfsEnabled(boolean lfsEnabled) {
return this;
}

public Group withAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
return this;
}

public Group withWebUrl(String url) {
this.webUrl = url;
return this;
}

public Group withRequestAccessEnabled(boolean requestAccessEnabled) {
this.requestAccessEnabled = requestAccessEnabled;
return this;
}

public Group withFullName(String fullName) {
this.fullName = fullName;
return this;
}

public Group withFullPath(String fullPath) {
this.fullPath = fullPath;
return this;
}

public Group withParentId(Long parentId) {
this.parentId = parentId;
return this;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/gitlab4j/api/models/ProjectGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.gitlab4j.api.models;

public class ProjectGroup extends AbstractGroup<ProjectGroup> {
}
Loading