Skip to content

Commit 578c3c8

Browse files
ysemkofdi
andauthored
Add methods for Endpoint "/groups/:id/groups/shared" (#1290)
--------- Co-authored-by: fdi <[email protected]>
1 parent cd1f4cb commit 578c3c8

File tree

2 files changed

+247
-0
lines changed

2 files changed

+247
-0
lines changed

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

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

0 commit comments

Comments
 (0)