Skip to content

Commit 453a1ab

Browse files
committed
feat: added methods for Endpoint "/groups/:id/groups/shared"
1 parent dff8509 commit 453a1ab

File tree

2 files changed

+205
-0
lines changed

2 files changed

+205
-0
lines changed

gitlab4j-api/src/main/java/org/gitlab4j/api/GroupApi.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.gitlab4j.api.models.Member;
3535
import org.gitlab4j.api.models.Project;
3636
import org.gitlab4j.api.models.SamlGroupLink;
37+
import org.gitlab4j.api.models.SharedGroupsFilter;
3738
import org.gitlab4j.api.models.UploadedFile;
3839
import org.gitlab4j.api.models.Variable;
3940
import org.gitlab4j.api.models.Visibility;
@@ -595,6 +596,89 @@ public Stream<Project> getProjectsStream(Object groupIdOrPath) throws GitLabApiE
595596
return (getProjects(groupIdOrPath, getDefaultPerPage()).stream());
596597
}
597598

599+
/**
600+
* Get a list of groups where the given group has been invited.
601+
* When accessed without authentication, only public shared groups are returned.
602+
*
603+
* <pre><code>GitLab Endpoint: GET /groups/:id/groups/shared</code></pre>
604+
*
605+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
606+
* @param filter the GroupProjectsFilter instance holding the filter values for the query
607+
* @return a Stream containing the Group instances that belong to the group and match the provided filter
608+
* @throws GitLabApiException if any exception occurs
609+
*/
610+
public Stream<Group> getSharedGroupsStream(Object groupIdOrPath, SharedGroupsFilter filter)
611+
throws GitLabApiException {
612+
return (getSharedGroups(groupIdOrPath, filter, getDefaultPerPage()).stream());
613+
}
614+
615+
/**
616+
* Get a list of groups where the given group has been invited.
617+
* When accessed without authentication, only public shared groups are returned.
618+
*
619+
* <pre><code>GitLab Endpoint: GET /groups/:id/groups/shared</code></pre>
620+
*
621+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
622+
* @return a list of groups where the specified group ID has been invited
623+
* @throws GitLabApiException if any exception occurs
624+
*/
625+
public List<Group> getSharedGroups(Object groupIdOrPath) throws GitLabApiException {
626+
return (getSharedGroups(groupIdOrPath, getDefaultPerPage()).all());
627+
}
628+
629+
/**
630+
* Get a list of groups in the specified page range where the given group has been invited.
631+
* When accessed without authentication, only public shared groups are returned.
632+
*
633+
* <pre><code>GitLab Endpoint: GET /groups/:id/groups/shared</code></pre>
634+
*
635+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
636+
* @param page the page to get
637+
* @param perPage the number of Group instances per page
638+
* @return a list of groups where the specified group ID has been invited in the specified page range
639+
* @throws GitLabApiException if any exception occurs
640+
*/
641+
public List<Group> getSharedGroups(Object groupIdOrPath, int page, int perPage) throws GitLabApiException {
642+
Response response = get(
643+
Response.Status.OK,
644+
getPageQueryParams(page, perPage),
645+
"groups",
646+
getGroupIdOrPath(groupIdOrPath),
647+
"groups",
648+
"shared");
649+
return (response.readEntity(new GenericType<List<Group>>() {}));
650+
}
651+
652+
/**
653+
* Get a list of groups where the given group has been invited.
654+
* When accessed without authentication, only public shared groups are returned.
655+
*
656+
* <pre><code>GitLab Endpoint: GET /groups/:id/groups/shared</code></pre>
657+
*
658+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
659+
* @param itemsPerPage the number of Group instances that will be fetched per page
660+
* @return a Pager of groups where the specified group ID has been invited
661+
* @throws GitLabApiException if any exception occurs
662+
*/
663+
public Pager<Group> getSharedGroups(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException {
664+
return (new Pager<Group>(
665+
this, Project.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "groups", "shared"));
666+
}
667+
668+
/**
669+
* Get a Stream of groups where the given group has been invited.
670+
* When accessed without authentication, only public shared groups are returned.
671+
*
672+
* <pre><code>GitLab Endpoint: GET /groups/:id/groups/shared</code></pre>
673+
*
674+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
675+
* @return a Stream of groups where the specified group ID has been invited
676+
* @throws GitLabApiException if any exception occurs
677+
*/
678+
public Stream<Group> getSharedGroupsStream(Object groupIdOrPath) throws GitLabApiException {
679+
return (getSharedGroups(groupIdOrPath, getDefaultPerPage()).stream());
680+
}
681+
598682
/**
599683
* Get all details of a group.
600684
*
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
5+
import org.gitlab4j.models.Constants.ProjectOrderBy;
6+
import org.gitlab4j.models.Constants.SortOrder;
7+
import org.gitlab4j.models.GitLabForm;
8+
import org.gitlab4j.models.utils.JacksonJson;
9+
10+
/**
11+
* This class is used to filter Groups when getting lists of groups for a specified group where it has been invited.
12+
*/
13+
public class SharedGroupsFilter implements Serializable {
14+
private static final long serialVersionUID = 1L;
15+
16+
private List<Long> skipGroups;
17+
private String search;
18+
private GroupOrderBy orderBy;
19+
private SortOrder sort;
20+
private Visibility visibility;
21+
private AccessLevel minAccessLevel;
22+
private Boolean withCustomAttributes;
23+
24+
/**
25+
* Do not include the provided groups IDs.
26+
*
27+
* @param skipGroups List of group IDs to not include in the search
28+
* @return the reference to this SharedGroupsFilter instance
29+
*/
30+
public GroupFilter withSkipGroups(List<Long> skipGroups) {
31+
this.skipGroups = skipGroups;
32+
return (this);
33+
}
34+
35+
/**
36+
* Return list of groups matching the search criteria.
37+
*
38+
* @param search the search criteria
39+
* @return the reference to this SharedGroupsFilter instance
40+
*/
41+
public SharedGroupsFilter withSearch(String search) {
42+
this.search = search;
43+
return (this);
44+
}
45+
46+
/**
47+
* Return groups ordered by name, path, id, or similarity. Default is name.
48+
*
49+
* @param orderBy specifies what field to order by
50+
* @return the reference to this SharedGroupsFilter instance
51+
*/
52+
public SharedGroupsFilter withOrderBy(ProjectOrderBy orderBy) {
53+
this.orderBy = orderBy;
54+
return (this);
55+
}
56+
57+
/**
58+
* Return groups sorted in asc or desc order. Default is desc.
59+
*
60+
* @param sort sort direction, ASC or DESC
61+
* @return the reference to this SharedGroupsFilter instance
62+
*/
63+
public SharedGroupsFilter withSortOder(SortOrder sort) {
64+
this.sort = sort;
65+
return (this);
66+
}
67+
68+
/**
69+
* Limit by visibility public, internal, or private.
70+
*
71+
* @param visibility the visibility to match
72+
* @return the reference to this SharedGroupsFilter instance
73+
*/
74+
public SharedGroupsFilter withVisibility(Visibility visibility) {
75+
this.visibility = visibility;
76+
return (this);
77+
}
78+
79+
/**
80+
* Limit to groups where current user has at least the specified role (access_level).
81+
*
82+
* @param minAccessLevel the minimum access level to match
83+
* @return the reference to this SharedGroupsFilter instance
84+
*/
85+
public SharedGroupsFilter withMinAccessLevel(Boolean minAccessLevel) {
86+
this.minAccessLevel = minAccessLevel;
87+
return (this);
88+
}
89+
90+
/**
91+
* Include custom attributes in response (admins only).
92+
*
93+
* @param withCustomAttributes if true, include custom attributes in the repsonse
94+
* @return the reference to this SharedGroupsFilter instance
95+
*/
96+
public SharedGroupsFilter withCustomAttributes(Boolean withCustomAttributes) {
97+
this.withCustomAttributes = withCustomAttributes;
98+
return (this);
99+
}
100+
101+
/**
102+
* Get the query params specified by this filter.
103+
*
104+
* @return a GitLabApiForm instance holding the query parameters for this SharedGroupsFilter instance
105+
*/
106+
public GitLabForm getQueryParams() {
107+
return (new GitLabForm()
108+
.withParam("skip_groups", skipGroups)
109+
.withParam("search", search)
110+
.withParam("order_by", orderBy)
111+
.withParam("sort", sort)
112+
.withParam("visibility", visibility)
113+
.withParam("simple", minAccessLevel)
114+
.withParam("with_custom_attributes", withCustomAttributes));
115+
}
116+
117+
@Override
118+
public String toString() {
119+
return (JacksonJson.toJsonString(this));
120+
}
121+
}

0 commit comments

Comments
 (0)